Class SCryptHash
java.lang.Object
cloud.opencode.base.crypto.password.SCryptHash
- All Implemented Interfaces:
PasswordHash
SCrypt password hashing implementation - Memory-hard password hashing using scrypt algorithm (requires Bouncy Castle)
SCrypt 密码哈希实现 - 使用 scrypt 算法的内存困难密码哈希(需要 Bouncy Castle)
Features | 主要功能:
- SCrypt password hashing - SCrypt 密码哈希
- Memory-hard key derivation - 内存密集型密钥派生
Usage Examples | 使用示例:
SCryptHash scrypt = SCryptHash.of();
String hash = scrypt.hash("password");
boolean valid = scrypt.verify("password", hash);
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
Performance | 性能特性:
- Time complexity: O(N * r * p) - 时间复杂度: O(N * r * p),N/r/p为参数
- Space complexity: O(N * r) - 空间复杂度: O(N * r)
- 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 SCryptHash instances 用于创建自定义 SCryptHash 实例的构建器 -
Method Summary
Modifier and TypeMethodDescriptionstatic SCryptHash.Builderbuilder()Create a builder for custom SCrypt configuration 创建用于自定义 SCrypt 配置的构建器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 SCryptHashof()Create SCrypt hasher with default parameters 使用默认参数创建 SCrypt 哈希器static SCryptHashCreate SCrypt hasher with OWASP recommended parameters 使用 OWASP 推荐参数创建 SCrypt 哈希器booleanVerify a password against a hash using character array 使用字符数组验证密码与哈希值booleanVerify a password against a hash using string 使用字符串验证密码与哈希值
-
Method Details
-
of
Create SCrypt hasher with default parameters 使用默认参数创建 SCrypt 哈希器- Returns:
- new SCryptHash instance
- Throws:
OpenCryptoException- if Bouncy Castle is not available
-
owaspRecommended
Create SCrypt hasher with OWASP recommended parameters 使用 OWASP 推荐参数创建 SCrypt 哈希器- Returns:
- new SCryptHash instance
- Throws:
OpenCryptoException- if Bouncy Castle is not available
-
builder
Create a builder for custom SCrypt configuration 创建用于自定义 SCrypt 配置的构建器- Returns:
- new Builder instance
- Throws:
OpenCryptoException- if Bouncy Castle is not available
-
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
-