Skip to content

Instantly share code, notes, and snippets.

@g105b
Last active July 18, 2022 17:49
Show Gist options
  • Save g105b/b5a7c815275aa3cb03a15ed1eb39dde8 to your computer and use it in GitHub Desktop.
Save g105b/b5a7c815275aa3cb03a15ed1eb39dde8 to your computer and use it in GitHub Desktop.
Encrypt-decrypt using openssl on the commandline
#!/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.
<?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��
#!/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