Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Define a 32-byte (64 character) hexadecimal encryption key
- // Note: The same encryption key used to encrypt the data must be used to decrypt the data
- define('ENCRYPTION_KEY', '75bbd89dcc2878554122f2909d7916873c6bb37dfd5fafee3c26e81c439a88b1');
- // Encrypt Function
- function mc_encrypt($encrypt, $key){
- $encrypt = json_encode($encrypt);
- //print_r($encrypt);
- $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM);
- $key = pack('H*', $key);
- $mac = hash_hmac('sha256', $encrypt, substr(bin2hex($key), -32));
- $passcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $encrypt.$mac, MCRYPT_MODE_CBC, $iv);
- $encoded = base64_encode($passcrypt).'|'.base64_encode($iv);
- return $encoded;
- }
- // Decrypt Function
- function mc_decrypt($decrypt, $key){
- $decrypt = explode('|', $decrypt.'|');
- $decoded = base64_decode($decrypt[0]);
- $iv = base64_decode($decrypt[1]);
- if(strlen($iv)!==mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC)){ return false; }
- $key = pack('H*', $key);
- $decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $decoded, MCRYPT_MODE_CBC, $iv));
- $mac = substr($decrypted, -64);
- $decrypted = substr($decrypted, 0, -64);
- $calcmac = hash_hmac('sha256', $decrypted, substr(bin2hex($key), -32));
- if($calcmac!==$mac){ return false; }
- $decrypted = json_decode($decrypted);
- return $decrypted;
- }
- ..
- value=<?=mc_encrypt(array(
- $id,
- $name,
- ), ENCRYPTION_KEY);?>
- $Data=mc_decrypt($Data, ENCRYPTION_KEY);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement