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 TypeMethodDescriptionbyte[]doSign()Complete the multi-part signing operation 完成多部分签名操作Complete the multi-part signing and return Base64 signature 完成多部分签名并返回 Base64 签名booleandoVerify(byte[] signature) Complete the multi-part verification operation 完成多部分验证操作Get the signature algorithm name 获取签名算法名称setKeyPair(KeyPair keyPair) Set both keys from a key pair 从密钥对设置公私钥setPrivateKey(byte[] encodedKey) Set the private key from encoded bytes 从编码字节设置私钥setPrivateKey(PrivateKey privateKey) Set the private key for signing operations 设置用于签名操作的私钥setPrivateKeyPem(String pem) Set the private key from PEM format 从 PEM 格式设置私钥setPublicKey(byte[] encodedKey) Set the public key from encoded bytes 从编码字节设置公钥setPublicKey(PublicKey publicKey) Set the public key for verification operations 设置用于验证操作的公钥setPublicKeyPem(String pem) Set the public key from PEM format 从 PEM 格式设置公钥byte[]sign(byte[] data) Sign data and return signature bytes 签名数据并返回签名字节byte[]sign(InputStream input) Sign data from input stream 从输入流签名数据byte[]Sign UTF-8 encoded string data 签名 UTF-8 编码的字符串数据signBase64(byte[] data) Sign data and return Base64 encoded signature 签名数据并返回 Base64 编码的签名signBase64(String data) Sign UTF-8 encoded string and return Base64 signature 签名 UTF-8 编码字符串并返回 Base64 签名byte[]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 the signature with UTF-8 encoded string 使用 UTF-8 编码字符串更新签名booleanverify(byte[] data, byte[] signature) Verify signature for given data 验证给定数据的签名booleanVerify signature for UTF-8 encoded string 验证 UTF-8 编码字符串的签名booleanverifyBase64(byte[] data, String base64Signature) Verify Base64 encoded signature 验证 Base64 编码的签名booleanverifyBase64(String data, String base64Signature) Verify Base64 encoded signature for string data 验证字符串数据的 Base64 编码签名booleanverifyFile(Path file, byte[] signature) Verify signature for file content 验证文件内容的签名booleanVerify hexadecimal encoded signature 验证十六进制编码的签名
-
Method Details
-
setPrivateKey
Set the private key for signing operations 设置用于签名操作的私钥- Parameters:
privateKey- the private key- Returns:
- this engine instance for method chaining
-
setPrivateKey
Set the private key from encoded bytes 从编码字节设置私钥- Parameters:
encodedKey- encoded private key bytes- Returns:
- this engine instance for method chaining
-
setPrivateKeyPem
Set the private key from PEM format 从 PEM 格式设置私钥- Parameters:
pem- PEM formatted private key- Returns:
- this engine instance for method chaining
-
setPublicKey
Set the public key for verification operations 设置用于验证操作的公钥- Parameters:
publicKey- the public key- Returns:
- this engine instance for method chaining
-
setPublicKey
Set the public key from encoded bytes 从编码字节设置公钥- Parameters:
encodedKey- encoded public key bytes- Returns:
- this engine instance for method chaining
-
setPublicKeyPem
Set the public key from PEM format 从 PEM 格式设置公钥- Parameters:
pem- PEM formatted public key- Returns:
- this engine instance for method chaining
-
setKeyPair
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
Sign UTF-8 encoded string data 签名 UTF-8 编码的字符串数据- Parameters:
data- string data to sign- Returns:
- signature bytes
-
signBase64
Sign data and return Base64 encoded signature 签名数据并返回 Base64 编码的签名- Parameters:
data- data to sign- Returns:
- Base64 encoded signature
-
signBase64
-
signHex
Sign data and return hexadecimal encoded signature 签名数据并返回十六进制编码的签名- Parameters:
data- data to sign- Returns:
- hexadecimal encoded signature
-
signFile
Sign file content 签名文件内容- Parameters:
file- file to sign- Returns:
- signature bytes
-
sign
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 signedsignature- signature bytes- Returns:
- true if signature is valid
-
verify
Verify signature for UTF-8 encoded string 验证 UTF-8 编码字符串的签名- Parameters:
data- string data that was signedsignature- signature bytes- Returns:
- true if signature is valid
-
verifyBase64
Verify Base64 encoded signature 验证 Base64 编码的签名- Parameters:
data- data that was signedbase64Signature- Base64 encoded signature- Returns:
- true if signature is valid
-
verifyBase64
-
verifyHex
Verify hexadecimal encoded signature 验证十六进制编码的签名- Parameters:
data- data that was signedhexSignature- hexadecimal encoded signature- Returns:
- true if signature is valid
-
verifyFile
Verify signature for file content 验证文件内容的签名- Parameters:
file- file that was signedsignature- signature bytes- Returns:
- true if signature is valid
-
update
Update the signature with additional data (for multi-part signing) 使用额外数据更新签名(用于多部分签名)- Parameters:
data- data to add- Returns:
- this engine instance for method chaining
-
update
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
-