DecodingResult

From Crypto++ Wiki
Jump to: navigation, search
DecodingResult
Documentation
#include <cryptopp/cryptlib.h>


DecodingResult is used to verify the Decryption process. The DecodingResult class reference can be found at the Class Reference.

Sample

// Decryption
CryptoPP::DecodingResult Result = Decryptor.Decrypt( ... );

// Crypto++ Test
if( false == Result.isValidCoding )
   { throw std::string("Crypto++: Invalid Coding"); }
#define ECC_ALGORITHM CryptoPP::ECP
#define ECC_CURVE CryptoPP::ASN1::secp160r1()

CryptoPP::ECIES< ECC_ALGORITHM >::PrivateKey PrivateKey;
CryptoPP::ECIES< ECC_ALGORITHM >::PublicKey PublicKey;
CryptoPP::AutoSeededRandomPool rng;

// Curve Key Generation
PrivateKey.Initialize( rng, ECC_CURVE );
PrivateKey.MakePublicKey( PublicKey );

// Encryptor and Decryptor
CryptoPP::ECIES< ECC_ALGORITHM >::Encryptor
   Encryptor( PublicKey );
CryptoPP::ECIES< ECC_ALGORITHM >::Decryptor
   Decryptor( PrivateKey );

// Message
std::string PlainText = "Yoda said, Do or do not. There is no try.";

...

// Encryption
Encryptor.Encrypt( rng, reinterpret_cast<const byte*>
   ( PlainText.c_str() ), PlainTextLength, CipherText );

...

// Decryption
DecodingResult Result = Decryptor.Decrypt( rng, CipherText, CipherTextLength,
   reinterpret_cast<byte*>( RecoveredText ) );

// Crypto++ Test
if( false == Result.isValidCoding )
   { throw std::string("Crypto++: Invalid Coding"); }