Hi Colin,
You are seeing a side effect of the library when using an external
cipher object with OFB mode. In this case, change your decryptor to an
encryptor:
CryptoPP::OFB_Mode_ExternalCipher::Encryption
cbcDecryption( beaDecryption, iv);
...
Templated ciphers do no have this issue. See
http://www.codeproject.com/KB/security/BlockCiphers.aspx
Jeff
On 4/2/08, Colin Bell <[EMAIL PROTECTED]> wrote:
>
> I feel like I'm almost there on this, but I still cannot decode the BTEA
> string.
>
> Howver I get the error:
>
> test.exe: ./src/../include/crypto/modes.h:136: virtual void
> CryptoPP::OFB_ModePolicy::WriteKeystream(byte*, size_t):
> Assertion `m_cipher->IsForwardTransformation()' failed.
> Aborted
>
> Please could someone give me a prod in the right direction... Thanks
>
> int encryptTest(){
> string plaintext = "Now is the time for all good men to come to the
> aide...";
> string ciphertext;
> string decryptedtext;
>
> string keyString = "1234234534564567";
> byte key[BTEA::DEFAULT_KEYLENGTH];
> byte iv[BTEA::DEFAULT_KEYLENGTH];
>
>
> memset(key, 0x0, BTEA::DEFAULT_KEYLENGTH);
> memset(iv, 0x0, BTEA::DEFAULT_KEYLENGTH);
> memcpy(key, keyString.c_str(), BTEA::DEFAULT_KEYLENGTH);
> memcpy(iv, keyString.c_str(), BTEA::DEFAULT_KEYLENGTH);
>
>
> CryptoPP::TEA::Encryption bteaEncryption(key, TEA::DEFAULT_KEYLENGTH);
> CryptoPP::OFB_Mode_ExternalCipher::Encryption
> cbcEncryption( bteaEncryption, iv );
>
> StringSink* sink = new StringSink(ciphertext);
> Base64Encoder* base64_enc = new Base64Encoder(sink);
>
>
> CryptoPP::StreamTransformationFilter
> stfEncryptor(cbcEncryption, base64_enc );
> stfEncryptor.Put( reinterpret_cast<const unsigned char*>(
> plaintext.c_str() ), plaintext.length() + 1 );
> stfEncryptor.MessageEnd();
>
>
> cout << ciphertext << "\n";
> }
>
> int decryptTest(){
> //string created by code above
> string ciphertext =
> "d00fgN/oDqFovMVKFKmh4YMB81uubca7+ITfEDhm/fZjrTWpQPdsbdxmkrqRvdj39f3vxrlO\rqt0=";
>
>
> string decryptedtext;
>
> string keyString = "1234234534564567";
> byte key[BTEA::DEFAULT_KEYLENGTH];
> byte iv[BTEA::DEFAULT_KEYLENGTH];
>
>
> memset(key, 0x0, BTEA::DEFAULT_KEYLENGTH);
> memset(iv, 0x0, BTEA::DEFAULT_KEYLENGTH);
> memcpy(key, keyString.c_str(), BTEA::DEFAULT_KEYLENGTH);
> memcpy(iv, keyString.c_str(), BTEA::DEFAULT_KEYLENGTH);
>
> CryptoPP::BTEA::Decryption beaDecryption(key, BTEA::DEFAULT_KEYLENGTH);
> CryptoPP::OFB_Mode_ExternalCipher::Decryption
> cbcDecryption( beaDecryption, iv);
> CryptoPP::StreamTransformationFilter
> stfDecryptor(cbcDecryption, new CryptoPP::StringSink( decryptedtext ) );
> //Base64Decoder* base64_dec = new
> CryptoPP::Base64Decoder(stfDecryptor);
> //StringSource source(ciphertext, true, base64_dec);
>
>
> string baseDecodedCipher;
> StringSink* sink = new StringSink(baseDecodedCipher);
> Base64Decoder* base64_dec = new CryptoPP::Base64Decoder(sink);
> StringSource source(ciphertext, true, base64_dec);
>
>
> stfDecryptor.Put( reinterpret_cast<const unsigned char*>(
> baseDecodedCipher.c_str() ), baseDecodedCipher.size() );
> stfDecryptor.MessageEnd();
>
>
> cout << decryptedtext << "\n";
> }
>
> [ SNIP ]
--~--~---------~--~----~------------~-------~--~----~
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.
-~----------~----~----~----~------~----~------~--~---