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 / 与密钥关联的用户 ID
keyId - 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

    Constructors
    Constructor
    Description
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks if this key pair can be used for encryption.
    boolean
    Checks if this key pair can be used for signing.
    final boolean
    Indicates whether some other object is "equal to" this one.
    static PgpKeyPair
    fromSecretKey(org.bouncycastle.openpgp.PGPSecretKey secretKey, String userId)
    Creates a PGP key pair from secret key (derives public key automatically).
    final int
    Returns a hash code value for this object.
    long
    Returns the value of the keyId record component.
    Returns the key ID as hexadecimal string.
    org.bouncycastle.openpgp.PGPPublicKey
    Returns the value of the publicKey record component.
    org.bouncycastle.openpgp.PGPSecretKey
    Returns the value of the secretKey record component.
    final String
    Returns a string representation of this record class.
    Returns the value of the userId record component.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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 key
      secretKey - the PGP secret key
      userId - the user ID
      keyId - 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 key
      userId - the user ID
      Returns:
      a new PgpKeyPair
    • keyIdHex

      public String 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

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • publicKey

      public org.bouncycastle.openpgp.PGPPublicKey publicKey()
      Returns the value of the publicKey record component.
      Returns:
      the value of the publicKey record component
    • secretKey

      public org.bouncycastle.openpgp.PGPSecretKey secretKey()
      Returns the value of the secretKey record component.
      Returns:
      the value of the secretKey record component
    • userId

      public String userId()
      Returns the value of the userId record component.
      Returns:
      the value of the userId record component
    • keyId

      public long keyId()
      Returns the value of the keyId record component.
      Returns:
      the value of the keyId record component