Created
January 17, 2013 06:26
-
-
Save kamihouse/4554135 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* en -> Simple class for encrypting passwords using Advanced Encryption Standard (AES) 256-bit | |
* pt -> Classe simples para criptografia de senhas usando Advanced Encryption Standard (AES) 256-bit | |
*/ | |
class Password { | |
private static $key= "NeB36lAm30&"; // Random key for encryption | |
public static function encript($password) { | |
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); | |
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); | |
$encripted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, self::key, $password, MCRYPT_MODE_ECB, $iv); | |
return base64_encode($encripted); | |
//return rand(1, 9) . base64_encode($encripted); | |
} | |
public static function decript($password) { | |
$encripted = base64_decode($password); | |
//$encripted = base64_decode(substr($password, 1)); | |
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); | |
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); | |
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, self::key, $encripted, MCRYPT_MODE_ECB, $iv)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment