Last active
July 18, 2022 17:49
-
-
Save g105b/b5a7c815275aa3cb03a15ed1eb39dde8 to your computer and use it in GitHub Desktop.
Encrypt-decrypt using openssl on the commandline
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
#!/bin/bash | |
key="sup3r_s3cr3t_p455w0rd" | |
decrypted=$(openssl enc \ | |
-aes-256-ctr \ | |
-d \ | |
-k "$key" \ | |
-iv "504914019097319c9731fc639abaa6ec" \ | |
-in encrypted.txt) | |
echo "Decrypted message: $decrypted" | |
# Output: Decrypted message: This is my message, I hope you can see it. It's very long now. |
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
<?php | |
$encrypted = trim(file_get_contents("encrypted.txt")); | |
$iv = hex2bin("504914019097319c9731fc639abaa6ec"); | |
$decrypted = openssl_decrypt( | |
$encrypted, | |
"aes-256-ctr", | |
"sup3r_s3cr3t_p455w0rd", | |
0, | |
$iv, | |
); | |
echo "Decrypted message: $decrypted"; | |
# Output: Decrypted message: ��c��������Pb�j�� |
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
#!/bin/bash | |
message="This is my message, I hope you can see it. It's very long now." | |
key="sup3r_s3cr3t_p455w0rd" | |
echo "$message" | openssl enc \ | |
-aes-256-ctr \ | |
-e \ | |
-k "$key" \ | |
-iv "504914019097319c9731fc639abaa6ec" \ | |
-out encrypted.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment