开发者

Alternatives to Mcrypt for encryption / decryption in PHP?

开发者 https://www.devze.com 2023-02-27 05:45 出处:网络
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 alternati

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 b开发者_JAVA百科etter is beter...


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.


There are several methods of encrypting PHP codes, using a key to encrypt/decrypt codes makes it more secure as an alternate to MCrypt.

One way is creating a function that may require a key to complete an encryption or decryption. PHP has its built-in functions like gzdeflate() or gzinflate(), another is using base64_encode()/base64_decode() and str_rot13() functions.

But I don't think using PHP Encoder would work.


The Encryption module module includes a basic encryption method by default, which it describes as "A simple mathematical encryption method that does not require any PHP extensions."


based on Leon's answer, PHP Encoder is using MCrypt module that may not work on Drupal. Another way is is to use IonCube Encoder.

If you want a more strict function, you may also try to use hash() and md5() function to create your key and require it on you encrypting function with the returns of gzdeflate()/gzinflate() functions as what Leon's suggestion.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号