I've been experimenting with Blowfish, using different examples and found that if I create the class object I use for decrypting AND provide the key and IV in the same step, the padding is stripped on output and the output is garbage.
Here's the one line that results in garbage output and stripped padding: CBC_Mode< Blowfish >::Encryption myDec((byte*) cKey, keyLen, bIV); If, instead, I do this in two steps, everything comes out okay: CBC_Mode< Blowfish >::Decryption myDec; myDec.SetKeyWithIV((byte*) cKey, keyLen, bIV); I'm including the encrypting and decrypting versions of the code. Note that in the working version, I have the single line with the constructor commented out - but in the non-working version, the next two lines are commented out. Everything else is the same. And it doesn't matter which version I use on the encrypting end, but it does matter what I use on the decrypting end. This code is the version that works just fine: //Just for testing, so not even bothering with a prng... const char* cKey = "12345678911234567892123456789312345678941234567895123456"; const byte* bIV = (byte*) "ABCDEFGH"; long int keyLen = strlen(cKey); //Filenames are strings // CBC_Mode< Blowfish >::Encryption myEnc((byte*) cKey, keyLen, bIV); CBC_Mode< Blowfish >::Encryption myEnc; myEnc.SetKeyWithIV((byte*) cKey, keyLen, bIV); FileSource((const char*) inFile.c_str(), true, new StreamTransformationFilter(myEnc, ( new FileSink((const char*) eName.c_str()) )) ); //And this for decryption: // CBC_Mode< Blowfish >::Encryption myDec((byte*) cKey, keyLen, bIV); CBC_Mode< Blowfish >::Decryption myDec; myDec.SetKeyWithIV((byte*) cKey, keyLen, bIV); FileSource((const char*) eName.c_str(), true, new StreamTransformationFilter(myDec, ( new FileSink((const char*) out2Name.c_str()) )) ); But when I change that last section of code to this - removing the two lines for creating and setting the key and IV and doing that all at once, the output changes to garbage and the the extra few bytes that needed padding to round it up to 8 bytes are gone: CBC_Mode< Blowfish >::Encryption myDec((byte*) cKey, keyLen, bIV); // CBC_Mode< Blowfish >::Decryption myDec; // myDec.SetKeyWithIV((byte*) cKey, keyLen, bIV); FileSource((const char*) eName.c_str(), true, new StreamTransformationFilter(myDec, ( new FileSink((const char*) out2Name.c_str()) )) ); It doesn't matter which version I use for encryption, but if I use this version for decryption, it doesn't work. I've looked for all the simple mistakes, including ones a learning disability I have can lead to. I'm providing the same info, I'm using the constructor in the same way - but when I do it this way, I get garbage for output and no padding. What am I doing wrong and why won't decryption work this way? -- -- You received this message because you are subscribed to the "Crypto++ Users" Google Group. To unsubscribe, send an email to [email protected]. More information about Crypto++ and this group is available at http://www.cryptopp.com. --- You received this message because you are subscribed to the Google Groups "Crypto++ Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
