Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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