Hi,
I want to use AES encryption in CFB mode. For experiments, I am using
the attached program. It generates a random key and an initialization
vector. It then encrypts all command line arguments and displays the HEX
encoded encrypted strings. Here is what it looks like:
$ testEncryptor 1111 1112 1113 1114
1111: E2B2334F
1112: E2B2334C
1113: E2B2334D
1114: E2B2334A
The encrypted results are almost identical.
I am aware that I am using the same IV for all arguments, but still I
would have expected similar input would NOT result in similar output. I
meam, the four input values differ in just one Byte and same is true for
their encrypted version? Somehow it seems that encryption is done Byte
by Byte. Can I change that?
Thanks and regards,
Roland
--
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.
// System includes
#include <iostream>
// Library includes
#include <cryptopp/aes.h>
#include <cryptopp/modes.h>
#include <cryptopp/filters.h>
#include <cryptopp/osrng.h>
#include <cryptopp/hex.h>
using namespace std;
using namespace CryptoPP;
int main(int argc, char* argv[])
{
if (argc < 2)
{
cerr << "Usage: " << argv[0] << " {<strings to be encrypted>}" << endl;
return 1;
}
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);
for (int i = 1; i < argc; ++i)
{
string cipherText;
CFB_Mode<AES>::Encryption encryptor( key, sizeof(key), iv);
StringSource encryptionFilter(argv[i], true, new StreamTransformationFilter(encryptor, new HexEncoder(new StringSink(cipherText))));
encryptionFilter.PumpAll();
cout << argv[i] << ": " << cipherText << endl;
}
return 0;
}