Class Blake3Hash
java.lang.Object
cloud.opencode.base.crypto.hash.Blake3Hash
- All Implemented Interfaces:
HashFunction
BLAKE3 hash function implementation - Next-generation cryptographic hash function
BLAKE3 哈希函数实现 - 下一代加密哈希函数
Requires Bouncy Castle provider to be available in the classpath. 需要 Bouncy Castle 提供者在类路径中可用。
Features | 主要功能:
- BLAKE3 hash algorithm - BLAKE3 哈希算法
- 256-bit digest output - 256 位摘要输出
- Requires Bouncy Castle provider - 需要 Bouncy Castle 提供者
Usage Examples | 使用示例:
Blake3Hash blake3 = Blake3Hash.create();
String hex = blake3.hashHex("data");
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
Performance | 性能特性:
- Time complexity: O(n) - 时间复杂度: O(n),n为数据长度
- Space complexity: O(1) - 空间复杂度: O(1)
- Since:
- JDK 25, opencode-base-crypto V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic Blake3Hashcreate()Create BLAKE3 hash function with default digest length (256-bit) 创建 BLAKE3 哈希函数(默认 256 位摘要)static Blake3Hashcreate(int digestLength) Create BLAKE3 hash function with custom digest length 创建指定摘要长度的 BLAKE3 哈希函数Get the hash algorithm name 获取哈希算法名称intGet the digest length in bytes 获取摘要长度(字节数)byte[]hash(byte[] data) Compute hash of byte array 计算字节数组的哈希值byte[]Compute hash of string (UTF-8 encoded) 计算字符串的哈希值(使用 UTF-8 编码)hashBase64(byte[] data) Compute hash and return as Base64 string 计算哈希值并返回 Base64 字符串hashHex(byte[] data) Compute hash and return as hexadecimal string 计算哈希值并返回十六进制字符串Compute hash of string and return as hexadecimal string 计算字符串哈希值并返回十六进制字符串
-
Method Details
-
create
Create BLAKE3 hash function with default digest length (256-bit) 创建 BLAKE3 哈希函数(默认 256 位摘要)- Returns:
- BLAKE3 hash function instance
- Throws:
OpenCryptoException- if Bouncy Castle provider is not available
-
create
Create BLAKE3 hash function with custom digest length 创建指定摘要长度的 BLAKE3 哈希函数BLAKE3 supports arbitrary output lengths. BLAKE3 支持任意输出长度。
- Parameters:
digestLength- digest length in bytes (must be positive)- Returns:
- BLAKE3 hash function instance
- Throws:
IllegalArgumentException- if digest length is not positiveOpenCryptoException- if Bouncy Castle provider is not available
-
hash
public byte[] hash(byte[] data) Description copied from interface:HashFunctionCompute hash of byte array 计算字节数组的哈希值- Specified by:
hashin interfaceHashFunction- Parameters:
data- input data to hash- Returns:
- hash digest as byte array
-
hash
Description copied from interface:HashFunctionCompute hash of string (UTF-8 encoded) 计算字符串的哈希值(使用 UTF-8 编码)- Specified by:
hashin interfaceHashFunction- Parameters:
data- input string to hash- Returns:
- hash digest as byte array
-
hashHex
Description copied from interface:HashFunctionCompute hash and return as hexadecimal string 计算哈希值并返回十六进制字符串- Specified by:
hashHexin interfaceHashFunction- Parameters:
data- input data to hash- Returns:
- hash digest as lowercase hex string
-
hashHex
Description copied from interface:HashFunctionCompute hash of string and return as hexadecimal string 计算字符串哈希值并返回十六进制字符串- Specified by:
hashHexin interfaceHashFunction- Parameters:
data- input string to hash- Returns:
- hash digest as lowercase hex string
-
hashBase64
Description copied from interface:HashFunctionCompute hash and return as Base64 string 计算哈希值并返回 Base64 字符串- Specified by:
hashBase64in interfaceHashFunction- Parameters:
data- input data to hash- Returns:
- hash digest as Base64 string
-
getDigestLength
public int getDigestLength()Description copied from interface:HashFunctionGet the digest length in bytes 获取摘要长度(字节数)- Specified by:
getDigestLengthin interfaceHashFunction- Returns:
- digest length in bytes
-
getAlgorithm
Description copied from interface:HashFunctionGet the hash algorithm name 获取哈希算法名称- Specified by:
getAlgorithmin interfaceHashFunction- Returns:
- algorithm name
-