I have an RSA decrypt key generated with crypto++ 4.2 that throws an BERDecodeError in 5.2.1.  The stack trace is:
CryptoPP::BERDecodeError() line 49 + 28 bytes
CryptoPP::BERGeneralDecoder::Init(unsigned char 48) line 389
CryptoPP::BERGeneralDecoder::BERGeneralDecoder(CryptoPP::BERGeneralDecoder & {...}, unsigned char 48) line 381
CryptoPP::BERSequenceDecoder::BERSequenceDecoder(CryptoPP::BERSequenceDecoder & {...}, unsigned char 48) line 182 + 23 bytes
CryptoPP::PKCS8PrivateKey::BERDecode(CryptoPP::BufferedTransformation & {...}) line 546 + 14 bytes
CryptoPP::InvertibleRSAFunction::BERDecode(CryptoPP::BufferedTransformation & {...}) line 65 + 22 bytes
CryptoPP::PK_FinalTemplate<CryptoPP::TF_DecryptorImpl<CryptoPP::TF_CryptoSchemeOptions<CryptoPP::TF_ES<CryptoPP::OAEP<CryptoPP::SHA,CryptoPP::P1363_MGF1>,CryptoPP::RSA,int>,CryptoPP::RSA,CryptoPP::OAEP<CryptoPP::SHA,CryptoPP::P1363_MGF1> > > >::PKc90a7c68(CryptoPP::BufferedTransformation & {...}, unsigned int 1) line 1530 + 150 bytes
License::decrypt(const char * 0x00900804, const char * 0x102956a4) line 100 + 20 bytes
The key works just fine in 4.2.  Walking 5.2.1 and 4.2 in parallel, the difference to be code in 4.2 absent from 5.2.1:
InvertibleRSAFunction::InvertibleRSAFunction(BufferedTransformation &bt)
{
    BERSequenceDecoder privateKeyInfo(bt);
    word32 version;
    BERDecodeUnsigned<word32>(privateKeyInfo, version, INTEGER, 0, 0);    // check version

    if (privateKeyInfo.PeekByte() == INTEGER)
    {
        // for backwards compatibility
        n.BERDecode(privateKeyInfo);
In 4.2, the _expression_ "privateKeyInfo.PeekByte() == INTEGER" is true.

This is obviously a compatibility problem.  Is there a) a way to get 5.2.1 to accept my key, or b) a way to reconstruct my keys from 4.2 to 5.2.1.

I was quite content with 4.2, which strikes me has smaller and more suitable for embedded use, but I have been unable to get it work on AMD64.  I really need only RSA, SHA, DES, and probably AES for the future, so almost any cross platform solution is acceptable, whether 4.2 or 5.2.1.

Reply via email to