简体   繁体   English

代码行中发生了什么?

[英]What's happening in the line of code?

What's happening in this line of code ? 这行代码中发生了什么?

SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");

I specially don't understand getInstance("PBKDF2WithHmacSHA1") part 我特别不了解getInstance(“PBKDF2WithHmacSHA1”)部分

This funky looking string defines the secret-key algorithm to be used. 这个时髦的字符串定义了要使用的密钥算法。 It is: 它是:

PBKDF2WithHmacSHA1
PBKDF2 With Hmac SHA1
  • the PBKDF2 function (from PKCS#5 version 2.0) PBKDF2功能(来自PKCS#5版本2.0)
  • which will be using SHA-1 HMAC for its pseudo-random number generator 将使用SHA-1 HMAC作为其伪随机数发生器

References : 参考文献
We find similar algorithm names in Java Crypto Extension Guide Appending A , somehow PKCS5 version 2 may not have been available/documented then (or indeed as suggested by brianegge, may be a matter of export restriction, a common issue with cryptographic items). 我们在Java加密扩展指南附录A中找到类似的算法名称,不知何时PKCS5版本2可能尚未提供/记录(或者实际上由brianegge建议,可能是出口限制的问题,加密项目的常见问题)。
The algorithm name does show up in RFC3962 (AES for Kerberos) which may not be the very application you have in mind, but defined, all the same) 算法名称确实显示在RFC3962 (针对Kerberos的AES)中,这可能不是您想到的应用程序,但已定义,所有相同)

Different distributions of Java contain different crypto. Java的不同发行版包含不同的加密。 This is due to export restrictions and patents. 这是由于出口限制和专利。 The line of code is requesting a factory which can create that type of key. 代码行正在请求可以创建该类型密钥的工厂。

Specifically, PBKDF2WithHmacSHA1 constructs secret keys using the Password-Based Key Derivation Function function found in PKCS5 v2.0 . 具体来说, PBKDF2WithHmacSHA1使用PKCS5 v2.0中 的基于密码的密钥派生函数函数构造密钥。

"PBKDF2" is a function defined in PKCS #5 used to derive key material from a password. “PBKDF2”是PKCS#5中定义的函数,用于从密码中导出密钥材料。

PBKDF2 requires a pseudo-random function, and in this case, a message authentication code based on the SHA-1 hash is used—"HmacSHA1". PBKDF2需要伪随机函数,在这种情况下,使用基于SHA-1散列的消息验证代码 - “HmacSHA1”。

So, this line is creating a factory. 所以,这条线正在创建一个工厂。 The factory might produce SecretKey objects that can be used to key a Cipher instance for a symmetric encryption algorithm or a Mac algorithm. 工厂可能会生成SecretKey对象,可用于将Cipher实例键入对称加密算法或Mac算法。 Or, it can be used to make a "transparent" specification of an existing SecretKey . 或者,它可用于制作现有SecretKey的“透明”规范。

One important thing to note about PBKDF2 is that it doesn't produce secret keys for any particular algorithm. 关于PBKDF2的一个重要注意事项是它不会为任何特定算法生成密钥。 It's a deterministic way to generate key "material" from a seed (a password), in such a way that the seed cannot be recovered from the generated key. 这是从种子(密码)生成关键“材料”的确定性方法,其方式是无法从生成的密钥中恢复种子。 Once the required number of bytes are generated, they are usually wrapped in a SecretKeySpec with the correct algorithm name. 生成所需的字节数后,它们通常包含在具有正确算法名称的SecretKeySpec

You can see other standard names for secret key factories in the Java Crypto Architecture Standard Names documentation. 您可以在Java Crypto Architecture 标准名称文档中查看密钥工厂的其他标准名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM