Class Scrypt
java.lang.Object
cloud.opencode.base.crypto.kdf.Scrypt
- All Implemented Interfaces:
KdfEngine
Scrypt key derivation function implementation - Memory-hard password-based KDF
Scrypt 密钥派生函数实现 - 内存困难的基于密码的 KDF
Features | 主要功能:
- SCrypt key derivation - SCrypt 密钥派生
- Memory-hard function - 内存密集型函数
Usage Examples | 使用示例:
Scrypt scrypt = Scrypt.create();
byte[] key = scrypt.deriveKey(password, salt, 32);
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
- 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 Scrypt configuration Scrypt 配置构建器 -
Method Summary
Modifier and TypeMethodDescriptionstatic Scrypt.Builderbuilder()Creates a builder for Scrypt configuration 创建 Scrypt 配置构建器byte[]derive(byte[] inputKeyMaterial, byte[] salt, byte[] info, int length) Derives a key from input key material with salt and info parameters 使用盐值和信息参数从输入密钥材料派生密钥byte[]derive(byte[] inputKeyMaterial, int length) Derives a key from input key material with default parameters 使用默认参数从输入密钥材料派生密钥byte[]deriveKey(char[] password, byte[] salt, int keyLength) Derives a key from a password and salt using Scrypt 使用 Scrypt 从密码和盐值派生密钥Returns the algorithm name of this KDF 返回此 KDF 的算法名称intgetN()Gets the CPU/memory cost parameter 获取 CPU/内存成本参数intgetP()Gets the parallelization parameter 获取并行化参数intgetR()Gets the block size parameter 获取块大小参数static Scryptof()Creates Scrypt instance with default parameters (N=32768, r=8, p=1) 创建使用默认参数的 Scrypt 实例(N=32768,r=8,p=1)static Scryptof(int n, int r, int p) Creates Scrypt instance with custom parameters 创建使用自定义参数的 Scrypt 实例
-
Method Details
-
of
Creates Scrypt instance with default parameters (N=32768, r=8, p=1) 创建使用默认参数的 Scrypt 实例(N=32768,r=8,p=1)- Returns:
- new Scrypt instance
-
of
Creates Scrypt instance with custom parameters 创建使用自定义参数的 Scrypt 实例- Parameters:
n- CPU/memory cost parameter (must be power of 2, greater than 1)r- block size parameter (must be positive)p- parallelization parameter (must be positive)- Returns:
- new Scrypt instance
- Throws:
IllegalArgumentException- if parameters are invalid
-
builder
Creates a builder for Scrypt configuration 创建 Scrypt 配置构建器- Returns:
- new Builder instance
-
deriveKey
public byte[] deriveKey(char[] password, byte[] salt, int keyLength) Derives a key from a password and salt using Scrypt 使用 Scrypt 从密码和盐值派生密钥- Parameters:
password- the password as char array (will not be modified)salt- the salt valuekeyLength- the desired key length in bytes- Returns:
- the derived key
- Throws:
NullPointerException- if password or salt is nullIllegalArgumentException- if keyLength is not positiveOpenCryptoException- if Bouncy Castle is not available or derivation fails
-
derive
public byte[] derive(byte[] inputKeyMaterial, byte[] salt, byte[] info, int length) Description copied from interface:KdfEngineDerives a key from input key material with salt and info parameters 使用盐值和信息参数从输入密钥材料派生密钥- Specified by:
derivein interfaceKdfEngine- Parameters:
inputKeyMaterial- the input key material (IKM)salt- the salt value (can be null or empty for some algorithms)info- the context and application specific information (can be null)length- the desired output key length in bytes- Returns:
- the derived key
-
derive
public byte[] derive(byte[] inputKeyMaterial, int length) Description copied from interface:KdfEngineDerives a key from input key material with default parameters 使用默认参数从输入密钥材料派生密钥 -
getAlgorithm
Description copied from interface:KdfEngineReturns the algorithm name of this KDF 返回此 KDF 的算法名称- Specified by:
getAlgorithmin interfaceKdfEngine- Returns:
- the algorithm name
-
getN
public int getN()Gets the CPU/memory cost parameter 获取 CPU/内存成本参数- Returns:
- the N parameter
-
getR
public int getR()Gets the block size parameter 获取块大小参数- Returns:
- the r parameter
-
getP
public int getP()Gets the parallelization parameter 获取并行化参数- Returns:
- the p parameter
-