- 论坛徽章:
- 0
|
Sample Programs
Encrypting and Decrypting Using AES
This example uses in-place encryption and decryption where the input and output buffers are identical:
- AutoSeededRandomPool rnd;
- // Generate a random key
- byte key[AES::DEFAULT_KEYLENGTH];
- rnd.GenerateBlock(key, AES::DEFAULT_KEYLENGTH);
- // Generate a random IV
- byte iv[AES::BLOCKSIZE];
- rnd.GenerateBlock(iv, AES::BLOCKSIZE);
- char plainText[] = "Hello! How are you.";
- int messageLen = (int)strlen(plainText) + 1;
- //////////////////////////////////////////////////////////////////////////
- // Encrypt
- CFB_Mode<AES>::Encryption cfbEncryption(key, sizeof(key), iv);
- cfbEncryption.ProcessData((byte*)plainText, (byte*)plainText, messageLen);
- //////////////////////////////////////////////////////////////////////////
- // Decrypt
- CFB_Mode<AES>::Decryption cfbDecryption(key, sizeof(key), iv);
- cfbDecryption.ProcessData((byte*)plainText, (byte*)plainText, messageLen);
复制代码 |
|