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
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.
-
-
Field Summary
Fields Modifier and Type Field Description 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.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
-
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
-
-
Constructor Summary
Constructors Constructor Description PublicKeyPacket(int version, int algorithm, java.util.Date time, BCPGKey key)
Construct an OpenPGP public primary key packet.PublicKeyPacket(int algorithm, java.util.Date time, BCPGKey key)
Deprecated.use versionedPublicKeyPacket(int, int, Date, BCPGKey)
instead
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
encode(BCPGOutputStream out)
Encode the packet to the OpenPGPBCPGOutputStream
.int
getAlgorithm()
Return thealgorithm 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 theKeyExpirationTime
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
-
-
-
-
Field Detail
-
VERSION_3
public static final int VERSION_3
OpenPGP v3 keys are deprecated. They can only be used with RSA.
-
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.
-
LIBREPGP_5
public static final int LIBREPGP_5
Non-Standard LibrePGP introduced v5, which is only supported by a subset of vendors.- See Also:
- Constant Field Values
-
VERSION_6
public static final int VERSION_6
OpenPGP v6 keys are newly introduced.
-
-
Constructor Detail
-
PublicKeyPacket
@Deprecated public PublicKeyPacket(int algorithm, java.util.Date time, BCPGKey key)
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
public PublicKeyPacket(int version, int algorithm, java.util.Date time, BCPGKey key)
Construct an OpenPGP public primary key packet.- Parameters:
version
- packet versionalgorithm
- public key algorithm idtime
- creation timekey
- key object
-
-
Method Detail
-
getVersion
public int getVersion()
Return the packet version.- Returns:
- packet version
-
getAlgorithm
public int getAlgorithm()
Return thealgorithm id
of the public key.- Returns:
- algorithm id
-
getValidDays
public int getValidDays()
Deprecated.v4 and v6 keys instead signal their expiration time via theKeyExpirationTime
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 OpenPGPBCPGOutputStream
. If theBCPGOutputStream
packet format is set toPacketFormat.ROUNDTRIP
, the result ofPacket.hasNewPacketFormat()
determines, which packet format is used to encode the packet. Otherwise, theBCPGOutputStream
dictates which format to use.- Specified by:
encode
in classContainedPacket
- Parameters:
out
- packet output stream- Throws:
java.io.IOException
-
getKeyID
public static long getKeyID(PublicKeyPacket publicPk, byte[] fingerprint)
-
-