Skip to content

Instantly share code, notes, and snippets.

@taikedz
Last active October 18, 2018 16:17
Show Gist options
  • Save taikedz/fb89c1f7b5c275fe70125852b9fe1e85 to your computer and use it in GitHub Desktop.
Save taikedz/fb89c1f7b5c275fe70125852b9fe1e85 to your computer and use it in GitHub Desktop.
Decrypt a symmetric password encrypted string using openssl, and put it in the x-clipboard (`shift + insert` to paste) uing xclip
# Example to create an encrypted string:
# echo "hi"|openssl aes-256-cbc -a
# the decryption example below is for password "pass"
# requires openssl and xclip
give-my-token() {
# Using 1.1.0+
echo "U2FsdGVkX1/uwQA5Uc/F8vTYJEWZcgcuY+V9DVQovNs="|openssl aes-256-cbc -a -d 2>/dev/null|xclip || {
echo "Could not decrypt."
return 1
}
echo "(written to x-clipboard)"
}
@taikedz
Copy link
Author

taikedz commented Oct 18, 2018

Note that the versions of OpenSSL must match to decrypt data OpenSSL may break compatibility between versions. For example, data encrypted with OpenSSL 1.0.2g 1 Mar 2016 cannot be decrypted using OpenSSL 1.1.0g 2 Nov 2017 and a correct password.

This was due to a change in hash algorithm in the lead-up to 1.1.0 and a workaround can be used to force the old behaviour. For obvious reasons, it's best to use the new behaviour, and update all encrypted files where appropriate.

To decrypt an old ciphertext with 1.1.0+, use the arguments -md md5 (-md was added to openssl sometime between the aforementioned versions precisely for this compatibility workaround)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment