Skip to content

Instantly share code, notes, and snippets.

@kamihouse
Created January 17, 2013 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamihouse/4554135 to your computer and use it in GitHub Desktop.
Save kamihouse/4554135 to your computer and use it in GitHub Desktop.
<?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