Hi,

I just started working on cryptopp library. I have a image buffer and i 
want to encrypt with some key decrypt later but facing issue decrypted and 
original images are not same am not sure weather issue in encryption or not 
could some one help me out of this.

using qt creator

Code:

    string key = "7D9BB722DA2DC8674E08C3D44AAE976F";
    byte ctr[ AES::BLOCKSIZE ];

    string cipher, encoded, recovered;

    QFile file("original.png");
    if(!file.open(QIODevice::ReadOnly)){
        cout << "could not open the file"<< endl;
    }

    QByteArray bufferrrr = file.readAll();
    QString buffer = bufferrrr.toBase64();

    file.close();

    try
    {
        cout << "plain text: " << buffer.toStdString() << endl;

        CTR_Mode< AES >::Encryption e;
        e.SetKeyWithIV( (byte*)key.data(), key.size(), ctr );

        // The StreamTransformationFilter adds padding
        //  as required. ECB and CBC Mode must be padded
        //  to the block size of the cipher. CTR does not.
        StringSource ss1( buffer.toStdString(), true,
                          new StreamTransformationFilter( e,
                                                          new StringSink( 
cipher )
                                                          ) // 
StreamTransformationFilter
                          ); // StringSource

    }
    catch( CryptoPP::Exception& e )
    {
        cerr << e.what() << endl;
        exit(1);
    }

    try
    {
        CTR_Mode< AES >::Decryption d;
        d.SetKeyWithIV( (byte*)key.data(), key.size(), ctr );

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

        cout << "recovered text: " << recovered << endl;

        QByteArray byteArray(recovered.c_str(), recovered.length());
        QImage image = QImage::fromData(byteArray);
        file.setFileName("recovered.png");
        if (file.open(QIODevice::WriteOnly))
        {
          image.save(&file, "png"); // or "PNG"
          file.close();
        }
    }
    catch( CryptoPP::Exception& e )
    {
        cerr << e.what() << endl;
        exit(1);
    }


-- 
-- 
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/d/optout.

Reply via email to