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";
}





On 2 Apr 2008, at 15:16, Colin Bell wrote:

> Ok I think I'm getting closer.. but have some questions
>
> 1. Is this correct?
> 2. How do I set my key?
> 3. The notes say there is no BTEA::BLOCKSIZE so what do I use?
>
> Many thanks
>
> Colin
>
> int main(void){
>       string ciphertext = "GOBBELDYGOOK GOES HERE FOR TESTING==";
>       string decryptedtext;
>
>       byte key[] = {1234, 5678, 9999, 9999};
>       byte iv[ CryptoPP::TEA::BLOCKSIZE ];
>    // memset( key, 0x00, CryptoPP::BTEA::DEFAULT_KEYLENGTH );
>       memset( iv, 0x00, CryptoPP::TEA::BLOCKSIZE );
>       
>       CryptoPP::BTEA::Decryption beaDecryption(key,  
> CryptoPP::BTEA::DEFAULT_KEYLENGTH);
>       CryptoPP::CBC_Mode_ExternalCipher::Decryption  
> cbcDecryption( beaDecryption, iv);
>       CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption,  
> new CryptoPP::StringSink( decryptedtext ) );
>       stfDecryptor.Put( reinterpret_cast<const unsigned  
> char*>( ciphertext.c_str() ), ciphertext.size() );
>       stfDecryptor.MessageEnd();
>       
>       cout << decryptedtext << "\n";
> }
>
> On 2 Apr 2008, at 14:23, Colin Bell wrote:
>> Hi all
>>
>> I've been searching all afternoon for some Crypto++ BTEA examples.  
>> Besides the Crypto++ site been down, I can't find anything helpful.
>>
>> Would someone mind pointing me in the right direction to doing a  
>> BTEA encryption and then a decryption with a key ie:"1234 1111 2222  
>> 3333" and a string. An example would really put me out of my misery!
>>
>> Many many thanks
>>
>> Colin
>


--~--~---------~--~----~------------~-------~--~----~
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.
-~----------~----~----~----~------~----~------~--~---

Reply via email to