Results 1 to 6 of 6

Thread: Encryption and decryption

  1. #1
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Encryption and decryption

    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
    Qt Code:
    1. my $cipher = Crypt::CBC->new(
    2. -cipher => "Crypt::Rijndael",
    3. -key => $key,
    4. -header => 'salt',
    5. );
    6. $cipher->start( 'encrypting' );
    7.  
    8. while ( read( $original_file, $buffer, 1024 ) ) {
    9. print $encrypted_file
    10. $cipher->crypt( $buffer );
    11. }
    To copy to clipboard, switch view to plain text mode 

    //For decryption
    Qt Code:
    1. my $cipher = Crypt::CBC->new(
    2. -cipher => "Crypt::OpenSSL::AES",
    3. -key => $key,
    4. -header => 'salt',
    5. );
    6. $cipher->start( 'decrypting' );
    7.  
    8. while ( read( $encrypted_file, $buffer, 1024 ) ) {
    9. print $decrypted_file
    10. $cipher->crypt( $buffer );
    11. }
    To copy to clipboard, switch view to plain text mode 
    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,

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Encryption and decryption

    Quote Originally Posted by vermarajeev View Post
    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.

  3. #3
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Encryption and decryption

    Quote Originally Posted by jacek View Post
    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Encryption and decryption

    AES is AES, no matter which library implements it.

  5. #5
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Encryption and decryption

    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

    Qt Code:
    1. void encryptFile( const char* password, const char* inFile, const char* outFile)
    2. {
    3. //Get random IV named iv
    4. //Digest the password named pass
    5. AES::Encryption aesEncryption(pass, CryptoPP::AES::DEFAULT_KEYLENGTH);
    6. CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, iv);
    7. //Encrypt the file
    8. }
    9.  
    10. void decryptFile( const char* password, const char* inFile, const char* outFile)
    11. {
    12. //Now to decrypt the encrypted file I need to have the same IV
    13. // with which the file was encrypted to decrypt it.
    14. //I dont know how to get it
    15.  
    16. //Get the IV from the encrypted file
    17. //digest the password
    18. //Finally decrypt the encrypted file.
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Encryption and decryption

    As far as I understand it, you can't. You just have to know it, like make it a part of the ciphertext

Similar Threads

  1. Basics of Encryption and decryption
    By vermarajeev in forum General Discussion
    Replies: 4
    Last Post: 26th April 2007, 11:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.