DecodingResult

From Crypto++ Wiki
Jump to navigation Jump to search

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::runtime_error("Crypto++: decryption failed");
}
#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::runtime_error("Crypto++: decryption failed");
}