BEREncode

From Crypto++ Wiki

Jump to: navigation, search

By default, sending a Encyption or Decryption object to a FileSink DER encodes the file. DEREncoding is specified by PKCS #8. See also RSA Key Format Compatibility Problem on the Crypto++ User Group.

[edit] Examples

// Grab a Generator
CryptoPP::AutoSeededRandomPool rng;

// Specify modulus, accept e = 17
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 );

/////////////////////////////////////////////////////////
// string k should begin with 0x30 (or simply 30)
//   0x30 is SEQUENCE_TAG.
// The rsa400pb.dat, rsa400pv.dat, rsa1024.dat,
//   rsa2048.dat files also use this format.

[edit] Sample Programs

BERTest.zip - Sample Program exercising BER Encoding and Decoding

Personal tools