From Crypto++ Wiki
Jump to navigation Jump to search

BEREncode encodes an object using ASN.1 BER encoding. BER encoding may be useful if DEREncode would be too inefficient. The default implementation of BEREncode calls DEREncode. The companion to BEREncode is BERDecode.

Each class object has their own format for encoding. The documentation for the class usually specifies the standard used to encode an object.

Also see Keys and Formats wiki page.


// Grab a Generator
CryptoPP::AutoSeededRandomPool rng;

// Specify modulus, accept e = 17. 128-bits is artificially small.
CryptoPP::RSAES_OAEP_SHA_Decryptor Decryptor( rng, 128 /*, e */ );
CryptoPP::RSAES_OAEP_SHA_Encryptor Encryptor( Decryptor );

// BER Encoded Keys
std::string pbkey, pvkey;

// Hex Encoder
CryptoPP::HexEncoder encoder;

// Public Key
encoder.Attach( new CryptoPP::StringSink( pbkey ) );
Encryptor.GetPublicKey().Save( encoder );

// Private Key
encoder.Attach( new CryptoPP::StringSink( pvkey ) );
Encryptor.GetPrivateKey().Save( encoder );

Downloads - Sample Program exercising BER Encoding and Decoding