CryptoPP cannot decode a cipher encrypted with Public key

I am using Cryptopp with Qt, My server sends a Public key to my client, the client encrypts a username with it and sends it (I have tested the cipher is sent properly) but server side i have an error : "invalid ciphertext", here is the code from my client :

QByteArray writtendata;
QDataStream streamBytes(&writtendata,QIODevice::WriteOnly);

streamBytes << quint16(0) << bytes;
streamBytes.device()->seek(0);
streamBytes << (quint16) (bytes.size() - sizeof(quint16));

int     written = socket->write(writtendata);
std :: cout << "sent : " << written << std :: endl ;

and server side :

        in >> datalenth;
        qDebug() << "datalength    : " << datalenth;

        if (socket->bytesAvailable() < datalenth)
            return;
        qDebug() << "byte available    : " << socket->bytesAvailable();
        QByteArray read;
        in >> read;
        qDebug() << "Read    : " << read.size();
        file.write(read);
        file.close();
        ifstream my;
        my.open("cipher.txt");

        string str((std::istreambuf_iterator<char>(my)), std::istreambuf_iterator<char>());
        qDebug() << "str:  "<< str.size();
        cout << str <<endl ;
        string recovered = T->discryptor(str) ;
        std :: cout << "recovered : " << recovered << std :: endl;
        my.close();

I don't really know where the problem comes from.

Hope that anyone can shed some light on this.

Answers


Need Your Help

Postgresql breaking rails querying functionality

ruby-on-rails ruby-on-rails-3 postgresql

I have a rails app that was working fine with sqlite but upon switching over to postgre I'm having an issue with this query:

Oracle 11g Reference Partitioning and Indexes

oracle oracle11g indexing

I have a parent table containing the following columns:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.