PBEKeySpec iterationCount 和 keyLength 参数有何影响?

发布于 2024-11-09 09:00:29 字数 232 浏览 0 评论 0原文

深入研究 Java 加密和哈希世界,我看到了 PBEKeySpec 类的构造函数示例,其中包含各种迭代计数和 keyLength 参数值。似乎没有什么可以解释这些参数的影响或含义。

我假设 keyLength 是密钥的长度,因此 32 位加密将采用 32 作为密钥长度,但这种假设感觉是错误的。我对 iterationCount 的猜测是每个字符被加密的次数,同样也没有感受到对这个假设的喜爱。

感谢信息或解释的链接。

Delving into the java encryption and hashing world I see examples of the constructor for the PBEKeySpec class with various values for the iterationCount and the keyLength parameters. Nothing seems to explain what these parameters impact or mean.

I am assuming that keyLength is how long the key is so 32 bit encryption would take a value of 32 for the key length, but that assumption feels wrong. My guess for the iterationCount is the number of times each char is encrypted, again not feeling the love on that assumption either.

Links to info or an explanation are appreciated.

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

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

发布评论

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

评论(1

偏爱你一生 2024-11-16 09:00:29

迭代计数是在派生对称密钥期间对密码进行哈希处理的次数。数字越大,验证密码猜测并得出正确密钥的难度就越大。它与盐一起使用,盐用于防止使用彩虹表的攻击。迭代计数应该尽可能高,而不会使您自己的系统速度减慢太多。迭代计数的更通用术语是“工作因子”。

密钥长度是派生对称密钥的长度以位为单位。 DESede 密钥的长度可以是 128 或 192 位,包括奇偶校验位。 AES 密钥的长度可以是 128、192 或 256 位。问题是 API 没有指定密钥长度(位/字节,带或不带奇偶校验);对于 PBEKeySpec ,密钥大小为位,包括本节中所示的奇偶校验位。

密钥派生函数通常只输出“足够”的随机位,因此您仍然可以指定所需的密钥大小。


注意:

  • 欲了解更多信息,请查看标准,PKCS标准往往是相对容易阅读。
  • 盐只需要是唯一的;通常,这是通过使用安全随机数生成器创建 64 到 256 位完全随机盐来实现的(对于 Java 来说,这意味着使用 new SecureRandom() ,然后使用 nextBytes(int amount)代码>)。盐可以是公开的并与密文或密码哈希一起存储。
  • 为密钥大小指定任何大于哈希输出大小(默认情况下为 SHA-1,160 位输出大小)的值可能会失败(对于 PBKDF1)或导致额外的速度减慢(对于 PBKDF2)。不推荐;只需使用算法规范中的 SHA-256、SHA-512 等哈希函数即可。
  • SHA-1(有时简称 SHA,因为从未使用过 SHA-0)和甚至 MD5 对于此类功能仍然是完全安全的(因为它不依赖于碰撞抵抗),但您仍然应该为新协议选择更安全的选项,例如 SHA-256 或 SHA-512。

The iteration count is the number of times that the password is hashed during the derivation of the symmetric key. The higher number, the more difficult it is to validate a password guess and then derive the correct key. It is used together with the salt which is used to prevent against attacks using rainbow tables. The iteration count should be as high as possible, without slowing your own system down too much. A more generic term for iteration count is work factor.

The key length is the length in bits of the derived symmetric key. A DESede key can be either 128 or 192 bits long, including parity bits. An AES key can be 128, 192 or 256 bits long. The problem is that it is not specified by the API which key length (bits / bytes, with- or without parity) is meant; for PBEKeySpec the key size is bits, including the parity bits as shown in this section.

The key derivation function normally just outputs "enough" random bits, so that's why you can still specify the required key size.


Notes:

  • For more info, please have a look at the standard, PKCS standards tend to be relatively easy to read.
  • The salt just needs to be unique; generally this is achieved by creating a 64 to 256 bit fully random salt using a secure random number generator (which, for Java means using new SecureRandom() and then nextBytes(int amount)). The salt can be public and stored with the ciphertext or password hash.
  • Specifying any value larger than the output size of the hash (by default this is SHA-1, 160 bits output size) for the key size may fail (for PBKDF1) or result in an additional slowdown (for PBKDF2). Not recommended; just use a hash function such as SHA-256, SHA-512 in the algorithm specification.
  • SHA-1 (sometimes just called SHA as SHA-0 was never used) and even MD5 are still completely secure for this kind of function (as it doesn't rely on collision resistance) but you should still go for a more secure option such as SHA-256 or SHA-512 for new protocols.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文