Package org.bouncycastle.bcpg
Class PublicKeyPacket
java.lang.Object
org.bouncycastle.bcpg.Packet
org.bouncycastle.bcpg.ContainedPacket
org.bouncycastle.bcpg.PublicKeyPacket
- All Implemented Interfaces:
PacketTags,PublicKeyAlgorithmTags,org.bouncycastle.util.Encodable
- Direct Known Subclasses:
PublicSubkeyPacket
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intNon-Standard LibrePGP introduced v5, which is only supported by a subset of vendors.static final intOpenPGP v3 keys are deprecated.static final intOpenPGP v4 keys are (at the time of writing) widely used, but are subject to some attacks.static final intOpenPGP v6 keys are newly introduced.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_IDFields 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 -
Constructor Summary
ConstructorsConstructorDescriptionPublicKeyPacket(int version, int algorithm, Date time, BCPGKey key) Construct an OpenPGP public primary key packet.PublicKeyPacket(int algorithm, Date time, BCPGKey key) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoidencode(BCPGOutputStream out) Encode the packet to the OpenPGPBCPGOutputStream.intReturn thealgorithm idof the public key.byte[]Return the encoded packet contents without the packet frame.getKey()Return the key object.static longgetKeyID(PublicKeyPacket publicPk, byte[] fingerprint) getTime()Return the keys creation time.intDeprecated.v4 and v6 keys instead signal their expiration time via theKeyExpirationTimesignature subpacket.intReturn the packet version.Methods inherited from class org.bouncycastle.bcpg.ContainedPacket
getEncoded, getEncodedMethods inherited from class org.bouncycastle.bcpg.Packet
getPacketTag, hasNewPacketFormat, isCritical
-
Field Details
-
VERSION_3
public static final int VERSION_3OpenPGP v3 keys are deprecated. They can only be used with RSA.- See Also:
-
VERSION_4
public static final int VERSION_4OpenPGP v4 keys are (at the time of writing) widely used, but are subject to some attacks.- See Also:
-
LIBREPGP_5
public static final int LIBREPGP_5Non-Standard LibrePGP introduced v5, which is only supported by a subset of vendors.- See Also:
-
VERSION_6
public static final int VERSION_6OpenPGP v6 keys are newly introduced.- See Also:
-
-
Constructor Details
-
PublicKeyPacket
Deprecated.use versionedPublicKeyPacket(int, int, Date, BCPGKey)insteadConstruct version 4 public primary key packet.- Parameters:
algorithm- public key algorithm idtime- creation timekey- key object
-
PublicKeyPacket
Construct an OpenPGP public primary key packet.- Parameters:
version- packet versionalgorithm- public key algorithm idtime- creation timekey- key object
-
-
Method Details
-
getVersion
public int getVersion()Return the packet version.- Returns:
- packet version
-
getAlgorithm
public int getAlgorithm()Return thealgorithm idof the public key.- Returns:
- algorithm id
-
getValidDays
public int getValidDays()Deprecated.v4 and v6 keys instead signal their expiration time via theKeyExpirationTimesignature 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
Return the keys creation time.- Returns:
- creation time of the key
-
getKey
Return the key object.- Returns:
- key
-
getEncodedContents
Return the encoded packet contents without the packet frame.- Returns:
- encoded packet contents
- Throws:
IOException
-
encode
Encode the packet to the OpenPGPBCPGOutputStream. If theBCPGOutputStreampacket format is set toPacketFormat.ROUNDTRIP, the result ofPacket.hasNewPacketFormat()determines, which packet format is used to encode the packet. Otherwise, theBCPGOutputStreamdictates which format to use.- Specified by:
encodein classContainedPacket- Parameters:
out- packet output stream- Throws:
IOException
-
getKeyID
-
PublicKeyPacket(int, int, Date, BCPGKey)instead