How do i encrypt and decrypt a string with aes-256-cbc encryption using openssl?



  • Usually, you will do this programmatically rather than on the command line.

           -pbkdf2
               Use PBKDF2 algorithm with default iteration count unless otherwise
               specified.
    

    Wiki link to pbkdf2 information: https://en.wikipedia.org/wiki/PBKDF2

    To encrypt, using base64 encoding, encryption using aes-256-cbc.

    $ echo "That's the text"|openssl enc -aes-256-cbc -base64 -pbkdf2
    U2FsdGVkX18LI1TGujfW+DQXUT6yS3GYcS2VyKtcDvc6b1G4gsLkFdIJ47iOHdk+
    

    To decrypt. As the encryption is base64 encoded, first decode using base64 and then decrypt.

    $ echo "U2FsdGVkX18LI1TGujfW+DQXUT6yS3GYcS2VyKtcDvc6b1G4gsLkFdIJ47iOHdk+" | openssl enc -base64 -d | openssl enc -aes-256-cbc -d -pbkdf2
    enter aes-256-cbc decryption password:
    That's the text
    

    To list the support ciphers.

    $ openssl enc -ciphers
    

Log in to reply
 

© Lightnetics 2024