Created
December 26, 2013 04:24
-
-
Save emayk/8129752 to your computer and use it in GitHub Desktop.
crypt example 1
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 | |
define("ENCRYPTION_KEY", "!@#$%^&*"); | |
$string = "This is the original data string!"; | |
echo $encrypted = encrypt($string, ENCRYPTION_KEY); | |
echo "<br />"; | |
echo $decrypted = decrypt($encrypted, ENCRYPTION_KEY); | |
/** | |
* Returns an encrypted & utf8-encoded | |
*/ | |
function encrypt($pure_string, $encryption_key) { | |
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB); | |
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); | |
$encrypted_string = mcrypt_encrypt(MCRYPT_BLOWFISH, $encryption_key, utf8_encode($pure_string), MCRYPT_MODE_ECB, $iv); | |
return $encrypted_string; | |
} | |
/** | |
* Returns decrypted original string | |
*/ | |
function decrypt($encrypted_string, $encryption_key) { | |
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB); | |
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); | |
$decrypted_string = mcrypt_decrypt(MCRYPT_BLOWFISH, $encryption_key, $encrypted_string, MCRYPT_MODE_ECB, $iv); | |
return $decrypted_string; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment