Pages

06 November 2009

Encrypt a password in linux (Bash Scripting)

root@dogmatix # echo -n "password" | openssl enc -des3 -k mysalt | openssl enc -base64
root@dogmatix # U2FsdGVkX18knoSdb82OZtpgSCXKztozJH4n9LShLyg=

This line above is now an encrypted password, that you can store in text files, on websites or anywhere else for the world to see. People will not be able to decrypt it unless they know the salt value (mysalt), or the encryption type (base64).

To decrypt this you will need to do the following: 

root@dogmatix # echo "U2FsdGVkX18knoSdb82OZtpgSCXKztozJH4n9LShLyg=" | openssl enc -base64 -d | openssl enc -des3 -k mysalt -d 
root@dogmatix # password