使用 openssl_encrypt 替换 Mcrypt 进行 3DES-ECB 加密

Use openssl_encrypt to replace Mcrypt for 3DES-ECB encryption(使用 openssl_encrypt 替换 Mcrypt 进行 3DES-ECB 加密)
本文介绍了使用 openssl_encrypt 替换 Mcrypt 进行 3DES-ECB 加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个使用 mycrypt 的加密方法,密码是 3des,模式 ecb:

mcrypt_module_open ( MCRYPT_3DES, '', 'ecb', '' )

现在想用openssl_encrypt加密,在openssl_get_cipher_methods()列表中没有找到des3-ecb.

解决方案

现在我想用openssl_encrypt加密它,在openssl_get_cipher_methods()列表中没有找到des3-ecb.

它是des-ede3.使用分组密码的对称加密需要某种操作模式.如果您查看列表,您会看到类似 des-ede3des-ede3-cbcdes-ede3-cfb 和 <代码>des-ede3-ofb.CBC、CFB 和 OFB 都已命名,而未命名密码必须是唯一的其他常见操作模式:ECB.

<小时>

切勿使用ECB模式.它是确定性的,因此在语义上不安全.你至少应该使用像 CBC 或 点击率.最好对您的密文进行身份验证,这样像填充预言机攻击这样的攻击是不可能的.这可以通过 GCM 或 EAX 等身份验证模式或 encrypt-then-MAC 方案来完成.>

现在不要使用三重 DES.即使您使用最大的 192 位密钥,它也最多只能提供 112 位的安全性.如果使用较短的密钥大小,则它仅提供 56 或 57 位的安全性.AES 会更快(处理器有一个特殊的 AES-NI 指令集),并且使用 128 位的最低密钥大小甚至更安全.3DES 的最大密文大小也有实际限制.请参阅3DES 和 AES 的安全性比较.

I have an encryption method with mycrypt and the cipher is 3des, mode ecb:

mcrypt_module_open ( MCRYPT_3DES, '', 'ecb', '' )

Now I want to encrypt it using openssl_encrypt, and I did not find des3-ecb in openssl_get_cipher_methods() list.

解决方案

now I want to encrypt it use openssl_encrypt, and I did not find des3-ecb in openssl_get_cipher_methods() list.

It's des-ede3. Symmetric encryption with a block cipher needs some kind of mode of operation. If you look through the list, you will see something like des-ede3, des-ede3-cbc, des-ede3-cfb and des-ede3-ofb. CBC, CFB and OFB are all named and the unnamed cipher must be the only other common mode of operation: ECB.


Never use ECB mode. It's deterministic and therefore not semantically secure. You should at the very least use a randomized mode like CBC or CTR. It is better to authenticate your ciphertexts so that attacks like a padding oracle attack are not possible. This can be done with authenticated modes like GCM or EAX, or with an encrypt-then-MAC scheme.

Don't use Triple DES nowadays. It only provides at best 112 bit of security even if you use the largest key size of 192 bit. If a shorter key size is used, then it only provides 56 or 57 bits of security. AES would be faster (processors have a special AES-NI instruction set) and even more secure with the lowest key size of 128 bit. There is also a practical limit on the maximum ciphertext size with 3DES. See Security comparison of 3DES and AES.

这篇关于使用 openssl_encrypt 替换 Mcrypt 进行 3DES-ECB 加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)