Created
March 6, 2016 16:49
-
-
Save locked/b537bf726f94a1c51fbf to your computer and use it in GitHub Desktop.
AES CBC PHP & CLI
This file contains hidden or 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
// This code generate AES block compatible with how Go does things | |
$string = "string to encrypt"; | |
$key = "my secret key"; | |
$iv = openssl_random_pseudo_bytes(16); | |
echo base64_encode($iv.openssl_encrypt($string, "aes-256-cbc", $key, OPENSSL_RAW_DATA, $iv)); | |
// The shell equivalent: | |
// echo 'string to encrypt' | openssl enc -aes-256-cbc -nosalt -K $KEY -iv acfa7a047800b2f221f2c4f7d626eafb | base64 | |
// In which: | |
// $KEY is the hex string of the binary, padded, key | |
// $IV is the hex string of the binary IV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment