Googleinurl

[Class] Criptografia SHA256 PHP

Dec 10th, 2014
759
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class Criptografia {
  4.  
  5.     private $chave = null, $iv = null;
  6.  
  7.     function __construct($senha) {
  8.         $this->chave = hash('SHA256', $senha, TRUE);
  9.         $this->iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_DEV_RANDOM);
  10.     }
  11.  
  12.     function encrypt($input) {
  13.         return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->chave, $input, MCRYPT_MODE_ECB, $this->iv));
  14.     }
  15.  
  16.     function decrypt($input) {
  17.         return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->chave, base64_decode($input), MCRYPT_MODE_ECB, $this->iv));
  18.     }
  19.  
  20. }
RAW Paste Data