Closed lucnap closed 9 years ago
You are right, there are zeroes added to the end of string.
Blowfish is a block cipher. It could encrypt or decrypt only blocks of information. Block size is 8 bytes.
Acceptable length of input string for Blowfish in bytes: 8,16, 24, 32 and so long.
If your messeage size is not 8 byte it is automaticaly padded by adding zeroes to the end. https://github.com/agorlov/javascript-blowfish/blob/master/Blowfish.js#L182
Example: string "secret" is 6 bytes.
To encrypt this, it is padded by zeroes: "secret\0\0" 8byte
I was doubt about shuld I trim zeroes when decrypt, or not. So I added function trimZeros to Blowfish class.
I was doubt, becouse blowfish could encrytp not only string information, but also binary.
There is no doubt I need to say about this in README.
Working example: http://plnkr.co/edit/I3y3AxgGJGFlJ89w060C?p=preview
Ok I understand. But instead of padding with zeroes, what you think about padding with the Method 2 suggested in this page? http://www.di-mgt.com.au/cryptopad.html
Good article, shows us different approaches of padding data for block ciphers. I will be appreciated you for pull request.
there is a bug when decrypt previous encrypted data in json format (stringified) It seems that some invisible character is added at the end...
here a plunker (watch console log) http://plnkr.co/edit/znEnkiURIjmv3DLeOgVP?p=preview