Class Pbkdf2Hash
java.lang.Object
cloud.opencode.base.crypto.password.Pbkdf2Hash
- All Implemented Interfaces:
PasswordHash
PBKDF2 password hashing implementation - Password-Based Key Derivation Function 2 using JDK standard library
PBKDF2 密码哈希实现 - 使用 JDK 标准库的基于密码的密钥派生函数 2
Features | 主要功能:
- PBKDF2 with SHA-256/SHA-512 - PBKDF2(SHA-256/SHA-512)
- Configurable iteration count - 可配置迭代次数
Usage Examples | 使用示例:
Pbkdf2Hash pbkdf2 = Pbkdf2Hash.sha256();
String hash = pbkdf2.hash("password");
boolean valid = pbkdf2.verify("password", hash);
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
Performance | 性能特性:
- Time complexity: O(iterations) - 时间复杂度: O(iterations)(迭代次数)
- Space complexity: O(1) - 空间复杂度: O(1)
- Since:
- JDK 25, opencode-base-crypto V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating custom Pbkdf2Hash instances 用于创建自定义 Pbkdf2Hash 实例的构建器 -
Method Summary
Modifier and TypeMethodDescriptionstatic Pbkdf2Hash.Builderbuilder()Create a builder for custom PBKDF2 configuration 创建用于自定义 PBKDF2 配置的构建器Get the algorithm name for this password hash implementation 获取此密码哈希实现的算法名称hash(char[] password) Hash a password from a character array 从字符数组哈希密码Hash a password from a string 从字符串哈希密码booleanneedsRehash(String hash) Check if a hash needs to be rehashed with current parameters 检查哈希值是否需要使用当前参数重新哈希static Pbkdf2HashCreate PBKDF2 hasher with OWASP recommended parameters (SHA-256, 600k iterations) 使用 OWASP 推荐参数创建 PBKDF2 哈希器(SHA-256,60 万次迭代)static Pbkdf2Hashsha256()Create PBKDF2 hasher with SHA-256 and OWASP recommended parameters 使用 SHA-256 和 OWASP 推荐参数创建 PBKDF2 哈希器static Pbkdf2Hashsha512()Create PBKDF2 hasher with SHA-512 使用 SHA-512 创建 PBKDF2 哈希器booleanVerify a password against a hash using character array 使用字符数组验证密码与哈希值booleanVerify a password against a hash using string 使用字符串验证密码与哈希值
-
Method Details
-
sha256
Create PBKDF2 hasher with SHA-256 and OWASP recommended parameters 使用 SHA-256 和 OWASP 推荐参数创建 PBKDF2 哈希器- Returns:
- new Pbkdf2Hash instance
-
sha512
Create PBKDF2 hasher with SHA-512 使用 SHA-512 创建 PBKDF2 哈希器- Returns:
- new Pbkdf2Hash instance
-
owaspRecommended
Create PBKDF2 hasher with OWASP recommended parameters (SHA-256, 600k iterations) 使用 OWASP 推荐参数创建 PBKDF2 哈希器(SHA-256,60 万次迭代)- Returns:
- new Pbkdf2Hash instance
-
builder
Create a builder for custom PBKDF2 configuration 创建用于自定义 PBKDF2 配置的构建器- Returns:
- new Builder instance
-
hash
Description copied from interface:PasswordHashHash a password from a character array 从字符数组哈希密码- Specified by:
hashin interfacePasswordHash- Parameters:
password- the password to hash (will not be modified)- Returns:
- the hash string (self-describing format)
-
hash
Description copied from interface:PasswordHashHash a password from a string 从字符串哈希密码- Specified by:
hashin interfacePasswordHash- Parameters:
password- the password to hash- Returns:
- the hash string (self-describing format)
-
verify
Description copied from interface:PasswordHashVerify a password against a hash using character array 使用字符数组验证密码与哈希值- Specified by:
verifyin interfacePasswordHash- Parameters:
password- the password to verify (will not be modified)hash- the hash to verify against- Returns:
- true if password matches the hash, false otherwise
-
verify
Description copied from interface:PasswordHashVerify a password against a hash using string 使用字符串验证密码与哈希值- Specified by:
verifyin interfacePasswordHash- Parameters:
password- the password to verifyhash- the hash to verify against- Returns:
- true if password matches the hash, false otherwise
-
needsRehash
Description copied from interface:PasswordHashCheck if a hash needs to be rehashed with current parameters 检查哈希值是否需要使用当前参数重新哈希Returns true if the hash was created with different parameters than the current instance, indicating the password should be rehashed on next successful authentication.
- Specified by:
needsRehashin interfacePasswordHash- Parameters:
hash- the hash to check- Returns:
- true if rehashing is needed, false otherwise
-
getAlgorithm
Description copied from interface:PasswordHashGet the algorithm name for this password hash implementation 获取此密码哈希实现的算法名称- Specified by:
getAlgorithmin interfacePasswordHash- Returns:
- algorithm name
-