Created
June 2, 2020 15:50
-
-
Save i2x/892b834d42da98ca078ef2f6bc5b1e77 to your computer and use it in GitHub Desktop.
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 | |
$user_name = "{'name': 'peet','timestamp' : " . time() . "}"; | |
$encrypt_method = "aes128"; | |
$secret_key = '123'; | |
$secret_iv = '456'; | |
// hash | |
$key = hash('sha256', $secret_key); | |
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a | |
// warning | |
$iv = substr(hash('sha256', $secret_iv), 0, 16); | |
$output = openssl_encrypt($user_name, $encrypt_method, $key, 0, $iv); | |
print_r($output . "<br><br>"); | |
$output = openssl_decrypt($output, $encrypt_method, $key, 0, $iv); | |
print($output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment