Last active
July 5, 2016 21:20
-
-
Save omarkdev/bf0f0942910e801aa7015cb79f8b8c52 to your computer and use it in GitHub Desktop.
Encryption and Decryption in PHP
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 | |
class mCode{ | |
protected function enc($string){ | |
$output = false; | |
$encrypt_method = "AES-256-CBC"; | |
$secret_key = 'secret-key-1'; | |
$secret_iv = 'secret-key-2'; | |
$key = hash('sha256', $secret_key); | |
$iv = substr(hash('sha256', $secret_iv), 0, 16); | |
$output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv); | |
$output = base64_encode($output); | |
return $output; | |
} | |
protected function dec($string){ | |
$output = false; | |
$encrypt_method = "AES-256-CBC"; | |
$secret_key = 'secret-key-1'; | |
$secret_iv = 'secret-key-2'; | |
$key = hash('sha256', $secret_key); | |
$iv = substr(hash('sha256', $secret_iv), 0, 16); | |
$output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); | |
return $output; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment