· 8 years ago · Jan 08, 2018, 08:04 PM
1<?php
2function enc($action, $string) {
3 $output = false;
4 $encrypt_method = "AES-256-CBC";
5 $secret_key = 'niluf';
6 $secret_iv = 'iv1';
7
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
14 if( $action == 'encrypt' ) {
15 $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
16 $output = base64_encode($output);
17 }
18 return $output;
19}
20$data = enc(json_encode($_POST));
21file_put_contents ( "filename.txt" , $data , FILE_APPEND);
22echo encrypt_decrypt("encrypt","ejBLWG1CM1VMUkYxMWQreDZEM3dOUT09");
23?>