Created
April 17, 2012 14:53
-
-
Save jvehent/2406497 to your computer and use it in GitHub Desktop.
password manager with openssl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To create a new credential file, use: | |
echo "credential file created on $(date +%Y%m%d)" |openssl aes-256-ecb -e -a -salt -out credential_file.encrypted | |
# ======================================= | |
#!/usr/bin/env bash | |
# --- getpassword.sh | |
# opens the credential file and display it in the terminal | |
if [[ -x "$1" || ! -r "$1" ]]; then | |
echo "usage: $0 <ciphered file>" | |
exit 1 | |
fi | |
SECFILE=$1 | |
CLEARTEXT=$(openssl aes-256-ecb -d -a -salt -in $SECFILE) | |
if [ $? -gt 0 ]; then | |
echo "Wrong password, cannot decrypt" | |
exit $? | |
else | |
echo "$CLEARTEXT" | |
fi | |
# ======================================= | |
#!/usr/bin/env bash | |
# --- storepassword.sh | |
# store a password in the credential file | |
if [[ $1 = "" || ! -r $1 ]]; then | |
echo "usage: $0 <ciphered file>" | |
exit 1 | |
fi | |
SECFILE=$1 | |
# decipher access file | |
echo -n "enter crypto password > " | |
read -s CRYPTOPASSWD | |
echo | |
CLEARTEXT=$(openssl aes-256-ecb -d -a -salt -in $SECFILE -pass pass:$CRYPTOPASSWD) | |
if [ $? -gt 0 ]; then | |
echo "Wrong password, cannot decrypt" | |
exit $? | |
fi | |
# get new value to store | |
echo "enter value to append (1 line)" | |
echo -n "> " | |
read PASSWD | |
UPDATED_CLEARTEXT=$(echo -e "$CLEARTEXT\n$PASSWD") | |
# cipher access file and delete temporary file | |
echo "$UPDATED_CLEARTEXT"| openssl aes-256-ecb -e -a -salt -out $SECFILE.updated -pass pass:$CRYPTOPASSWD | |
if [ $? -gt 0 ] | |
then | |
echo "Password encryption failed, password not stored in $SECFILE" | |
exit $? | |
else | |
mv $SECFILE.updated $SECFILE | |
echo "information successfully encrypted and store in $SECFILE" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment