Hi all,

So I've looked around enough, and it seems others have had almost the same
issue, but has been solved differently.

Anyway on to what I'm trying to accomplish: I have a private key being sent
over a socket by a Java Server to decrypt a string, and a Qt/C++ client that
is trying to accept this key. While I was able to do so by sending the key
to a file first, and loading it as such: 

CryptoPP::RSA::PrivateKey privKey;

CryptoPP::ByteQueue queue;
CryptoPP::FileSource file(filename.c_str(), true /*pumpAll*/);
file.TransferTo(queue);
queue.MessageEnd();
privKey.Load(queue);

I was not able to reproduce the same results using a byte array, I've tried
a couple ways:

//-----------------------------   1) -----------------------------------
QByteArray keyData = keySocket.readAll(); // reads all available data from
the socket (double checked)
char *data = keyData.data(); // returns a pointer to a '/0' terminated
string

CryptoPP::ByteQueue queue;
CryptoPP::StringSource keySource(data, true);

keySource.TransferTo(queue);
queue.MessageEnd();
privKey.Load(queue);

//------------------------------- 2) ----------------------------------
QByteArray keyData = keySocket.readAll(); // reads all available data from
the socket (double checked)
std::string dataString = QString(keyData).toStdString(); // creates a std
string from the byte array

CryptoPP::StringSource keySource(dataString, true);

privKey.Load(keySource);

Both times I end up with a "BER decode error" exception when trying to load
the key.

Am I just doing this completely wrong? I know there must be something
missing, but I've been going crazy trying so many ways!

Please help! It would be much appreciated!

-- 
View this message in context: 
http://old.nabble.com/Stuck-loading-Private-Key-from-Byte-Array-tp31846337p31846337.html
Sent from the Crypto++ Users mailing list archive at Nabble.com.

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