Szyfrowanie i deszyfrowanie Crypto ++ w dwóch różnych programach c ++

Piszę kod do szyfrowania i deszyfrowania za pomocą biblioteki crypto ++. Znalazłem kod do szyfrowania i deszyfrowania, który jest pokazany poniżej. Kod działa poprawnie jako jeden program. Ale kiedy podzielę się na dwa programy c ++ (jeden do szyfrowania, a drugi do deszyfrowania ) pargram deszyfrowania daje mi błąd

terminate called after throwing an instance of 'CryptoPP::InvalidCiphertext' what(): StreamTransformationFilter: ciphertext length is not a multiple of block size

Zaszyfrowany tekst, który otrzymuję po zaszyfrowaniu, to

���z=(f�����P%���2��W3�p�H�����^��@C��#������bp���nx��

które przenoszę do kodu deszyfrującego. Co ja robię źle?

moim pierwszym programem do szyfrowania jest

#include <iostream>
#include <iomanip>
#include <cryptopp/hex.h>
#include <cryptopp/sha.h>
#include <cryptopp/base64.h>
#include <iostream>
#include <string>
#include "crypto++/modes.h"
#include "crypto++/aes.h"
#include "crypto++/filters.h"

int main(int argc, char* argv[]) {

    //
    // 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 );

    //
    // String and Sink setup
    //
    std::string plaintext = "Now is the time for all good men to come to the aide...";
    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
    //
    std::cout << "Cipher Text (" << ciphertext.size() << " bytes)" << std::endl;

    for( int i = 0; i < ciphertext.size(); i++ ) {

        std::cout << "0x" << std::hex << (0xFF & static_cast<byte>(ciphertext[i])) << " ";
    }

    std::cout << std::endl << std::endl;

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

    return 0;
}

Wysyłam tekst zaszyfrowany za pomocą adresu URL, np.https: //xxx.xxx.xx.xx/_SERVER_TEST.fcgi? z = (f P% 2 W3 p H ^ @ C # bp nx

a po drugiej stronie próbuję opisać mój tekst zaszyfrowany. ale adres URL nie rozumie szyfru.

moim drugim programem jest odszyfrowywanie

#include <iostream>
#include <iomanip>
#include <cryptopp/hex.h>
#include <cryptopp/sha.h>
#include <cryptopp/base64.h>
#include <iostream>
#include <string>
#include "crypto++/modes.h"
#include "crypto++/aes.h"
#include "crypto++/filters.h"

int main(int argc, char* argv[]) {

    //
    // 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 );

    std::string ciphertext;
    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.size() );
    stfDecryptor.MessageEnd();

    //
    // Dump Decrypted Text
    //
    std::cout << "Decrypted Text: " << std::endl;
    std::cout << decryptedtext;
    std::cout << std::endl << std::endl;

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

    return 0;
}

questionAnswers(0)

yourAnswerToTheQuestion