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.