Record Class PgpKeyPair
java.lang.Object
java.lang.Record
cloud.opencode.base.crypto.pgp.PgpKeyPair
- Record Components:
publicKey- the PGP public key / PGP 公钥secretKey- the PGP secret key / PGP 私钥userId- the user ID associated with the key / 与密钥关联的用户 IDkeyId- the key ID / 密钥 ID
public record PgpKeyPair(org.bouncycastle.openpgp.PGPPublicKey publicKey, org.bouncycastle.openpgp.PGPSecretKey secretKey, String userId, long keyId)
extends Record
PGP Key Pair - Holds PGP public and secret key pair
PGP 密钥对 - 保存 PGP 公钥和私钥对
This record encapsulates a PGP key pair including the public key for encryption and the secret key for decryption/signing operations.
此记录封装了 PGP 密钥对,包括用于加密的公钥和用于解密/签名操作的私钥。
Features | 主要功能:
- PGP public and secret key encapsulation - PGP 公钥和私钥封装
- Key capability checks (encrypt/sign) - 密钥能力检查(加密/签名)
Usage Examples | 使用示例:
PgpKeyPair pair = PgpKeyUtil.generateKeyPair("user@example.com", "pass");
String keyId = pair.keyIdHex();
boolean canEncrypt = pair.canEncrypt();
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-crypto V1.2.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionPgpKeyPair(org.bouncycastle.openpgp.PGPPublicKey publicKey, org.bouncycastle.openpgp.PGPSecretKey secretKey, String userId, long keyId) Creates a PGP key pair with the given public and secret keys. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if this key pair can be used for encryption.booleancanSign()Checks if this key pair can be used for signing.final booleanIndicates whether some other object is "equal to" this one.static PgpKeyPairfromSecretKey(org.bouncycastle.openpgp.PGPSecretKey secretKey, String userId) Creates a PGP key pair from secret key (derives public key automatically).final inthashCode()Returns a hash code value for this object.longkeyId()Returns the value of thekeyIdrecord component.keyIdHex()Returns the key ID as hexadecimal string.org.bouncycastle.openpgp.PGPPublicKeyReturns the value of thepublicKeyrecord component.org.bouncycastle.openpgp.PGPSecretKeyReturns the value of thesecretKeyrecord component.final StringtoString()Returns a string representation of this record class.userId()Returns the value of theuserIdrecord component.
-
Constructor Details
-
PgpKeyPair
public PgpKeyPair(org.bouncycastle.openpgp.PGPPublicKey publicKey, org.bouncycastle.openpgp.PGPSecretKey secretKey, String userId, long keyId) Creates a PGP key pair with the given public and secret keys. 使用给定的公钥和私钥创建 PGP 密钥对。- Parameters:
publicKey- the PGP public keysecretKey- the PGP secret keyuserId- the user IDkeyId- the key ID- Throws:
NullPointerException- if publicKey or secretKey is null
-
-
Method Details
-
fromSecretKey
public static PgpKeyPair fromSecretKey(org.bouncycastle.openpgp.PGPSecretKey secretKey, String userId) Creates a PGP key pair from secret key (derives public key automatically). 从私钥创建 PGP 密钥对(自动派生公钥)。- Parameters:
secretKey- the PGP secret keyuserId- the user ID- Returns:
- a new PgpKeyPair
-
keyIdHex
Returns the key ID as hexadecimal string. 返回十六进制格式的密钥 ID。- Returns:
- the key ID in hex format
-
canEncrypt
public boolean canEncrypt()Checks if this key pair can be used for encryption. 检查此密钥对是否可用于加密。- Returns:
- true if the public key can encrypt
-
canSign
public boolean canSign()Checks if this key pair can be used for signing. 检查此密钥对是否可用于签名。- Returns:
- true if the secret key can sign
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
publicKey
-
secretKey
-
userId
-
keyId
-