Skip to content

Instantly share code, notes, and snippets.

@justinkelly
Created September 16, 2011 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinkelly/1222159 to your computer and use it in GitHub Desktop.
Save justinkelly/1222159 to your computer and use it in GitHub Desktop.
Simple mcrypt encrypt & decrypt functions for PHP
<?php
$salt ='whatever_you_want'
function simple_encrypt($text)
{
return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $salt, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
}
function simple_decrypt($text)
{
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $salt, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
}
?>
@Bodenhaltung
Copy link

Bodenhaltung commented Apr 24, 2017

Sorry, i know, this gist is 6 years old, but i use this way too, is there a solution to migrate from mcrypt to openssl? mcrypt will be removed in php-7.2, so now i get with php-7.1 the deprecated messages. What i understand is, openssl does not support RIJNDAEL_256? So j have to reencrypt all files?

@ouily
Copy link

ouily commented Nov 6, 2018

Same problem :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment