Hi jacek,
One problem in crypto++5.4 library. In the sample code test.cpp provided by crypto++ library, it tells me
- To encrypt a file with AES in CTR mode
cryptest ae input output
- To encrypt a file with AES in CTR mode
cryptest ae input output
To copy to clipboard, switch view to plain text mode
but when I pass these as arguments in command line I get this error
"CryptoPP::Exception caught: AES/CTR: 1 is not a valid key length"
"CryptoPP::Exception caught: AES/CTR: 1 is not a valid key length"
To copy to clipboard, switch view to plain text mode
Then I went through the code to check what is wrong?? I realized I need to pass 6 arguments namely
cryptest ae key IV input output
cryptest ae key IV input output
To copy to clipboard, switch view to plain text mode
where IV is initialization vector
Now I have one question, Suppose I have a password "somepassword". How do I calculate key and IV for this somepassword. I tried using some dummy value
"2b7e151628aed2a6abf7158809cf4f3c" as my key;
"000102030405060708090a0b0c0d0e0f" as my initialization vector;
"2b7e151628aed2a6abf7158809cf4f3c" as my key;
"000102030405060708090a0b0c0d0e0f" as my initialization vector;
To copy to clipboard, switch view to plain text mode
The file got encrypted. But I want to calculate key and IV based on password.
Please tell me using some sample code. I'll be thankful to you...
Then there is another problem.
crypto++ library gives code for only encryption. How can I decrypt the file with same password "somepassword". I tried using decrypt instead of encrypt, but I'm not sure what I'm doing is correct or not.
Here is the sample code for decryption
void AES_CTR_Decrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile)
{
SecByteBlock key = HexDecodeString(hexKey);
SecByteBlock iv = HexDecodeString(hexIV);
CTR_Mode<AES>::Decryption aes(key, key.size(), iv);
FileSource(infile, true, new StreamTransformationFilter(aes, new FileSink(outfile)));
}
void AES_CTR_Decrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile)
{
SecByteBlock key = HexDecodeString(hexKey);
SecByteBlock iv = HexDecodeString(hexIV);
CTR_Mode<AES>::Decryption aes(key, key.size(), iv);
FileSource(infile, true, new StreamTransformationFilter(aes, new FileSink(outfile)));
}
To copy to clipboard, switch view to plain text mode
Bookmarks