Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 578651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:17:00+00:00 2026-05-13T14:17:00+00:00

For a project I’m working on, I need to encrypt and decrypt a string

  • 0

For a project I’m working on, I need to encrypt and decrypt a string using Blowfish in a compatible way across NSIS and PHP.

At the moment I’m using the Blowfish++ plugin for NSIS and the mcrypt library with PHP. The problem is, I can’t get them both to produce the same output.

Let’s start with the NSIS Blowfish++ plugin. Basically the API is:

; Second argument needs to be base64 encoded
; base64_encode("12345678") == "MTIzNDU2Nzg="

blowfish::encrypt "test@test.com***" "MTIzNDU2Nzg="
Pop $0 ; 0 on success, 1 on failure
Pop $1 ; encrypted message on success, error message on failure

There’s no mention of whether it’s CBC, ECB, CFB, etc. and I’m not familiar enough with Blowfish to be able to tell by reading the mostly undocumented source. I assume it’s ECB since the PHP docs for mcrypt tells me that ECB doesn’t need an IV.

I’ve also learned by reading the source code that the Blowfish++ plugin will Base64 decode the second argument to encrypt (I’m not sure why). It also returns a Base64 encoded string.

For the PHP side of things, I’m basically using this code to encrypt:

$plainText = "test@test.com***";
$cipher = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_ECB, '');   
$iv = '00000000';  // Show not be used anyway.
$key = "12345678";

$cipherText = "";
if (mcrypt_generic_init($cipher, $key, $iv) != -1)
{
    $cipherText = mcrypt_generic($cipher, $plainText);
    mcrypt_generic_deinit($cipher);        
}

echo base64_encode($cipherText);

However, if I do all these things, I get the following output from each:

NSIS: GyCyBcUE0s5gqVDshVUB8w==
PHP:  BQdlPd19zEkX5KT9tnF8Ng==

What am I doing wrong? Is the NSIS plugin not using ECB? If not, what is it using for it’s IV?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:17:00+00:00Added an answer on May 13, 2026 at 2:17 pm

    OK, I’ve gone through that code and reproduced your results. The problem isn’t the cipher mode – NSIS is using ECB. The problem is that the NSIS Blowfish code is simply broken on little-endian machines.

    The Blowfish algorithm operates on two 32-bit unsigned integers. To convert between a 64 bit plaintext or ciphertext block and these two integers, the block is supposed to be interpreted as two Big Endian integers. The NSIS Blowfish plugin is instead interpreting them in host byte order – so it fails to do the right thing on little-endian hosts (like x86). This means it’ll interoperate with itself, but not with genuine Blowfish implementations (like mcrypt).

    I’ve patched Blowfish++ for you to make it do the right thing – the modified Blowfish::Encrypt and Blowfish::Decrypt are below, and the new version of blowfish.cpp is here on Pastebin.

    void Blowfish::Encrypt(void *Ptr,unsigned int N_Bytes)
    {
        unsigned int i;
        unsigned char *Work;
    
        if (N_Bytes%8)
        {
                return;
        }
    
        Work = (unsigned char *)Ptr;
    
        for (i=0;i<N_Bytes;i+=8)
        {
            Word word0, word1;
    
            word0.byte.zero = Work[i];
            word0.byte.one = Work[i+1];
            word0.byte.two = Work[i+2];
            word0.byte.three = Work[i+3];
    
            word1.byte.zero = Work[i+4];
            word1.byte.one = Work[i+5];
            word1.byte.two = Work[i+6];
            word1.byte.three = Work[i+7];
    
            BF_En(&word0, &word1);
    
            Work[i] = word0.byte.zero;
            Work[i+1] = word0.byte.one;
            Work[i+2] = word0.byte.two;
            Work[i+3] = word0.byte.three;
    
            Work[i+4] = word1.byte.zero;
            Work[i+5] = word1.byte.one;
            Work[i+6] = word1.byte.two;
            Work[i+7] = word1.byte.three;
        }
    
        Work = NULL;
    }
    
    void Blowfish::Decrypt(void *Ptr, unsigned int N_Bytes)
    {
        unsigned int i;
        unsigned char *Work;
    
        if (N_Bytes%8)
        {
                return;
        }
    
        Work = (unsigned char *)Ptr;
        for (i=0;i<N_Bytes;i+=8)
        {
            Word word0, word1;
    
            word0.byte.zero = Work[i];
            word0.byte.one = Work[i+1];
            word0.byte.two = Work[i+2];
            word0.byte.three = Work[i+3];
    
            word1.byte.zero = Work[i+4];
            word1.byte.one = Work[i+5];
            word1.byte.two = Work[i+6];
            word1.byte.three = Work[i+7];
    
            BF_De(&word0, &word1);
    
            Work[i] = word0.byte.zero;
            Work[i+1] = word0.byte.one;
            Work[i+2] = word0.byte.two;
            Work[i+3] = word0.byte.three;
    
            Work[i+4] = word1.byte.zero;
            Work[i+5] = word1.byte.one;
            Work[i+6] = word1.byte.two;
            Work[i+7] = word1.byte.three;
        }
    
        Work = NULL;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Call [UITableView reloadData]; to reload the table. May 16, 2026 at 4:02 pm
  • Editorial Team
    Editorial Team added an answer You need to create the temp files in a directory… May 16, 2026 at 4:02 pm
  • Editorial Team
    Editorial Team added an answer This was completed via fsb's suggestion to use the JZ… May 16, 2026 at 4:02 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Project file here if you want to download: http://files.me.com/knyck2/918odc So I am working on
Project layout: /project_a /shared /project_b /shared /shared project_a and project_b both need to contain
The project I'm working on allows an end-user to modify CSS code to integrate
I project I have been working on has now been split between me and
A project I have been working on for the past year writes out log
Project Darkstar was the topic of the monthly JavaSIG meeting down at the Google
Project Euler and other coding contests often have a maximum time to run or
Project Scenario Technology : Dotnetnuke (Approx. 100 - 150 screens) Data Architecture : LINQ
Project Euler 126 says: If we then add a second layer to this solid
Project is C#. So I have a bunch of multithreaded code that is designed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.