Search code examples
phpdrupalencryptionmcrypt

Alternatives to Mcrypt for encryption / decryption in PHP?


I'm giving some code for a Drupal module that needs to do encryption and decryption. I dont think I can assume that the Mcrypt module is installed on the Drupal system. What can i use as an alternative encryption mechanism?

This isnt for financial stuff, so i dont need sophisticated cryptology, but better is beter...


Solution

  • How about using your database? MySQL has AES and DES encryption and decryption functions. You could then use a "fake" query to get your string:

    select id, aes_encrypt('My secret text', 'the key string') 
    from permissions 
    limit 1
    

    (MySQL returns an empty set if you don't have at least one field from the table.)

    Decryption works the same way. It's 128-bit AES, which is not too bad, cryptographically, and if you can't even be sure about MCrypt, I doubt you will be recompiling MySQL to get 256-bit AES.