Can't DER encode and BER decode RSA public key

Posted by Mildred on Stack Overflow See other posts from Stack Overflow or by Mildred
Published on 2014-08-22T07:39:52Z Indexed on 2014/08/23 10:21 UTC
Read the original article Hit count: 312

Filed under:
|
|
|

I have problems using Crypto++ to save a RSA public key (that I obtained loading a private key file in PKCS#8 format). When decoding the key, I always get a BERDecodeErr exception.

Here is the code I am using:

CryptoPP::RSASSA_PKCS1v15_SHA_Signer   _signer;
CryptoPP::RSASSA_PKCS1v15_SHA_Verifier _verifier;
CryptoPP::ByteQueue                    bytes;

//_signer.AccessPublicKey().Save(bytes); // seem to save private key instead
_signer.AccessKey().DEREncodePublicKey(bytes);

//_verifier.AccessKey().Load(bytes);
//_verifier.AccessKey().BERDecodePublicKey(bytes, 0, 0);
_verifier.AccessPublicKey().Load(bytes);

I also tried with the instructions commented above, without success.

How do you do to save or open the public key?

The public key looks like this in hex format, is there a tool to check its format / validity (regarding what crypto++ supports) ?

3081890281810097e24f2e95504a397e90fbc56d1b330ab2ab97a0d326007b890e40013f9e1d9bd9
f54b0c0840782ddae19b5b4595d8f8b9ffe0d2120174fcbc39585c5867cd2dfba69f8e540caa2c52
de8f08278a34e9249120500117f0ba756c5bb2be660013160db9f82f75deb7ccf63742a9e945da6c
cf30c2b109b73342daaabd02b872e50203010001

© Stack Overflow or respective owner

Related posts about public-key

Related posts about crypto++