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
| <?php | |
| // use to generate key : 'openssl rand -hex 32' | |
| function my_encrypt($data, $passphrase) { | |
| $secret_key = hex2bin($passphrase); | |
| $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc')); | |
| $encrypted_64 = openssl_encrypt($data, 'aes-256-cbc', $secret_key, 0, $iv); | |
| $iv_64 = base64_encode($iv); | |
| $json = new stdClass(); | |
| $json->iv = $iv_64; |
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
| <?php | |
| /** | |
| * simple method to encrypt or decrypt a plain text string | |
| * initialization vector(IV) has to be the same when encrypting and decrypting | |
| * | |
| * @param string $action: can be 'encrypt' or 'decrypt' | |
| * @param string $string: string to encrypt or decrypt | |
| * | |
| * @return string | |
| */ |