|
Hi, there,
I am trying to use RSA to encypt and decrypt
something,
here, I got very strange problem(crypto++library is
4.2),
after encryption, I try to decrypt, here is the
code,
//
char* privStr = new
char[2*privateLength+1];
HexEncoder hexEncoder; hexEncoder.Put((byte *)privateKeyStr, privateLength); hexEncoder.MessageEnd(); hexEncoder.Get((byte *)privStr, 2*privateLength); privStr[2*privateLength] = 0;
StringSource privRSAKey(privStr, true, new
HexDecoder);
RSAES_PKCS1v15_Decryptor privatekey(privRSAKey); //
I always got a exception here,
BERGeneralDecoder::BERGeneralDecoder(BufferedTransformation &inQueue,
byte asnTag)
: m_inQueue(inQueue), m_finished(false) { byte b; if (!m_inQueue.Get(b) || b != asnTag) BERDecodeError(); <----------------------------------the exception I always got here. m_definiteLength = BERLengthDecode(m_inQueue,
m_length);
} But if change the original code like this way,
directly define a private key,
there is no any problem, can get the result
decypted text.
//
char* privStr = new
char[2*privateLength+1];
privStr="30820152020100300D06092A864886F70D01010105000482013C27B46E92C878558F7C819");
StringSource privRSAKey(privStr, true, new
HexDecoder);
RSAES_PKCS1v15_Decryptor privatekey(privRSAKey); //
BTW, I do the encryption and decryption separately.
when I encrypt, use the codes like the decrypt, not any problem
char* pubstr = new
char[2*publicLength+1];
HexEncoder hexEncoder; hexEncoder.Put((byte *)publicKeyStr, publicLength); hexEncoder.MessageEnd(); hexEncoder.Get((byte *)pubstr, 2*publicLength); pubstr[2*publicLength] = 0; StringSource* pubRSAKey = new StringSource(pubstr ,true,new HexDecoder); RSAES_PKCS1v15_Encryptor* pubkey = new RSAES_PKCS1v15_Encryptor(*pubRSAKey); I got confused and do not why?
anyone can help me figure it out.
thanks
David |
