· 5 years ago · Dec 19, 2019, 08:36 AM
1<?php
2
3$string = "r00000010001";
4
5$encrypt_method = "AES-256-CBC";
6$secret_key = '7CEsPlLfVXcHf2S4wsnPnfNqYa+N/D/1zCXExN4aJSs=';
7$secret_iv = 'StqUaIcbO9LFZ9QiuguXR6M/BepqZDV8p1now0FA/C4=';
8// hash
9$key = hash('sha256', $secret_key);
10
11// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
12$iv = substr(hash('sha256', $secret_iv), 0, 16);
13$output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
14$output = base64_encode($output);
15echo $output . "\r\n";
16
17echo openssl_decrypt(base64_decode($output), "AES-256-CBC", $key, 0, $iv);