Class Blake2Hash

java.lang.Object
cloud.opencode.base.crypto.hash.Blake2Hash
All Implemented Interfaces:
HashFunction

public final class Blake2Hash extends Object implements HashFunction
BLAKE2 hash function implementation - High-speed cryptographic hash function (BLAKE2b, BLAKE2s) BLAKE2 哈希函数实现 - 高速加密哈希函数(BLAKE2b、BLAKE2s)

Requires Bouncy Castle provider to be available in the classpath. 需要 Bouncy Castle 提供者在类路径中可用。

Features | 主要功能:

  • BLAKE2b and BLAKE2s algorithms - BLAKE2b 和 BLAKE2s 算法
  • Configurable digest length - 可配置的摘要长度
  • Requires Bouncy Castle provider - 需要 Bouncy Castle 提供者

Usage Examples | 使用示例:

Blake2Hash blake2 = Blake2Hash.blake2b256();
String hex = blake2.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 Type
    Method
    Description
    static Blake2Hash
    blake2b(int digestLength)
    Create BLAKE2b hash function with custom digest length 创建指定摘要长度的 BLAKE2b 哈希函数
    static Blake2Hash
    Create BLAKE2b-256 hash function (256-bit digest) 创建 BLAKE2b-256 哈希函数(256 位摘要)
    static Blake2Hash
    Create BLAKE2b-512 hash function (512-bit digest) 创建 BLAKE2b-512 哈希函数(512 位摘要)
    static Blake2Hash
    blake2s(int digestLength)
    Create BLAKE2s hash function with custom digest length 创建指定摘要长度的 BLAKE2s 哈希函数
    static Blake2Hash
    Create BLAKE2s-256 hash function (256-bit digest) 创建 BLAKE2s-256 哈希函数(256 位摘要)
    Get the hash algorithm name 获取哈希算法名称
    int
    Get the digest length in bytes 获取摘要长度(字节数)
    byte[]
    hash(byte[] data)
    Compute hash of byte array 计算字节数组的哈希值
    byte[]
    hash(String data)
    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 计算字符串哈希值并返回十六进制字符串

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • blake2b

      public static Blake2Hash blake2b(int digestLength)
      Create BLAKE2b hash function with custom digest length 创建指定摘要长度的 BLAKE2b 哈希函数
      Parameters:
      digestLength - digest length in bytes (1-64)
      Returns:
      BLAKE2b hash function instance
      Throws:
      IllegalArgumentException - if digest length is invalid
      OpenCryptoException - if Bouncy Castle provider is not available
    • blake2b256

      public static Blake2Hash blake2b256()
      Create BLAKE2b-256 hash function (256-bit digest) 创建 BLAKE2b-256 哈希函数(256 位摘要)
      Returns:
      BLAKE2b-256 hash function instance
      Throws:
      OpenCryptoException - if Bouncy Castle provider is not available
    • blake2b512

      public static Blake2Hash blake2b512()
      Create BLAKE2b-512 hash function (512-bit digest) 创建 BLAKE2b-512 哈希函数(512 位摘要)
      Returns:
      BLAKE2b-512 hash function instance
      Throws:
      OpenCryptoException - if Bouncy Castle provider is not available
    • blake2s

      public static Blake2Hash blake2s(int digestLength)
      Create BLAKE2s hash function with custom digest length 创建指定摘要长度的 BLAKE2s 哈希函数
      Parameters:
      digestLength - digest length in bytes (1-32)
      Returns:
      BLAKE2s hash function instance
      Throws:
      IllegalArgumentException - if digest length is invalid
      OpenCryptoException - if Bouncy Castle provider is not available
    • blake2s256

      public static Blake2Hash blake2s256()
      Create BLAKE2s-256 hash function (256-bit digest) 创建 BLAKE2s-256 哈希函数(256 位摘要)
      Returns:
      BLAKE2s-256 hash function instance
      Throws:
      OpenCryptoException - if Bouncy Castle provider is not available
    • hash

      public byte[] hash(byte[] data)
      Description copied from interface: HashFunction
      Compute hash of byte array 计算字节数组的哈希值
      Specified by:
      hash in interface HashFunction
      Parameters:
      data - input data to hash
      Returns:
      hash digest as byte array
    • hash

      public byte[] hash(String data)
      Description copied from interface: HashFunction
      Compute hash of string (UTF-8 encoded) 计算字符串的哈希值(使用 UTF-8 编码)
      Specified by:
      hash in interface HashFunction
      Parameters:
      data - input string to hash
      Returns:
      hash digest as byte array
    • hashHex

      public String hashHex(byte[] data)
      Description copied from interface: HashFunction
      Compute hash and return as hexadecimal string 计算哈希值并返回十六进制字符串
      Specified by:
      hashHex in interface HashFunction
      Parameters:
      data - input data to hash
      Returns:
      hash digest as lowercase hex string
    • hashHex

      public String hashHex(String data)
      Description copied from interface: HashFunction
      Compute hash of string and return as hexadecimal string 计算字符串哈希值并返回十六进制字符串
      Specified by:
      hashHex in interface HashFunction
      Parameters:
      data - input string to hash
      Returns:
      hash digest as lowercase hex string
    • hashBase64

      public String hashBase64(byte[] data)
      Description copied from interface: HashFunction
      Compute hash and return as Base64 string 计算哈希值并返回 Base64 字符串
      Specified by:
      hashBase64 in interface HashFunction
      Parameters:
      data - input data to hash
      Returns:
      hash digest as Base64 string
    • getDigestLength

      public int getDigestLength()
      Description copied from interface: HashFunction
      Get the digest length in bytes 获取摘要长度(字节数)
      Specified by:
      getDigestLength in interface HashFunction
      Returns:
      digest length in bytes
    • getAlgorithm

      public String getAlgorithm()
      Description copied from interface: HashFunction
      Get the hash algorithm name 获取哈希算法名称
      Specified by:
      getAlgorithm in interface HashFunction
      Returns:
      algorithm name