我想这是专业人士的问题。缺点
对于简单的数据加密:
使用openssl_encrypt
而不是mcrypt_encrypt
有什么好处?
答案 0 :(得分:15)
不要使用mcrypt 。如果您在代码中输入单词mcrypt,那么您可能犯了错误。虽然可以提供构建在mcrypt之上的相对安全的加密库(defuse / php-encryption的早期版本),但是将代码切换到openssl将提供更好的安全性,性能,可维护性和可移植性。 source: paragonie.com
速度 openssl更快。请查看下表source: jrm.cc
# php examples/compare.php
Results:
+---------+--------+----------+-------------+--------------+
| ext | keylen | textsize | (en/de)code | ops/sec |
+---------+--------+----------+-------------+--------------+
| mcrypt | 128 | short | enc | 5626.38872 |
| mcrypt | 128 | short | dec | 5729.21909 |
| mcrypt | 192 | short | enc | 5694.37256 |
| mcrypt | 192 | short | dec | 5682.78434 |
| mcrypt | 256 | short | enc | 5644.36358 |
| mcrypt | 256 | short | dec | 5661.23080 |
| mcrypt | 128 | medium | enc | 5583.97725 |
| mcrypt | 128 | medium | dec | 5650.75122 |
| mcrypt | 192 | medium | enc | 5591.54051 |
| mcrypt | 192 | medium | dec | 5552.83950 |
| mcrypt | 256 | medium | enc | 5524.18533 |
| mcrypt | 256 | medium | dec | 5513.65563 |
| mcrypt | 128 | long | enc | 4773.67544 |
| mcrypt | 128 | long | dec | 4774.14273 |
| mcrypt | 192 | long | enc | 4633.75035 |
| mcrypt | 192 | long | dec | 4634.35450 |
| mcrypt | 256 | long | enc | 4494.90529 |
| mcrypt | 256 | long | dec | 4280.92422 |
| openssl | 128 | short | enc | 168581.35048 |
| openssl | 128 | short | dec | 170417.03234 |
| openssl | 192 | short | enc | 172052.83452 |
| openssl | 192 | short | dec | 171349.94689 |
| openssl | 256 | short | enc | 171112.27154 |
| openssl | 256 | short | dec | 171644.45899 |
| openssl | 128 | medium | enc | 166944.11718 |
| openssl | 128 | medium | dec | 169084.25381 |
| openssl | 192 | medium | enc | 166665.50107 |
| openssl | 192 | medium | dec | 168459.47466 |
| openssl | 256 | medium | enc | 163878.40900 |
| openssl | 256 | medium | dec | 167946.82470 |
| openssl | 128 | long | enc | 110370.61207 |
| openssl | 128 | long | dec | 142731.36868 |
| openssl | 192 | long | enc | 103798.85171 |
| openssl | 192 | long | dec | 135396.21667 |
| openssl | 256 | long | enc | 96767.81100 |
| openssl | 256 | long | dec | 132203.99672 |
+---------+--------+----------+-------------+--------------+
Abandonware mcrypt基本上是放弃软件。因此,特别是如果您从头开始(或作为php.net comment states 在2015年编写代码),请正确行事。使用OpenSSL。 source: stackoverflow Artjom B.