Different blowfish encryption results

437 views Asked by At

I am trying to replicate a particular function from our SAP system to a web site and a part of the flow is a blowfish encryption. I looked around for Blowfish encryption libraries for Javascript and implemented it into my js code.

However, upon comparison with the original SAP flow, the results of our blowfish encryptions are different.

The only thing that's different is that SAP blowfish uses UTF-16LE. I've tried converting my password and the text to UTF-16LE but I cannot get the same results from the original system.

I've found these two codes while searching around (these 2 converts/decodes from UTF8-UTF16 and vice versa)

function strEncodeUTF16(str) {
  var byteArray = new Uint8Array(str.length * 2);
    for (var i = 0; i < str.length; i++) {
    byteArray[i*2] = str.charCodeAt(i); // & 0xff;
    byteArray[i*2+1] = str.charCodeAt(i) >> 8; // & 0xff;
    }
    return String.fromCharCode.apply(String,byteArray);
}

function decodeUTF16LE( binaryStr ) {
    var cp = [];
    for( var i = 0; i < binaryStr.length; i+=2) {
        cp.push( 
             binaryStr.charCodeAt(i) |
            ( binaryStr.charCodeAt(i+1) << 8 )
        );
    }

    return String.fromCharCode.apply( String, cp );
}

The blowfish library I'm using is from the Dojo Toolkit: Blowfish.js from Dojo Toolkit 1.8.1

A sample test case would be:

Password: 7F30742A2

Text: 329

Result: B33663DFAC049492

However, when I try it on my end

var encrypted = blowfish.encrypt(id, key, {outputType:1, cipherMode: 0});

My result is: ef701b0e904b10c3

I am not sure where the difference is happening. Any thoughts?

0

There are 0 answers