Hello,

I am new with cryptopp,i try to encrydpt and decrypt text from a file.
I alway receive this error CryptoPP::InvalidCiphertext at memory location 
0x0012efe4 just *after these lines* :
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new 
CryptoPP::StringSink( decryptedtext ) );
stfDecryptor.Put( reinterpret_cast<const unsigned char*>( 
ciphertext.c_str() ), ciphertext.length());
stfDecryptor.MessageEnd();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

*The encryption/decryption code:*
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

BOOL Encryption()
{
//
        // Key and IV setup
        //AES encryption uses a secret key of a variable length (128-bit, 
196-bit or 256-  
        //bit). This key is secretly exchanged between two parties before 
communication  
        //begins. DEFAULT_KEYLENGTH= 16 bytes
        byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ 
CryptoPP::AES::BLOCKSIZE ];
        memset( key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH );
        memset( iv, 0x00, CryptoPP::AES::BLOCKSIZE );

HW_PROFILE_INFO hwProfileInfo;
GetCurrentHwProfile(&hwProfileInfo);

(hwProfileInfo.szHwProfileGuid, strlen(hwProfileInfo.szHwProfileGuid), key);

(hwProfileInfo.szHwProfileGuid, strlen(hwProfileInfo.szHwProfileGuid), iv);
        //
        // String and Sink setup
        //
string STRING;
ifstream infile;
infile.open ("test2.txt");

         getline(infile,STRING, '\0'); // Saves the line in STRING.
                char cFilm[1000];
                strcpy(cFilm,STRING.c_str());
  infile.close();
        std::string plaintext = cFilm;
        std::string ciphertext;
        std::string decryptedtext;
        //
        // Dump Plain Text
        //
        std::cout << "Plain Text (" << plaintext.size() << " bytes)" << 
std::endl;
        std::cout << plaintext;
        std::cout << std::endl << std::endl;
        //
        // Create Cipher Text
        //
        CryptoPP::AES::Encryption aesEncryption(key, 
CryptoPP::AES::DEFAULT_KEYLENGTH);
        CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption( 
aesEncryption, iv );
        CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new 
CryptoPP::StringSink( ciphertext ) );
        stfEncryptor.Put( reinterpret_cast<const unsigned char*>( 
plaintext.c_str() ), plaintext.length() + 1 );
        stfEncryptor.MessageEnd();
        //
        // Dump Cipher Text
        //
   ofstream write ("test2a.txt", ios::out | ios::binary);
   int at = ciphertext.length()+ 1;
   write.write(ciphertext.c_str(),at);
          write.close();
          ciphertext.erase();

remove("test2.txt");
rename("test2a.txt","c:\\test2.txt");
        return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL Decryption()
{
//
        // Key and IV setup
        //AES encryption uses a secret key of a variable length (128-bit, 
196-bit or 256-  
        //bit). This key is secretly exchanged between two parties before 
communication  
        //begins. DEFAULT_KEYLENGTH= 16 bytes
        byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ 
CryptoPP::AES::BLOCKSIZE ];
        memset( key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH );
        memset( iv, 0x00, CryptoPP::AES::BLOCKSIZE );

HW_PROFILE_INFO hwProfileInfo;
GetCurrentHwProfile(&hwProfileInfo);
//char* rawKey="malakagergeerwherwhewrhwehewhhwrehrewhewhrewrwhherwherwh";
(hwProfileInfo.szHwProfileGuid, strlen(hwProfileInfo.szHwProfileGuid), key);
//char* rawIv="malakaherwheherwheerwhewrwherwhgerwhewrhewrrwhewrhewrherw";
(hwProfileInfo.szHwProfileGuid, strlen(hwProfileInfo.szHwProfileGuid), iv);
//
        // String and Sink setup
        //
string STRING2;
ifstream infile2;
infile2.open ("test2.txt",ios::binary);

         getline(infile2,STRING2, '\0'); // Saves the line in STRING.
                char cFilm2[1000];
                strcpy(cFilm2,STRING2.c_str());
  infile2.close();

        std::string ciphertext (cFilm2);
        std::string decryptedtext;
  
//
        // Decrypt
        //
        CryptoPP::AES::Decryption aesDecryption(key, 
CryptoPP::AES::DEFAULT_KEYLENGTH);
        CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption( 
aesDecryption, iv );
  
        CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new 
CryptoPP::StringSink( decryptedtext ) );
        stfDecryptor.Put( reinterpret_cast<const unsigned char*>( 
ciphertext.c_str() ), ciphertext.length());
        stfDecryptor.MessageEnd();
  
        //
        // Dump Decrypted Text
        //
   ofstream write ("test2a.txt", ios::out | ios::binary);
   write << decryptedtext;
          write.close();
          decryptedtext.erase();
remove("test2.txt");
rename("test2a.txt","test2.txt");
        return 0;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Anyone know how to solve this??
Thanks! 

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


Reply via email to