PBEKeySpec iterationCount 和 keyLength 参数有何影响?
深入研究 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
迭代计数是在派生对称密钥期间对密码进行哈希处理的次数。数字越大,验证密码猜测并得出正确密钥的难度就越大。它与盐一起使用,盐用于防止使用彩虹表的攻击。迭代计数应该尽可能高,而不会使您自己的系统速度减慢太多。迭代计数的更通用术语是“工作因子”。
密钥长度是派生对称密钥的长度以位为单位。 DESede 密钥的长度可以是 128 或 192 位,包括奇偶校验位。 AES 密钥的长度可以是 128、192 或 256 位。问题是 API 没有指定密钥长度(位/字节,带或不带奇偶校验);对于
PBEKeySpec
,密钥大小为位,包括本节中所示的奇偶校验位。密钥派生函数通常只输出“足够”的随机位,因此您仍然可以指定所需的密钥大小。
注意:
new SecureRandom()
,然后使用nextBytes(int amount)
代码>)。盐可以是公开的并与密文或密码哈希一起存储。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:
new SecureRandom()
and thennextBytes(int amount)
). The salt can be public and stored with the ciphertext or password hash.