blowfish.js
blowfish.js copied to clipboard
Padding
A weird issue has come up recently where the padding seems to be messed up.
To replicate: var me = new Blowfish("me"); var Data = me.encrypt("stuff"); alert(me.decrypt(Data));
It should alert "stuff" but instead its "stuff000"
I wrote this simple addon for the decrypt function to fix it:
//Patch by me to remove trailing zeros
returndata = this.unescape(dec);
revertext = returndata.split("").reverse();
for(i=0;i<8;i++){
if(revertext[i] == "0"){
delete revertext[i];
}
}
returndata = revertext.reverse().join("");*
return returndata;
but it is obviously not ideal.
I just checked this against the "marcelgreter" branch (https://github.com/drench/blowfish.js/tree/marcelgreter) and that version does not have the padding problem. Give that version a try if you don't need compatibility with Perl's Crypt::Blowfish.