Hi everyone,

I am currently working on a program where i have one client and two
servers (one encryptor server and one decryptor server). The client
will ask the user for some data to encrypt (as a string and turn into
char with memcpy) and send the char buffer using sockets to the
encryptor server. Which encrypts the info and sends it back to the
client. The client then sends the encrypted data to the second server
which will decrypt it and send it back to the client.

So far, I can get the encrypted data to the 2nd server fine and
SOMETIMES, the decryptor server will give me this message: (other
times it will work perfectly fine to give the client back the
decrypted data - prob because the cliphertext length was good)

StreamTransformationFilter: ciphertext length is not a multiple of
block size

Please help me. Thanks in advance.









My decryption code is as follows:

int decrypt(char *pBuffer, int size, int &i)
{
                         //CONVERTING THE KEY FROM STRING TO BYTE

                        string stringKey = "2b7e151628aed2a6abf7158809cf4f3c";
                        int buf = stringKey.size()+1;
                        char pKey[TEMP_BUFFER_SIZE];
                        memset(pKey, 0, buf);
                        memcpy (pKey, stringKey.c_str(), stringKey.size()+1);

                        byte key[AES::DEFAULT_KEYLENGTH];
                        memset(key, 0, AES::DEFAULT_KEYLENGTH);
                        CharToByte(pKey, key, stringKey.size());

                        // "ECB Mode";
                        string encoded, recovered;

//pBUFFER HAS THE ENCRYPTED INFORMATION

                        string cipher = pBuffer;


                        try
                        {
                                ECB_Mode< AES >::Decryption d;
                                d.SetKey(key, sizeof(key));


                                // The StreamTransformationFilter removes
                                //  padding as required.
                                StringSource s(cipher, true, new 
StreamTransformationFilter(d,new
StringSink(recovered), StreamTransformationFilter::DEFAULT_PADDING,
true
                                        ) // StreamTransformationFilter
                                ); // StringSource

                                cout << "recovered text: " << recovered << endl;
                        }
                        catch(const CryptoPP::Exception& e)
                        {
                                cerr << e.what() << endl;
                                exit(1);
                        }

        int bufSz = recovered.size()+1;
        memset(pBuffer, 0, bufSz);
        memcpy (pBuffer, recovered.c_str(), recovered.size()+1);

        //strcpy_s(pBuffer,bufSz,recovered.c_str());
        cout << "pBuffer text: " << pBuffer << endl;

        return recovered.size();

}

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