<?php function HexStringToByte($hexString) { $string = hex2bin($hexString); return $string; } function encrypt_string($string='', $key=''){ $iv_size = 16; $iv = "1212121212121212"; $blocksize = 16; $pad = $blocksize - (strlen($string) % $blocksize); $string = $string . str_repeat(chr($pad), $pad); return base64_encode($iv.openssl_encrypt($string, 'aes-128-cbc', $key, OPENSSL_RAW_DATA, $iv)); } function decrypt_string($data, $key) { $ciphertext_dec = base64_decode($data) ; $iv_size = 16; $iv_dec = substr($ciphertext_dec, 0, $iv_size); $ciphertext_dec = substr($ciphertext_dec, $iv_size); return openssl_decrypt($ciphertext_dec, 'aes-128-cbc', $key, OPENSSL_RAW_DATA, $iv_dec); } //$ciphertext = encrypt_string('Neeraj',HexStringToByte('0A6D4D8794371FC45B1E85368E38BE75')); //print_r($ciphertext); $ds = decrypt_string("jhI5nAdyb1qOEjmcB3JvWkrXzfs0jaJJIVMgqaElpdQ=",HexStringToByte('0A6D4D8794371FC45B1E85368E38BE75')); print_r($ds); exit;
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more