Posted By

bradless on 01/12/11


Tagged

decrypt encrypt mcrypt


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

AllKnightAccess
squall6969


2 way encryption / decryption in PHP w/ mcrypt


 / Published in: PHP
 

URL: http://www.phpsnaps.com/snaps/view/rijndael-256-bit-encryption-using-mcrypt/

Here are some functions I found on the net that will allow you to easily do encryption / decryption as long as you have the mcrypt extension loaded with PHP.

  1. <?
  2. // Encrypt Function
  3. function mc_encrypt($encrypt, $mc_key) {
  4. $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
  5. $passcrypt = trim(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $mc_key, trim($encrypt), MCRYPT_MODE_ECB, $iv));
  6. $encode = base64_encode($passcrypt);
  7. return $encode;
  8. }
  9.  
  10. // Decrypt Function
  11. function mc_decrypt($decrypt, $mc_key) {
  12. $decoded = base64_decode($decrypt);
  13. $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
  14. $decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $mc_key, trim($decoded), MCRYPT_MODE_ECB, $iv));
  15. return $decrypted;
  16. }
  17. ?>

Report this snippet  

You need to login to post a comment.