Advertisement
Guest User

Untitled

a guest
May 23rd, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. <?php
  2.  
  3. function safe_b64encode($string) {
  4. $skey = "your_key";
  5. $data = base64_encode($string);
  6. $data = str_replace(array('+','/','='),array('-','_',''),$data);
  7. return $data;
  8. }
  9.  
  10. function safe_b64decode($string) {
  11. $skey = "your_key";
  12. $data = str_replace(array('-','_'),array('+','/'),$string);
  13. $mod4 = strlen($data) % 4;
  14. if ($mod4) {
  15. $data .= substr('====', $mod4);
  16. }
  17. return base64_decode($data);
  18. }
  19.  
  20. function crypto_irf($value){
  21.  
  22. if(!$value)
  23. {
  24. return false;
  25. }
  26. $skey = "your_key";
  27. $text = $value;
  28. $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
  29. $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
  30. $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $skey, $text, MCRYPT_MODE_ECB, $iv);
  31. return trim(safe_b64encode($crypttext));
  32. }
  33.  
  34. function decrypto_irf($value){
  35.  
  36. if(!$value)
  37. {
  38. return false;
  39. }
  40. $skey = "your_key";
  41. $crypttext = safe_b64decode($value);
  42. $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
  43. $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
  44. $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $skey, $crypttext, MCRYPT_MODE_ECB, $iv);
  45. return trim($decrypttext);
  46. }
  47.  
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement