Class KeyPairUtil
java.lang.Object
cloud.opencode.base.crypto.key.KeyPairUtil
Key pair utility class - Utility methods for working with asymmetric key pairs
密钥对工具类 - 用于处理非对称密钥对的实用方法
Features | 主要功能:
- Key pair serialization and deserialization - 密钥对序列化和反序列化
- PEM and DER format support - PEM 和 DER 格式支持
Usage Examples | 使用示例:
String pem = KeyPairUtil.toPem(keyPair);
KeyPair restored = KeyPairUtil.fromPem(pem, "RSA");
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
Performance | 性能特性:
- Time complexity: O(k^3) - 时间复杂度: O(k^3),k为密钥位数
- Space complexity: O(k) - 空间复杂度: O(k)
- Since:
- JDK 25, opencode-base-crypto V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic PublicKeyextractPublicKey(PrivateKey privateKey) Extract public key from private key (for RSA and EC keys) 从私钥中提取公钥(适用于 RSA 和 EC 密钥)static KeyPairGenerate key pair with specified algorithm and key size 使用指定的算法和密钥大小生成密钥对static KeyPairgenerateEc(CurveType curve) Generate elliptic curve key pair with specified curve 使用指定的曲线生成椭圆曲线密钥对static booleanisMatchingPair(PublicKey publicKey, PrivateKey privateKey) Check if public and private keys form a matching pair 检查公钥和私钥是否匹配
-
Method Details
-
generate
Generate key pair with specified algorithm and key size 使用指定的算法和密钥大小生成密钥对- Parameters:
algorithm- key algorithm (e.g., "RSA", "EC")keySize- key size in bits- Returns:
- generated key pair
- Throws:
OpenKeyException- if key generation fails
-
generateEc
Generate elliptic curve key pair with specified curve 使用指定的曲线生成椭圆曲线密钥对- Parameters:
curve- elliptic curve type- Returns:
- generated EC key pair
- Throws:
OpenKeyException- if key generation fails
-
extractPublicKey
Extract public key from private key (for RSA and EC keys) 从私钥中提取公钥(适用于 RSA 和 EC 密钥)- Parameters:
privateKey- private key- Returns:
- extracted public key
- Throws:
OpenKeyException- if extraction fails
-
isMatchingPair
Check if public and private keys form a matching pair 检查公钥和私钥是否匹配- Parameters:
publicKey- public keyprivateKey- private key- Returns:
- true if keys form a matching pair
- Throws:
OpenKeyException- if validation fails
-