Interface KeyExchangeEngine
- All Known Implementing Classes:
EcdhEngine, X25519Engine, X448Engine
public interface KeyExchangeEngine
Key exchange engine interface for various key agreement protocols
密钥协商引擎接口 - 支持各种密钥协商协议
Features | 主要功能:
- Key pair generation for key exchange - 密钥交换的密钥对生成
- Shared secret computation - 共享密钥计算
Usage Examples | 使用示例:
KeyExchangeEngine engine = X25519Engine.create();
KeyPair keyPair = engine.generateKeyPair();
byte[] shared = engine.computeSharedSecret(keyPair.getPrivate(), peerPublicKey);
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[]Computes the shared secret using the configured keys 使用配置的密钥计算共享密钥byte[]deriveKey(byte[] info, int length) Derives key material from the shared secret using HKDF 使用 HKDF 从共享密钥派生密钥材料Generates a new key pair for the key exchange 为密钥交换生成新的密钥对Gets the algorithm name of this key exchange engine 获取密钥交换引擎的算法名称setPrivateKey(PrivateKey privateKey) Sets the private key for this party 设置本方的私钥setRemotePublicKey(PublicKey publicKey) Sets the remote party's public key 设置对方的公钥
-
Method Details
-
generateKeyPair
KeyPair generateKeyPair()Generates a new key pair for the key exchange 为密钥交换生成新的密钥对- Returns:
- a new key pair
-
setPrivateKey
Sets the private key for this party 设置本方的私钥- Parameters:
privateKey- the private key to use- Returns:
- this engine for method chaining
- Throws:
NullPointerException- if privateKey is null
-
setRemotePublicKey
Sets the remote party's public key 设置对方的公钥- Parameters:
publicKey- the remote public key- Returns:
- this engine for method chaining
- Throws:
NullPointerException- if publicKey is null
-
deriveKey
byte[] deriveKey(byte[] info, int length) Derives key material from the shared secret using HKDF 使用 HKDF 从共享密钥派生密钥材料- Parameters:
info- optional context and application specific information (can be null)length- desired key length in bytes- Returns:
- derived key material
- Throws:
IllegalStateException- if required keys are not setIllegalArgumentException- if length is invalid
-
getAlgorithm
String getAlgorithm()Gets the algorithm name of this key exchange engine 获取密钥交换引擎的算法名称- Returns:
- the algorithm name
-