Re: Re: Decryption

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I think this will solve your problems, here is real working code.

class ENCRYPTION
{
   var $KEY = "NEED_A_DECENT_KEY";

   //Encrypt Function
   function encrypt($string)
   {
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND); $passcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->KEY, $string, MCRYPT_MODE_ECB, $iv);
       $encoded = base64_encode($passcrypt);
       return $encoded;
}
   //Decrypt Function
   function decrypt($string)
   {
       $decoded = base64_decode($string);
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND); $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->KEY, $decoded, MCRYPT_MODE_ECB, $iv);
       return trim($decrypted);
   }
}

DvDmanDT wrote:
.. What exactly are you trying to do? If you are trying to decrypt user input, then no, it's not going to work.. You'll have to read the input first, then pass that to mcrypt_decrypt, then write that to your outfile..

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux