用于加密/解密 php 对象或数组的首选 mcrypt 密码(如果有)是什么

发布于 2024-10-20 04:46:07 字数 587 浏览 2 评论 0原文

我会保持简短。作为 PHP mcrypt 库的一部分,有 40 种左右可能的密码,请参阅此处。

我自己对加密不太了解,我正在假设无论使用什么密码,解密时的数据与加密的数据相同(否则有什么意义?)

我需要加密然后解密数组或序列化标准对象。我浏览了 mcrypt 库基本实现的几个在线示例,并注意到每个示例都使用不同的密码。这让我想知道这是否有任何意义,或者只是个人喜好?

我的问题是,这些密码之间是否存在任何显着差异,我应该关心知道

  • 我将加密/解密是数组或序列化标准对象,并且包含相对较少的数据。
  • 此操作相当罕见,因此速度不是一个大问题,在 << 范围内的任何地方。 2秒是可以接受的。
  • 加密的字符串需要存储在 cookie 中并通过 url 查询字符串传输(因此长度和字符集有限制)

注意

我不会争论是否应该使用哈希或 hmac。加密是必要的,也是解决此问题的正确选择。

I'll keep this short and simple. As part of PHP's mcrypt library there are 40 or so possible ciphers, see here.

Not knowing much about encryption myself, I'm working under the assumption regardless of the cipher used, the data when decrypted is identical as the data encrypted (otherwise what's the point right?)

I need to encrypt and then decryption either an array or serialised standard object. I've browsed a couple examples online of the basic implementation of the mcrypt library and noticed that each example used a different cipher. It got me wondering if there was any significance to this, or simply personal preference?

My question is, is there any significant differences between these ciphers I should be concerned with knowing that

  • I'll be encrypting/decrypting is an either an array or serialised standard object, and contain relatively little data.
  • This operation will be fairly uncommon so speed isn't a massive issue, anywhere in the range on < 2s is acceptable.
  • The encrypted string will need to be stored in a cookie and transmitted via url query string (so there are limitations on length and character set)

Note

I'm not after a debate about whether I should be using a hash or hmac. Encryption is necessary and the correct option for this problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流年已逝 2024-10-27 04:46:07

任何合理的密码都会在给定正确密钥的情况下在明文/密文之间进行加密/解密。

您选择的密码存在巨大差异。无论是块长度、密钥长度和/或一般安全性。例如,您永远不应该使用 DES,因为它只使用 56 位密钥。您引用的列表中的其他密码与此类似。在使用任何密码之前,请务必仔细阅读并确定它是否适合您的环境。

但我无法详细介绍您列表中的每个密码。 :-)

我个人喜欢 AES (Rijndael),它采用三种大小的密钥:128、192 和 256 位。最著名的攻击比暴力攻击更快,但仍然不可行。它也很快(实际上英特尔在 Westmere 和 Sandy Bridge 中包含了 AES 的机器指令)。

Serpent 和 Twofish 也是很好的密码。几年前的 AES 竞赛中,Serpent 排名第二,仅次于 Rijndael,而 Twofish 排名第三(我认为是)。

Any reasonable cipher encrypts/decrypts between plaintext/ciphertext given the correct key.

There are huge differences to which cipher you choose. Be it block length, key length and/or general security. For instance, you should never use DES because it only uses a 56-bit key. Similar for other ciphers on the list you refer to. Before using any cipher always read up on it and determine whether it is a good cipher for your context.

But I can't go into detail about every cipher on your list here. :-)

I personally like AES (Rijndael) which takes three sizes of keys 128, 192 and 256 bits. The best known attack is faster than a brute-force attack but is still infeasible. It is fast, too (actually Intel included machine instructions for AES in Westmere and Sandy Bridge).

Serpent and Twofish are also good ciphers. Serpent came second to Rijndael and Twofish came third (I think it was) in the AES contest some years back.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文