public class OpenPGPCertificate
extends java.lang.Object
Compared to a PGPPublicKeyRing, an OpenPGPCertificate has been evaluated at (or rather for)
a given evaluation time. It offers a clean API for accessing the key-holder's preferences at a specific
point in time and makes sure, that relevant self-signatures on certificate components are validated and verified.
| Modifier and Type | Field and Description |
|---|---|
protected PGPKeyRing |
keyRing |
| Constructor and Description |
|---|
OpenPGPCertificate(PGPKeyRing keyRing)
Instantiate an
OpenPGPCertificate from a passed PGPKeyRing using the default
OpenPGPImplementation and its OpenPGPPolicy. |
OpenPGPCertificate(PGPKeyRing keyRing,
OpenPGPImplementation implementation)
Instantiate an
OpenPGPCertificate from a parsed PGPKeyRing
using the provided OpenPGPImplementation and its OpenPGPPolicy. |
OpenPGPCertificate(PGPKeyRing keyRing,
OpenPGPImplementation implementation,
OpenPGPPolicy policy)
Instantiate an
OpenPGPCertificate from a parsed PGPKeyRing
using the provided OpenPGPImplementation and provided OpenPGPPolicy. |
| Modifier and Type | Method and Description |
|---|---|
java.util.List<KeyIdentifier> |
getAllKeyIdentifiers()
Return a list of ALL (sub-)key's identifiers, including those of expired / revoked / unbound keys.
|
java.util.List<OpenPGPCertificate.OpenPGPComponentSignature> |
getAllThirdPartyKeySignatures()
Return a list containing all third-party issued key signatures on the primary key (delegations
and revocations).
|
java.util.List<OpenPGPCertificate.OpenPGPUserId> |
getAllUserIds()
Return a
List of all OpenPGPUserIds on the certificate, regardless of their
validity. |
OpenPGPCertificate.OpenPGPComponentSignature |
getCertification()
Return the current self-certification signature.
|
OpenPGPCertificate.OpenPGPComponentSignature |
getCertification(java.util.Date evaluationTime)
Return the most recent self-certification signature at evaluation time.
|
java.util.List<OpenPGPCertificate.OpenPGPComponentKey> |
getCertificationKeys()
Return a
List containing all currently valid marked certification keys. |
java.util.List<OpenPGPCertificate.OpenPGPComponentKey> |
getCertificationKeys(java.util.Date evaluationTime)
Return a list of all keys that - at evaluation time - are validly marked as certification keys.
|
java.util.List<OpenPGPCertificate.OpenPGPComponentKey> |
getComponentKeysWithFlag(java.util.Date evaluationTime,
int... keyFlags)
Return a
List containing all component keys that carry any of the
given key flags at evaluation time. |
java.util.List<OpenPGPCertificate.OpenPGPCertificateComponent> |
getComponents()
Return a
List containing all components of the certificate. |
OpenPGPCertificate.OpenPGPSignatureChain |
getDelegationBy(OpenPGPCertificate thirdPartyCertificate)
Return an
OpenPGPCertificate.OpenPGPSignatureChain from the given 3rd-party certificate to this certificate,
which represents a delegation of trust. |
OpenPGPCertificate.OpenPGPSignatureChain |
getDelegationBy(OpenPGPCertificate thirdPartyCertificate,
java.util.Date evaluationTime)
Return an
OpenPGPCertificate.OpenPGPSignatureChain from the given 3rd-party certificate to this certificate,
which represents a delegation of trust at evaluation time. |
OpenPGPCertificate.OpenPGPSignatureChains |
getDelegationsBy(OpenPGPCertificate thirdPartyCertificate)
Return all
OpenPGPCertificate.OpenPGPSignatureChains that represent delegations by the given
third-party OpenPGPCertificate on this certificates primary key. |
byte[] |
getEncoded()
Return a byte array containing the binary representation of the certificate.
|
byte[] |
getEncoded(PacketFormat format)
Return a byte array containing the binary representation of the certificate, encoded using the
given packet length encoding format.
|
java.util.List<OpenPGPCertificate.OpenPGPComponentKey> |
getEncryptionKeys()
Return a
List containing all currently marked, valid encryption keys. |
java.util.List<OpenPGPCertificate.OpenPGPComponentKey> |
getEncryptionKeys(java.util.Date evaluationTime)
Return a list of all keys that are - at evaluation time - valid encryption keys.
|
java.util.List<OpenPGPCertificate.OpenPGPComponentKey> |
getEncryptionKeys(java.util.Date evaluationTime,
int... keyFlags)
Return a list of all keys that are - at evaluation time - valid encryption keys and carry any of the given
key flags.
|
java.util.Date |
getExpirationTime()
Return the time at which the certificate expires.
|
java.util.Date |
getExpirationTime(java.util.Date evaluationTime)
Return the time at which the certificate is expected to expire, considering the given evaluation time.
|
byte[] |
getFingerprint()
Return the primary keys fingerprint in binary format.
|
java.util.List<OpenPGPCertificate.OpenPGPIdentityComponent> |
getIdentities()
Return all identities (
User IDs, User Attributes
of the certificate. |
OpenPGPCertificate.OpenPGPComponentKey |
getKey(KeyIdentifier identifier)
Return the
OpenPGPCertificate.OpenPGPComponentKey identified by the passed in KeyIdentifier. |
KeyIdentifier |
getKeyIdentifier()
Return the
KeyIdentifier of the certificates primary key. |
java.util.List<OpenPGPCertificate.OpenPGPComponentKey> |
getKeys()
Return all
OpenPGPComponentKeys in the certificate. |
java.util.Date |
getLastModificationDate()
Return the last time, the key was modified (before right now).
|
java.util.Date |
getLastModificationDateAt(java.util.Date evaluationTime)
Return the last time, the key was modified before or at the given evaluation time.
|
PGPKeyRing |
getPGPKeyRing()
Return the
PGPKeyRing that this certificate is based on. |
PGPPublicKeyRing |
getPGPPublicKeyRing()
Return the underlying
PGPPublicKeyRing. |
java.lang.String |
getPrettyFingerprint()
Return the primary keys fingerprint as a pretty-printed
String. |
OpenPGPCertificate.OpenPGPPrimaryKey |
getPrimaryKey()
Return the primary key of the certificate.
|
OpenPGPCertificate.OpenPGPUserId |
getPrimaryUserId()
Return the current primary
OpenPGPCertificate.OpenPGPUserId of the certificate. |
OpenPGPCertificate.OpenPGPUserId |
getPrimaryUserId(java.util.Date evaluationTime)
Return the
OpenPGPCertificate.OpenPGPUserId that is considered primary at the given evaluation time. |
java.util.Map<KeyIdentifier,OpenPGPCertificate.OpenPGPComponentKey> |
getPublicKeys()
|
OpenPGPCertificate.OpenPGPComponentSignature |
getRevocation()
Return the most recent revocation signature on the certificate.
|
OpenPGPCertificate.OpenPGPComponentSignature |
getRevocation(java.util.Date evaluationTime)
Return the (at evaluation time) most recent revocation signature on the certificate.
|
OpenPGPCertificate.OpenPGPSignatureChain |
getRevocationBy(OpenPGPCertificate thirdPartyCertificate)
Return an
OpenPGPCertificate.OpenPGPSignatureChain from the given 3rd-party certificate to this certificate,
which represents a revocation of trust. |
OpenPGPCertificate.OpenPGPSignatureChain |
getRevocationBy(OpenPGPCertificate thirdPartyCertificate,
java.util.Date evaluationTime)
Return an
OpenPGPCertificate.OpenPGPSignatureChain from the given 3rd-party certificate to this certificate,
which (at evaluation time) represents a revocation of trust. |
OpenPGPCertificate.OpenPGPSignatureChains |
getRevocationsBy(OpenPGPCertificate thirdPartyCertificate)
Return all
OpenPGPCertificate.OpenPGPSignatureChains that represent revocations of delegations by the given
third-party OpenPGPCertificate on this certificates primary key. |
OpenPGPCertificate.OpenPGPComponentKey |
getSigningKeyFor(PGPSignature signature)
Return the
OpenPGPCertificate.OpenPGPComponentKey that likely issued the passed in PGPSignature. |
java.util.List<OpenPGPCertificate.OpenPGPComponentKey> |
getSigningKeys()
Return a
List containing all currently valid marked signing keys. |
java.util.List<OpenPGPCertificate.OpenPGPComponentKey> |
getSigningKeys(java.util.Date evaluationTime)
Return a list of all keys that - at evaluation time - are validly marked as signing keys.
|
java.util.Map<KeyIdentifier,OpenPGPCertificate.OpenPGPSubkey> |
getSubkeys()
Return a
Map containing the subkeys of this certificate, keyed by their KeyIdentifier. |
OpenPGPCertificate.OpenPGPUserId |
getUserId(java.lang.String userId)
Return the
OpenPGPCertificate.OpenPGPUserId object matching the given user-id String. |
java.util.List<OpenPGPCertificate.OpenPGPComponentKey> |
getValidKeys()
Return a
List of all component keys that are valid right now. |
java.util.List<OpenPGPCertificate.OpenPGPComponentKey> |
getValidKeys(java.util.Date evaluationTime)
Return a
List of all component keys that are valid at the given
evaluation time. |
java.util.List<OpenPGPCertificate.OpenPGPUserId> |
getValidUserIds()
Return a
List of all valid OpenPGPUserIds on the certificate. |
java.util.List<OpenPGPCertificate.OpenPGPUserId> |
getValidUserIds(java.util.Date evaluationTime)
Return a
List containing all OpenPGPUserIds that are valid at the given
evaluation time. |
boolean |
isSecretKey()
Return true, if this object is an
OpenPGPKey, false otherwise. |
static OpenPGPCertificate |
join(OpenPGPCertificate certificate,
OpenPGPCertificate other)
Join two copies of the same
OpenPGPCertificate, merging its components
into a single instance. |
static OpenPGPCertificate |
join(OpenPGPCertificate certificate,
java.lang.String armored)
Join two copies of the same
OpenPGPCertificate, merging its components
into a single instance. |
java.lang.String |
toAsciiArmoredString()
Return an ASCII armored
String containing the certificate. |
java.lang.String |
toAsciiArmoredString(PacketFormat packetFormat)
Return an ASCII armored
String containing the certificate. |
java.lang.String |
toAsciiArmoredString(PacketFormat packetFormat,
ArmoredOutputStream.Builder armorBuilder)
Return an ASCII armored
String containing the certificate. |
protected PGPKeyRing keyRing
public OpenPGPCertificate(PGPKeyRing keyRing)
OpenPGPCertificate from a passed PGPKeyRing using the default
OpenPGPImplementation and its OpenPGPPolicy.keyRing - key ringpublic OpenPGPCertificate(PGPKeyRing keyRing, OpenPGPImplementation implementation)
OpenPGPCertificate from a parsed PGPKeyRing
using the provided OpenPGPImplementation and its OpenPGPPolicy.keyRing - public key ringimplementation - OpenPGP implementationpublic OpenPGPCertificate(PGPKeyRing keyRing, OpenPGPImplementation implementation, OpenPGPPolicy policy)
OpenPGPCertificate from a parsed PGPKeyRing
using the provided OpenPGPImplementation and provided OpenPGPPolicy.keyRing - public key ringimplementation - OpenPGP implementationpolicy - OpenPGP policypublic boolean isSecretKey()
OpenPGPKey, false otherwise.public java.util.List<OpenPGPCertificate.OpenPGPUserId> getAllUserIds()
List of all OpenPGPUserIds on the certificate, regardless of their
validity.public java.util.List<OpenPGPCertificate.OpenPGPUserId> getValidUserIds()
List of all valid OpenPGPUserIds on the certificate.public java.util.List<OpenPGPCertificate.OpenPGPUserId> getValidUserIds(java.util.Date evaluationTime)
List containing all OpenPGPUserIds that are valid at the given
evaluation time.evaluationTime - reference timepublic java.util.Map<KeyIdentifier,OpenPGPCertificate.OpenPGPComponentKey> getPublicKeys()
public OpenPGPCertificate.OpenPGPPrimaryKey getPrimaryKey()
public java.util.Map<KeyIdentifier,OpenPGPCertificate.OpenPGPSubkey> getSubkeys()
Map containing the subkeys of this certificate, keyed by their KeyIdentifier.
Note: This map does NOT contain the primary key (getPrimaryKey()).public java.util.List<OpenPGPCertificate.OpenPGPComponentKey> getComponentKeysWithFlag(java.util.Date evaluationTime, int... keyFlags)
List containing all component keys that carry any of the
given key flags at evaluation time.
Note: To get all component keys that have EITHER KeyFlags.ENCRYPT_COMMS OR KeyFlags.ENCRYPT_STORAGE,
call this method like this:
keys = getComponentKeysWithFlag(date, KeyFlags.ENCRYPT_COMMS, KeyFlags.ENCRYPT_STORAGE);If you instead want to access all keys, that have BOTH flags, you need to
|both flags:
keys = getComponentKeysWithFlag(date, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);
evaluationTime - reference timekeyFlags - key flagspublic java.util.List<OpenPGPCertificate.OpenPGPCertificateComponent> getComponents()
List containing all components of the certificate.
Components are primary key, subkeys and identities (user-ids, user attributes).public java.util.List<OpenPGPCertificate.OpenPGPComponentKey> getKeys()
OpenPGPComponentKeys in the certificate.
The return value is a List containing the OpenPGPCertificate.OpenPGPPrimaryKey and all
OpenPGPSubkeys.public java.util.List<OpenPGPCertificate.OpenPGPComponentKey> getValidKeys()
List of all component keys that are valid right now.public java.util.List<OpenPGPCertificate.OpenPGPComponentKey> getValidKeys(java.util.Date evaluationTime)
List of all component keys that are valid at the given
evaluation time.evaluationTime - reference timepublic OpenPGPCertificate.OpenPGPComponentKey getKey(KeyIdentifier identifier)
OpenPGPCertificate.OpenPGPComponentKey identified by the passed in KeyIdentifier.identifier - key identifierpublic OpenPGPCertificate.OpenPGPComponentKey getSigningKeyFor(PGPSignature signature)
OpenPGPCertificate.OpenPGPComponentKey that likely issued the passed in PGPSignature.signature - signaturepublic PGPKeyRing getPGPKeyRing()
PGPKeyRing that this certificate is based on.public PGPPublicKeyRing getPGPPublicKeyRing()
PGPPublicKeyRing.public KeyIdentifier getKeyIdentifier()
KeyIdentifier of the certificates primary key.public java.util.List<KeyIdentifier> getAllKeyIdentifiers()
public OpenPGPCertificate.OpenPGPComponentSignature getCertification()
OpenPGPCertificate.OpenPGPUserId.public OpenPGPCertificate.OpenPGPComponentSignature getCertification(java.util.Date evaluationTime)
OpenPGPCertificate.OpenPGPUserId.evaluationTime - reference timepublic OpenPGPCertificate.OpenPGPComponentSignature getRevocation()
OpenPGPCertificate.OpenPGPUserId.public OpenPGPCertificate.OpenPGPComponentSignature getRevocation(java.util.Date evaluationTime)
OpenPGPCertificate.OpenPGPUserId.evaluationTime - reference timepublic java.util.Date getLastModificationDate()
public java.util.Date getLastModificationDateAt(java.util.Date evaluationTime)
evaluationTime - evaluation timepublic static OpenPGPCertificate join(OpenPGPCertificate certificate, java.lang.String armored) throws java.io.IOException, PGPException
OpenPGPCertificate, merging its components
into a single instance.
The ASCII armored String might contain more than one OpenPGPCertificate.
Items that are not a copy of the base certificate are silently ignored.certificate - base certificatearmored - ASCII armored String containing one or more copies of the same certificate,
possibly containing a different set of componentsjava.io.IOException - if the armored data cannot be processedPGPException - if a protocol level error occurspublic static OpenPGPCertificate join(OpenPGPCertificate certificate, OpenPGPCertificate other) throws PGPException
OpenPGPCertificate, merging its components
into a single instance.certificate - base certificateother - copy of the same certificate, potentially carrying a different set of componentsPGPException - if a protocol level error occurspublic byte[] getFingerprint()
public java.lang.String getPrettyFingerprint()
String.public java.lang.String toAsciiArmoredString()
throws java.io.IOException
String containing the certificate.java.io.IOException - if the cert cannot be encodedpublic java.lang.String toAsciiArmoredString(PacketFormat packetFormat) throws java.io.IOException
String containing the certificate.packetFormat - packet length encoding formatjava.io.IOException - if the cert cannot be encodedpublic java.lang.String toAsciiArmoredString(PacketFormat packetFormat, ArmoredOutputStream.Builder armorBuilder) throws java.io.IOException
String containing the certificate.
The ArmoredOutputStream.Builder can be used to customize the ASCII armor (headers, CRC etc.).packetFormat - packet length encoding formatarmorBuilder - builder for the ASCII armored output streamjava.io.IOException - if the cert cannot be encodedpublic byte[] getEncoded()
throws java.io.IOException
java.io.IOException - if the certificate cannot be encodedpublic byte[] getEncoded(PacketFormat format) throws java.io.IOException
format - packet length encoding formatjava.io.IOException - if the certificate cannot be encodedpublic java.util.List<OpenPGPCertificate.OpenPGPComponentKey> getEncryptionKeys()
List containing all currently marked, valid encryption keys.public java.util.List<OpenPGPCertificate.OpenPGPComponentKey> getEncryptionKeys(java.util.Date evaluationTime)
evaluationTime - evaluation timepublic java.util.List<OpenPGPCertificate.OpenPGPComponentKey> getEncryptionKeys(java.util.Date evaluationTime, int... keyFlags)
getEncryptionKeys(evalTime, A, B). To instead get all keys that have BOTH flags A AND B, call
getEncryptionKeys(evalTime, A | B).
evaluationTime - evaluation timekeyFlags - key flagsKeyFlagspublic java.util.List<OpenPGPCertificate.OpenPGPComponentKey> getSigningKeys()
List containing all currently valid marked signing keys.public java.util.List<OpenPGPCertificate.OpenPGPComponentKey> getSigningKeys(java.util.Date evaluationTime)
evaluationTime - evaluation timepublic java.util.List<OpenPGPCertificate.OpenPGPComponentKey> getCertificationKeys()
List containing all currently valid marked certification keys.public java.util.List<OpenPGPCertificate.OpenPGPComponentKey> getCertificationKeys(java.util.Date evaluationTime)
evaluationTime - evaluation timepublic java.util.List<OpenPGPCertificate.OpenPGPIdentityComponent> getIdentities()
User IDs, User Attributes
of the certificate.public OpenPGPCertificate.OpenPGPUserId getPrimaryUserId()
OpenPGPCertificate.OpenPGPUserId of the certificate.public OpenPGPCertificate.OpenPGPUserId getPrimaryUserId(java.util.Date evaluationTime)
OpenPGPCertificate.OpenPGPUserId that is considered primary at the given evaluation time.evaluationTime - evaluation timepublic OpenPGPCertificate.OpenPGPUserId getUserId(java.lang.String userId)
OpenPGPCertificate.OpenPGPUserId object matching the given user-id String.userId - user-idpublic java.util.Date getExpirationTime()
public java.util.Date getExpirationTime(java.util.Date evaluationTime)
evaluationTime - reference timepublic java.util.List<OpenPGPCertificate.OpenPGPComponentSignature> getAllThirdPartyKeySignatures()
public OpenPGPCertificate.OpenPGPSignatureChains getDelegationsBy(OpenPGPCertificate thirdPartyCertificate)
OpenPGPCertificate.OpenPGPSignatureChains that represent delegations by the given
third-party OpenPGPCertificate on this certificates primary key.
A delegation is a signature of type PGPSignature.DIRECT_KEY, which represents a
delegation of trust and can be used to mark the certificate as a trusted introducer.
Each delegation is returned as an OpenPGPCertificate.OpenPGPSignatureChain where the delegation
is the leaf link prepended by the binding signature chain of the issuing third-party
certificate component at delegation signature creation time.thirdPartyCertificate - third-party certificate which issued the delegation signaturespublic OpenPGPCertificate.OpenPGPSignatureChain getDelegationBy(OpenPGPCertificate thirdPartyCertificate)
OpenPGPCertificate.OpenPGPSignatureChain from the given 3rd-party certificate to this certificate,
which represents a delegation of trust.
The delegation is returned as an OpenPGPCertificate.OpenPGPSignatureChain where the delegation
is the leaf link prepended by the binding signature chain of the issuing third-party
certificate component at delegation signature creation time.
If no delegation signature is found, return null.thirdPartyCertificate - OpenPGPCertificate of a 3rd party.public OpenPGPCertificate.OpenPGPSignatureChain getDelegationBy(OpenPGPCertificate thirdPartyCertificate, java.util.Date evaluationTime)
OpenPGPCertificate.OpenPGPSignatureChain from the given 3rd-party certificate to this certificate,
which represents a delegation of trust at evaluation time.
The delegation is returned as an OpenPGPCertificate.OpenPGPSignatureChain where the delegation
is the leaf link prepended by the binding signature chain of the issuing third-party
certificate component at delegation signature creation time.
If no delegation signature is found, return null.thirdPartyCertificate - OpenPGPCertificate of a 3rd party.evaluationTime - reference timepublic OpenPGPCertificate.OpenPGPSignatureChains getRevocationsBy(OpenPGPCertificate thirdPartyCertificate)
OpenPGPCertificate.OpenPGPSignatureChains that represent revocations of delegations by the given
third-party OpenPGPCertificate on this certificates primary key.
A delegation revocation is a signature of type PGPSignature.KEY_REVOCATION, which revokes an earlier
delegation of trust.
Each revocation is returned as an OpenPGPCertificate.OpenPGPSignatureChain where the revocation
is the leaf link prepended by the binding signature chain of the issuing third-party
certificate component at revocation signature creation time.thirdPartyCertificate - third-party certificate which issued the revocation signaturespublic OpenPGPCertificate.OpenPGPSignatureChain getRevocationBy(OpenPGPCertificate thirdPartyCertificate)
OpenPGPCertificate.OpenPGPSignatureChain from the given 3rd-party certificate to this certificate,
which represents a revocation of trust.
The revocation is returned as an OpenPGPCertificate.OpenPGPSignatureChain where the revocation
is the leaf link prepended by the binding signature chain of the issuing third-party
certificate component at revocation signature creation time.thirdPartyCertificate - OpenPGPCertificate of a 3rd party.public OpenPGPCertificate.OpenPGPSignatureChain getRevocationBy(OpenPGPCertificate thirdPartyCertificate, java.util.Date evaluationTime)
OpenPGPCertificate.OpenPGPSignatureChain from the given 3rd-party certificate to this certificate,
which (at evaluation time) represents a revocation of trust.
The revocation is returned as an OpenPGPCertificate.OpenPGPSignatureChain where the revocation
is the leaf link prepended by the binding signature chain of the issuing third-party
certificate component at revocation signature creation time.thirdPartyCertificate - OpenPGPCertificate of a 3rd party.evaluationTime - reference time