Skip to content

Instantly share code, notes, and snippets.

@gadelkareem
Last active June 11, 2019 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gadelkareem/4c04ef37ddbf83d7015c to your computer and use it in GitHub Desktop.
Save gadelkareem/4c04ef37ddbf83d7015c to your computer and use it in GitHub Desktop.
OpenSSL encrypt-decrypt examples

###Encrypt

php -r "echo openssl_encrypt('Hello OpenSSL', 'AES-256-CBC', 'SecretPass', 0, '6299868101947302');"

TLHG68yaaVtSsV3zOYtn2Q==

printf "Hello OpenSSL" | openssl enc -a -e -aes-256-cbc -K $(printf "SecretPass" | od -A n -t x1 | tr -d '\040\011\012\015') -iv $(printf "6299868101947302" | od -A n -t x1 | tr -d '\040\011\012\015')

TLHG68yaaVtSsV3zOYtn2Q==

###Decrypt

php -r "echo openssl_decrypt('TLHG68yaaVtSsV3zOYtn2Q==', 'AES-256-CBC', 'SecretPass', 0, '6299868101947302');"

Hello OpenSSL

echo "TLHG68yaaVtSsV3zOYtn2Q==" | openssl enc -a -d -aes-256-cbc -K $(printf "SecretPass" | od -A n -t x1 | tr -d '\040\011\012\015') -iv $(printf "6299868101947302" | od -A n -t x1 | tr -d '\040\011\012\015')

Hello OpenSSL

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