Bouncy Castle Cryptography Library 1.79

org.bouncycastle.bcpg
Class PublicKeyPacket

java.lang.Object
  |
  +--org.bouncycastle.bcpg.Packet
        |
        +--org.bouncycastle.bcpg.ContainedPacket
              |
              +--org.bouncycastle.bcpg.PublicKeyPacket
All Implemented Interfaces:
org.bouncycastle.util.Encodable, PacketTags, PublicKeyAlgorithmTags
Direct Known Subclasses:
PublicSubkeyPacket

public class PublicKeyPacket
extends ContainedPacket
implements PublicKeyAlgorithmTags

Base class for OpenPGP public (primary) keys. The public key packet holds the public parameters of an OpenPGP key pair. An OpenPGP certificate (transferable public key) consists of one primary key and optionally multiple subkey packets.

See Also:
RFC4880 - Public-Key Packet, RFC9580 - Public-Key Packet, LibrePGP - Public-Key Packet

Field Summary
static int LIBREPGP_5
          Non-Standard LibrePGP introduced v5, which is only supported by a subset of vendors.
static int VERSION_3
          OpenPGP v3 keys are deprecated.
static int VERSION_4
          OpenPGP v4 keys are (at the time of writing) widely used, but are subject to some attacks.
static int VERSION_6
          OpenPGP v6 keys are newly introduced.
 
Fields inherited from interface org.bouncycastle.bcpg.PublicKeyAlgorithmTags
AEDH, AEDSA, DIFFIE_HELLMAN, DSA, EC, ECDH, ECDSA, Ed25519, Ed448, EDDSA, EDDSA_LEGACY, ELGAMAL_ENCRYPT, ELGAMAL_GENERAL, EXPERIMENTAL_1, EXPERIMENTAL_10, EXPERIMENTAL_11, EXPERIMENTAL_2, EXPERIMENTAL_3, EXPERIMENTAL_4, EXPERIMENTAL_5, EXPERIMENTAL_6, EXPERIMENTAL_7, EXPERIMENTAL_8, EXPERIMENTAL_9, RSA_ENCRYPT, RSA_GENERAL, RSA_SIGN, X25519, X448
 
Fields inherited from interface org.bouncycastle.bcpg.PacketTags
AEAD_ENC_DATA, COMPRESSED_DATA, EXPERIMENTAL_1, EXPERIMENTAL_2, EXPERIMENTAL_3, EXPERIMENTAL_4, LITERAL_DATA, MARKER, MOD_DETECTION_CODE, ONE_PASS_SIGNATURE, PADDING, PUBLIC_KEY, PUBLIC_KEY_ENC_SESSION, PUBLIC_SUBKEY, RESERVED, SECRET_KEY, SECRET_SUBKEY, SIGNATURE, SYM_ENC_INTEGRITY_PRO, SYMMETRIC_KEY_ENC, SYMMETRIC_KEY_ENC_SESSION, TRUST, USER_ATTRIBUTE, USER_ID
 
Constructor Summary
PublicKeyPacket(int algorithm, java.util.Date time, BCPGKey key)
          Deprecated. use versioned PublicKeyPacket(int, int, Date, BCPGKey) instead
PublicKeyPacket(int version, int algorithm, java.util.Date time, BCPGKey key)
          Construct an OpenPGP public primary key packet.
 
Method Summary
 void encode(BCPGOutputStream out)
          Encode the packet to the OpenPGP BCPGOutputStream.
 int getAlgorithm()
          Return the algorithm id of the public key.
 byte[] getEncodedContents()
          Return the encoded packet contents without the packet frame.
 BCPGKey getKey()
          Return the key object.
static long getKeyID(PublicKeyPacket publicPk, byte[] fingerprint)
           
 java.util.Date getTime()
          Return the keys creation time.
 int getValidDays()
          Deprecated. v4 and v6 keys instead signal their expiration time via the KeyExpirationTime signature subpacket.
 int getVersion()
          Return the packet version.
 
Methods inherited from class org.bouncycastle.bcpg.ContainedPacket
getEncoded, getEncoded
 
Methods inherited from class org.bouncycastle.bcpg.Packet
getPacketTag, hasNewPacketFormat, isCritical
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION_3

public static final int VERSION_3
OpenPGP v3 keys are deprecated. They can only be used with RSA.
See Also:
OpenPGP - Version 3 Public Keys

VERSION_4

public static final int VERSION_4
OpenPGP v4 keys are (at the time of writing) widely used, but are subject to some attacks.
See Also:
OpenPGP - Version 4 Public Keys

LIBREPGP_5

public static final int LIBREPGP_5
Non-Standard LibrePGP introduced v5, which is only supported by a subset of vendors.

VERSION_6

public static final int VERSION_6
OpenPGP v6 keys are newly introduced.
See Also:
OpenPGP - Version 6 Public Keys
Constructor Detail

PublicKeyPacket

public PublicKeyPacket(int algorithm,
                       java.util.Date time,
                       BCPGKey key)
Deprecated. use versioned PublicKeyPacket(int, int, Date, BCPGKey) instead

Construct version 4 public primary key packet.
Parameters:
algorithm - public key algorithm id
time - creation time
key - key object

PublicKeyPacket

public PublicKeyPacket(int version,
                       int algorithm,
                       java.util.Date time,
                       BCPGKey key)
Construct an OpenPGP public primary key packet.
Parameters:
version - packet version
algorithm - public key algorithm id
time - creation time
key - key object
Method Detail

getVersion

public int getVersion()
Return the packet version.
Returns:
packet version

getAlgorithm

public int getAlgorithm()
Return the algorithm id of the public key.
Returns:
algorithm id

getValidDays

public int getValidDays()
Deprecated. v4 and v6 keys instead signal their expiration time via the KeyExpirationTime signature subpacket.

Only for v3 keys - The time in days since the keys creation, during which the key is valid.
Returns:
v3 key validity period in days since creation.

getTime

public java.util.Date getTime()
Return the keys creation time.
Returns:
creation time of the key

getKey

public BCPGKey getKey()
Return the key object.
Returns:
key

getEncodedContents

public byte[] getEncodedContents()
                          throws java.io.IOException
Return the encoded packet contents without the packet frame.
Returns:
encoded packet contents
Throws:
java.io.IOException -  

encode

public void encode(BCPGOutputStream out)
            throws java.io.IOException
Encode the packet to the OpenPGP BCPGOutputStream. If the BCPGOutputStream packet format is set to PacketFormat.ROUNDTRIP, the result of Packet.hasNewPacketFormat() determines, which packet format is used to encode the packet. Otherwise, the BCPGOutputStream dictates which format to use.
Overrides:
encode in class ContainedPacket
Parameters:
out - packet output stream
Throws:
java.io.IOException -  

getKeyID

public static long getKeyID(PublicKeyPacket publicPk,
                            byte[] fingerprint)

Bouncy Castle Cryptography Library 1.79