Skip to main content
4 of 4
deleted 25 characters in body
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 238

Shell Script: Decrypt the encrypted password and store it in variable

I have a file "credential.txt" which contains the password of mysql. I have another script which calls this text file and retrieves the password from it. For security purposes, I don't want to store the password directly. For that I have encrypted the file by using the Triple-DES Cipher encryption:

openssl des3 -salt -in credential.txt -out credential.des3

Reference: https://linuxtidbits.wordpress.com/2009/01/12/encryptingdecrypting-a-file-easily-with-a-couple-bash-scripts/

Now from my shell script, I want to get the encrypted password from credential.des3, and store it in a variable. From the referenced article, it shows how to decrypt the file and store the decrypted password in a different file.

openssl des3 -d -salt -in credential.des3 -out unencrypted-data.file

The thing is I don't want to save the decrypted file on the system. I want to capture the output of decrypting. My shell script is automated to run using cronjobs, so I can't ask the user to specify the password. Is there any way to decrypt the password and store it in a variable like:

var = $(decrypted_pass)

and use it whenever necessary in a shell script.

I have tried the below command, but it not working.

var=$(openssl das3 -salt -in credential.des3)

Rose
  • 143
  • 1
  • 3
  • 8