Skip to content

Instantly share code, notes, and snippets.

@i2x
Created June 2, 2020 15:50
Show Gist options
  • Save i2x/892b834d42da98ca078ef2f6bc5b1e77 to your computer and use it in GitHub Desktop.
Save i2x/892b834d42da98ca078ef2f6bc5b1e77 to your computer and use it in GitHub Desktop.
<?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