As part of my Chilkat evaluation, I wanted to confirm that I could successfully decrypt a Blowfish ECB message emitted as part of the IHO S-63 standard. The standard says it uses Blowfish in ECB mode, with RFC1423 padding. When I try to decrypt under these settings in ChilKat, decryption claims to succeed, but the output buffer has zero size.
Here's the code I've written:
As an experiment, I encrypted AND decrypted with these settings on a test message, and the buffers were properly sized in the end. I'm guessing I'm not decrypting symmetrically with the S-63 data, but if so, I would've expected garbled data rather than an empty output buffer.
Please advise, I'm ready to purchase licenses once I get past this.
This question is marked "community wiki".
asked Feb 18 '13 at 00:35
Make sure you test with data that is longer than a single block. For example, the Blowfish algorithm has a block size of 8 bytes. Make sure your encrypted data is more than 8 bytes. If your secret key is incorrect, then you'll decrypt to garbled data, and it may be that the result of the garbled data indicates padding such that ALL of the result is padding, and it is all removed, and you get 0 bytes back. Therefore, if you test with a larger amount of data, then an incorrect key will result in garbled data being returned, with potentially only the last block being missing.
Also, check the contents of the LastErrorText for more information.
answered Feb 18 '13 at 08:36
The encrypted data that is passed to me is 8 bytes in length, with only 5 bytes being relevant and the rest is padding.
Per the code snippet, LastErrorText() reports DecryptBytes() succeeded.
The hint about unpadding was helpful. For decryption only, I call set_Padding(2 = random) to discourage/disable any unpadding behavior afterward. This seems to fix the problem, as I now get 8 bytes of output, which I will only extract the first 5 bytes.
answered Feb 18 '13 at 23:34