Interface SignatureEngine

All Known Implementing Classes:
EcdsaSignature, EddsaSignature, RsaPssSignature, RsaSignature, Sm2Signature

public interface SignatureEngine
Digital signature engine interface - Unified API for signature generation and verification 数字签名引擎接口 - 统一的签名生成和验证 API

Features | 主要功能:

  • Digital signature generation and verification - 数字签名生成和验证
  • Key pair management - 密钥对管理

Usage Examples | 使用示例:

SignatureEngine engine = EddsaSignature.ed25519();
engine.setPrivateKey(privateKey);
byte[] sig = engine.sign(data);

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: Partial - 空值安全: 部分
Since:
JDK 25, opencode-base-crypto V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Complete the multi-part signing operation 完成多部分签名操作
    Complete the multi-part signing and return Base64 signature 完成多部分签名并返回 Base64 签名
    boolean
    doVerify(byte[] signature)
    Complete the multi-part verification operation 完成多部分验证操作
    Get the signature algorithm name 获取签名算法名称
    Set both keys from a key pair 从密钥对设置公私钥
    setPrivateKey(byte[] encodedKey)
    Set the private key from encoded bytes 从编码字节设置私钥
    Set the private key for signing operations 设置用于签名操作的私钥
    Set the private key from PEM format 从 PEM 格式设置私钥
    setPublicKey(byte[] encodedKey)
    Set the public key from encoded bytes 从编码字节设置公钥
    Set the public key for verification operations 设置用于验证操作的公钥
    Set the public key from PEM format 从 PEM 格式设置公钥
    byte[]
    sign(byte[] data)
    Sign data and return signature bytes 签名数据并返回签名字节
    byte[]
    Sign data from input stream 从输入流签名数据
    byte[]
    sign(String data)
    Sign UTF-8 encoded string data 签名 UTF-8 编码的字符串数据
    signBase64(byte[] data)
    Sign data and return Base64 encoded signature 签名数据并返回 Base64 编码的签名
    Sign UTF-8 encoded string and return Base64 signature 签名 UTF-8 编码字符串并返回 Base64 签名
    byte[]
    signFile(Path file)
    Sign file content 签名文件内容
    signHex(byte[] data)
    Sign data and return hexadecimal encoded signature 签名数据并返回十六进制编码的签名
    update(byte[] data)
    Update the signature with additional data (for multi-part signing) 使用额外数据更新签名(用于多部分签名)
    update(String data)
    Update the signature with UTF-8 encoded string 使用 UTF-8 编码字符串更新签名
    boolean
    verify(byte[] data, byte[] signature)
    Verify signature for given data 验证给定数据的签名
    boolean
    verify(String data, byte[] signature)
    Verify signature for UTF-8 encoded string 验证 UTF-8 编码字符串的签名
    boolean
    verifyBase64(byte[] data, String base64Signature)
    Verify Base64 encoded signature 验证 Base64 编码的签名
    boolean
    verifyBase64(String data, String base64Signature)
    Verify Base64 encoded signature for string data 验证字符串数据的 Base64 编码签名
    boolean
    verifyFile(Path file, byte[] signature)
    Verify signature for file content 验证文件内容的签名
    boolean
    verifyHex(byte[] data, String hexSignature)
    Verify hexadecimal encoded signature 验证十六进制编码的签名
  • Method Details

    • setPrivateKey

      SignatureEngine setPrivateKey(PrivateKey privateKey)
      Set the private key for signing operations 设置用于签名操作的私钥
      Parameters:
      privateKey - the private key
      Returns:
      this engine instance for method chaining
    • setPrivateKey

      SignatureEngine setPrivateKey(byte[] encodedKey)
      Set the private key from encoded bytes 从编码字节设置私钥
      Parameters:
      encodedKey - encoded private key bytes
      Returns:
      this engine instance for method chaining
    • setPrivateKeyPem

      SignatureEngine setPrivateKeyPem(String pem)
      Set the private key from PEM format 从 PEM 格式设置私钥
      Parameters:
      pem - PEM formatted private key
      Returns:
      this engine instance for method chaining
    • setPublicKey

      SignatureEngine setPublicKey(PublicKey publicKey)
      Set the public key for verification operations 设置用于验证操作的公钥
      Parameters:
      publicKey - the public key
      Returns:
      this engine instance for method chaining
    • setPublicKey

      SignatureEngine setPublicKey(byte[] encodedKey)
      Set the public key from encoded bytes 从编码字节设置公钥
      Parameters:
      encodedKey - encoded public key bytes
      Returns:
      this engine instance for method chaining
    • setPublicKeyPem

      SignatureEngine setPublicKeyPem(String pem)
      Set the public key from PEM format 从 PEM 格式设置公钥
      Parameters:
      pem - PEM formatted public key
      Returns:
      this engine instance for method chaining
    • setKeyPair

      SignatureEngine setKeyPair(KeyPair keyPair)
      Set both keys from a key pair 从密钥对设置公私钥
      Parameters:
      keyPair - the key pair
      Returns:
      this engine instance for method chaining
    • sign

      byte[] sign(byte[] data)
      Sign data and return signature bytes 签名数据并返回签名字节
      Parameters:
      data - data to sign
      Returns:
      signature bytes
    • sign

      byte[] sign(String data)
      Sign UTF-8 encoded string data 签名 UTF-8 编码的字符串数据
      Parameters:
      data - string data to sign
      Returns:
      signature bytes
    • signBase64

      String signBase64(byte[] data)
      Sign data and return Base64 encoded signature 签名数据并返回 Base64 编码的签名
      Parameters:
      data - data to sign
      Returns:
      Base64 encoded signature
    • signBase64

      String signBase64(String data)
      Sign UTF-8 encoded string and return Base64 signature 签名 UTF-8 编码字符串并返回 Base64 签名
      Parameters:
      data - string data to sign
      Returns:
      Base64 encoded signature
    • signHex

      String signHex(byte[] data)
      Sign data and return hexadecimal encoded signature 签名数据并返回十六进制编码的签名
      Parameters:
      data - data to sign
      Returns:
      hexadecimal encoded signature
    • signFile

      byte[] signFile(Path file)
      Sign file content 签名文件内容
      Parameters:
      file - file to sign
      Returns:
      signature bytes
    • sign

      byte[] sign(InputStream input)
      Sign data from input stream 从输入流签名数据
      Parameters:
      input - input stream to read data from
      Returns:
      signature bytes
    • verify

      boolean verify(byte[] data, byte[] signature)
      Verify signature for given data 验证给定数据的签名
      Parameters:
      data - data that was signed
      signature - signature bytes
      Returns:
      true if signature is valid
    • verify

      boolean verify(String data, byte[] signature)
      Verify signature for UTF-8 encoded string 验证 UTF-8 编码字符串的签名
      Parameters:
      data - string data that was signed
      signature - signature bytes
      Returns:
      true if signature is valid
    • verifyBase64

      boolean verifyBase64(byte[] data, String base64Signature)
      Verify Base64 encoded signature 验证 Base64 编码的签名
      Parameters:
      data - data that was signed
      base64Signature - Base64 encoded signature
      Returns:
      true if signature is valid
    • verifyBase64

      boolean verifyBase64(String data, String base64Signature)
      Verify Base64 encoded signature for string data 验证字符串数据的 Base64 编码签名
      Parameters:
      data - string data that was signed
      base64Signature - Base64 encoded signature
      Returns:
      true if signature is valid
    • verifyHex

      boolean verifyHex(byte[] data, String hexSignature)
      Verify hexadecimal encoded signature 验证十六进制编码的签名
      Parameters:
      data - data that was signed
      hexSignature - hexadecimal encoded signature
      Returns:
      true if signature is valid
    • verifyFile

      boolean verifyFile(Path file, byte[] signature)
      Verify signature for file content 验证文件内容的签名
      Parameters:
      file - file that was signed
      signature - signature bytes
      Returns:
      true if signature is valid
    • update

      SignatureEngine update(byte[] data)
      Update the signature with additional data (for multi-part signing) 使用额外数据更新签名(用于多部分签名)
      Parameters:
      data - data to add
      Returns:
      this engine instance for method chaining
    • update

      SignatureEngine update(String data)
      Update the signature with UTF-8 encoded string 使用 UTF-8 编码字符串更新签名
      Parameters:
      data - string data to add
      Returns:
      this engine instance for method chaining
    • doSign

      byte[] doSign()
      Complete the multi-part signing operation 完成多部分签名操作
      Returns:
      signature bytes
    • doSignBase64

      String doSignBase64()
      Complete the multi-part signing and return Base64 signature 完成多部分签名并返回 Base64 签名
      Returns:
      Base64 encoded signature
    • doVerify

      boolean doVerify(byte[] signature)
      Complete the multi-part verification operation 完成多部分验证操作
      Parameters:
      signature - signature to verify
      Returns:
      true if signature is valid
    • getAlgorithm

      String getAlgorithm()
      Get the signature algorithm name 获取签名算法名称
      Returns:
      algorithm name