Sample Program:
#include <iostream>
#include <iomanip>
// Crypto
#include "cryptopp/modes.h"
#include "cryptopp/aes.h"
#include "cryptopp/filters.h"
int main(int argc, char* argv[])
{
//AES encryption uses a secret key (DEFAULT_KEYLENGTH= 16 bytes)
byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[
CryptoPP::AES::BLOCKSIZE ];
memset( key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH );
memset( iv, 0x00, CryptoPP::AES::BLOCKSIZE );
// Local string variables
std::string inputText = "hello world.";
std::string encryptedText;
std::string decryptedtext;
// Dump Input Text
std::cout << "Input Text (" << inputText.size() << " bytes)" <<
std::endl;
std::cout << inputText;
std::cout << std::endl << std::endl;
// Create Encrypted Text
CryptoPP::AES::Encryption aesEncryption(key,
CryptoPP::AES::DEFAULT_KEYLENGTH);
CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption(
aesEncryption, iv );
CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new
CryptoPP::StringSink( encryptedText ) );
stfEncryptor.Put( reinterpret_cast<const unsigned char*>(
inputText.c_str() ), inputText.length() + 1 );
stfEncryptor.MessageEnd();
// Dump Encrypted Text
std::cout << "Encrypted Text (" << encryptedText.size() << " bytes)" <<
std::endl;
for( int i = 0; i < encryptedText.size(); i++ ) {
std::cout << "0x" << std::hex << (0xFF &
static_cast<byte>(encryptedText[i])) << " ";
}
std::cout << std::endl << std::endl;
// Decrypt
CryptoPP::AES::Decryption aesDecryption(key,
CryptoPP::AES::DEFAULT_KEYLENGTH);
CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption(
aesDecryption, iv );
CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new
CryptoPP::StringSink( decryptedtext ) );
stfDecryptor.Put( reinterpret_cast<const unsigned char*>(
encryptedText.c_str() ), encryptedText.size() );
stfDecryptor.MessageEnd();
// Dump Decrypted Text
std::cout << "Decrypted Text: " << std::endl;
std::cout << decryptedtext;
std::cout << std::endl << std::endl;
return 0;
}
On Tuesday, February 19, 2013 1:26:11 PM UTC+5:30, Rajat Budhiraja wrote:
>
> Hello Everybody
>
> I am new to CryptoPP and intend to use the AES algorithm from it. I have
> downloaded and installed the Version 5.6.1 on a Linux machine. I found a
> sample AES program on Internet and got it to compile and execute
> successfully. But, this program is randomly generating keys; then
> encrypting and decrypting the data.
>
> My question is how to use specific values (e.g. "abcd" or "4567") as keys
> or use these to generate keys and encrypt the plain-text data (and, not use
> randomly generated keys), because I need to decrypt the data on the other
> end as well (and for that I need the key on the other end as well).
>
> Does Cryptopp AES supports this?
>
> Any help on this will be appreciated.
> I can share the sample program if needed.
>
> Thanks
>
--
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.