PDA

View Full Version : Encryption and decryption


vermarajeev
16th August 2007, 12:31
Hello guys,
I have written functionality to encrypt and decrypt the file using perl script. Now I want to port this script to crypto++ libaray functionality.
Here is the perl script code,
//For encryption
my $cipher = Crypt::CBC->new(
-cipher => "Crypt::Rijndael",
-key => $key,
-header => 'salt',
);
$cipher->start( 'encrypting' );

while ( read( $original_file, $buffer, 1024 ) ) {
print $encrypted_file
$cipher->crypt( $buffer );
}

//For decryption
my $cipher = Crypt::CBC->new(
-cipher => "Crypt::OpenSSL::AES",
-key => $key,
-header => 'salt',
);
$cipher->start( 'decrypting' );

while ( read( $encrypted_file, $buffer, 1024 ) ) {
print $decrypted_file
$cipher->crypt( $buffer );
}
I can find the alternative to Crypt::Rijndael in crypto++ lib, but what is the alternative to Crypt::OpenSSL::AES in crypto++ library.

Thanks in advance,

jacek
16th August 2007, 23:51
I can find the alternative to Crypt::Rijndael in crypto++ lib, but what is the alternative to Crypt::OpenSSL::AES in crypto++ library.
Rijndael is AES.

vermarajeev
17th August 2007, 05:45
Rijndael is AES.

Hi Jacek,
Thank you for your reply.

I know Rijndael is AES but what about "Crypt::OpenSSL::AES" while decrypting the file?
The encrypted file should be compatible with OpenSSL.

wysota
17th August 2007, 13:41
AES is AES, no matter which library implements it.

vermarajeev
27th August 2007, 14:55
Ok for a while I forget about perl script.

Here is a basic question about encryption/decryption.

I encrypt a file with AES::CBC mode using a random IV( Initialization Vector ). Now how do I get back the same IV for decrypting the encrypted file?

If I use my defined hard coded IV I'm able to decode the file with no problem (as I know what the IV is) but I want to use a random IV to encrypt a file and then want to decrypt the encrypted file.

The pseudo can is something like this

void encryptFile( const char* password, const char* inFile, const char* outFile)
{
//Get random IV named iv
//Digest the password named pass
AES::Encryption aesEncryption(pass, CryptoPP::AES::DEFAULT_KEYLENGTH);
CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, iv);
//Encrypt the file
}

void decryptFile( const char* password, const char* inFile, const char* outFile)
{
//Now to decrypt the encrypted file I need to have the same IV
// with which the file was encrypted to decrypt it.
//I dont know how to get it

//Get the IV from the encrypted file
//digest the password
//Finally decrypt the encrypted file.

}

In the above code I dont know how to get the same IV by which the file was encrypted. Any idea?

If possible please give your answers taking crypto++ library in view.

Thanks.

wysota
27th August 2007, 22:17
As far as I understand it, you can't. You just have to know it, like make it a part of the ciphertext :)