Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

16
  • 8
    You can either user "MCRYPT_MODE_CBC" instead of "MCRYPT_MODE_ECB" to ensure more security. Commented Aug 17, 2013 at 5:00
  • 11
    Ramesh, this is because you're getting the raw encrypted data. You can get a nicer version of the encrypted data by using base64, like this: base64_encode(encrypt($string)) -- To decrypt it: decrypt(base64_decode($encrypted)) Commented Jul 31, 2014 at 0:19
  • 83
    WARNING: this is insecure. ECB mode should not be used for strings, ECB does not take an IV, this is not authenticated, it uses a old cipher (Blowfish) instead of AES, the key is not binary etc. etc. The SO community should really stop upvoting encryption / decryption that just "work" and start upvoting answers that are known to be secure. If you don't know that for sure, don't vote. Commented Feb 3, 2015 at 23:00
  • 3
    I kind of did this already by having the sample code of mcrypt_encrypt replaced: php.net/manual/en/function.mcrypt-encrypt.php. Note that reviewing it now it probably should have a rtrim for character "\0" at the end. Commented Feb 4, 2015 at 11:03
  • 5
    The correct answer is to use something like defuse/php-encryption instead of writing your own mcrypt code. Commented May 11, 2015 at 5:25