Package org.pgpainless.key.info
Class KeyRingInfo
- java.lang.Object
-
- org.pgpainless.key.info.KeyRingInfo
-
public class KeyRingInfo extends java.lang.Object
Utility class to quickly extract certain information from aPGPPublicKeyRing
/PGPSecretKeyRing
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
KeyRingInfo.Signatures
-
Constructor Summary
Constructors Constructor Description KeyRingInfo(org.bouncycastle.openpgp.PGPKeyRing keys)
Evaluate the key ring right now.KeyRingInfo(org.bouncycastle.openpgp.PGPKeyRing keys, java.util.Date validationDate)
Evaluate the key ring at the provided validation date.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static KeyRingInfo
evaluateForSignature(org.bouncycastle.openpgp.PGPKeyRing keyRing, org.bouncycastle.openpgp.PGPSignature signature)
Evaluate the key ring at creation time of the given signature.PublicKeyAlgorithm
getAlgorithm()
Return the algorithm of the primary key.java.util.Date
getCreationDate()
Return the creation date of the primary key.org.bouncycastle.openpgp.PGPSignature
getCurrentSubkeyBindingSignature(long keyId)
java.util.List<java.lang.String>
getEmailAddresses()
Return a list of all user-ids of the primary key that appear to be email-addresses.java.util.List<org.bouncycastle.openpgp.PGPPublicKey>
getEncryptionSubkeys(java.lang.String userId, EncryptionStream.Purpose purpose)
java.util.List<org.bouncycastle.openpgp.PGPPublicKey>
getEncryptionSubkeys(EncryptionStream.Purpose purpose)
OpenPgpV4Fingerprint
getFingerprint()
Return theOpenPgpV4Fingerprint
of this key ring.java.util.List<KeyFlag>
getKeyFlagsOf(long keyId)
java.util.List<KeyFlag>
getKeyFlagsOf(java.lang.String userId)
long
getKeyId()
Return the key id of the primary key of this key ring.java.util.Date
getLastModified()
Return the date on which the key ring was last modified.org.bouncycastle.openpgp.PGPSignature
getLatestDirectKeySelfSignature()
Return the latest direct-key self signature.org.bouncycastle.openpgp.PGPSignature
getLatestUserIdCertification(java.lang.String userId)
java.util.Set<HashAlgorithm>
getPreferredHashAlgorithms(java.lang.String userId, long keyID)
java.util.Date
getPrimaryKeyExpirationDate()
Return the date of expiration of the primary key or null if the key has no expiration date.java.lang.String
getPrimaryUserId()
Return the primary user-id of the key ring.org.bouncycastle.openpgp.PGPPublicKey
getPublicKey()
Return the firstPGPPublicKey
of this key ring.org.bouncycastle.openpgp.PGPPublicKey
getPublicKey(long keyId)
Return the public key with the given key id.static org.bouncycastle.openpgp.PGPPublicKey
getPublicKey(org.bouncycastle.openpgp.PGPKeyRing keyRing, long keyId)
Return the public key with the given key id from the provided key ring.org.bouncycastle.openpgp.PGPPublicKey
getPublicKey(OpenPgpV4Fingerprint fingerprint)
Return the public key with the given fingerprint.java.util.List<org.bouncycastle.openpgp.PGPPublicKey>
getPublicKeys()
Return allPGPPublicKeys
of this key ring.java.util.Date
getRevocationDate()
Return the date on which the primary key was revoked, or null if it has not yet been revoked.org.bouncycastle.openpgp.PGPSignature
getRevocationSelfSignature()
org.bouncycastle.openpgp.PGPSecretKey
getSecretKey()
Return the primaryPGPSecretKey
of this key ring or null if the key ring is not aPGPSecretKeyRing
.org.bouncycastle.openpgp.PGPSecretKey
getSecretKey(long keyId)
Return the secret key with the given key id.org.bouncycastle.openpgp.PGPSecretKey
getSecretKey(OpenPgpV4Fingerprint fingerprint)
Return the secret key with the given fingerprint.java.util.List<org.bouncycastle.openpgp.PGPSecretKey>
getSecretKeys()
Return all secret keys of the key ring.java.util.List<org.bouncycastle.openpgp.PGPPublicKey>
getSigningSubkeys()
java.util.Date
getSubkeyExpirationDate(OpenPgpV4Fingerprint fingerprint)
org.bouncycastle.openpgp.PGPSignature
getSubkeyRevocationSignature(long keyId)
org.bouncycastle.openpgp.PGPSignature
getUserIdRevocation(java.lang.String userId)
java.util.List<java.lang.String>
getUserIds()
Return a list of all user-ids of the primary key.java.util.List<java.lang.String>
getValidUserIds()
Return a list of valid user-ids.boolean
isFullyDecrypted()
Returns true when every secret key on the key ring is not encrypted.boolean
isFullyEncrypted()
Returns true when every secret key on the key ring is encrypted.boolean
isKeyValidlyBound(long keyId)
Return true if the public key with the given key id is bound to the key ring properly.boolean
isSecretKey()
Return true if the key ring is aPGPSecretKeyRing
.boolean
isUserIdValid(java.lang.String userId)
Return true if the provided user-id is valid.
-
-
-
Constructor Detail
-
KeyRingInfo
public KeyRingInfo(org.bouncycastle.openpgp.PGPKeyRing keys)
Evaluate the key ring right now.- Parameters:
keys
- key ring
-
KeyRingInfo
public KeyRingInfo(org.bouncycastle.openpgp.PGPKeyRing keys, java.util.Date validationDate)
Evaluate the key ring at the provided validation date.- Parameters:
keys
- key ringvalidationDate
- date of validation
-
-
Method Detail
-
evaluateForSignature
public static KeyRingInfo evaluateForSignature(org.bouncycastle.openpgp.PGPKeyRing keyRing, org.bouncycastle.openpgp.PGPSignature signature)
Evaluate the key ring at creation time of the given signature.- Parameters:
keyRing
- key ringsignature
- signature- Returns:
- info of key ring at signature creation time
-
getPublicKey
public org.bouncycastle.openpgp.PGPPublicKey getPublicKey()
Return the firstPGPPublicKey
of this key ring.- Returns:
- public key
-
getPublicKey
public org.bouncycastle.openpgp.PGPPublicKey getPublicKey(OpenPgpV4Fingerprint fingerprint)
Return the public key with the given fingerprint.- Parameters:
fingerprint
- fingerprint- Returns:
- public key or null
-
getPublicKey
public org.bouncycastle.openpgp.PGPPublicKey getPublicKey(long keyId)
Return the public key with the given key id.- Parameters:
keyId
- key id- Returns:
- public key or null
-
getPublicKey
public static org.bouncycastle.openpgp.PGPPublicKey getPublicKey(org.bouncycastle.openpgp.PGPKeyRing keyRing, long keyId)
Return the public key with the given key id from the provided key ring.- Parameters:
keyRing
- key ringkeyId
- key id- Returns:
- public key or null
-
isKeyValidlyBound
public boolean isKeyValidlyBound(long keyId)
Return true if the public key with the given key id is bound to the key ring properly.- Parameters:
keyId
- key id- Returns:
- true if key is bound validly
-
getPublicKeys
public java.util.List<org.bouncycastle.openpgp.PGPPublicKey> getPublicKeys()
Return allPGPPublicKeys
of this key ring. The first key in the list being the primary key. Note that the list is unmodifiable.- Returns:
- list of public keys
-
getSecretKey
public org.bouncycastle.openpgp.PGPSecretKey getSecretKey()
Return the primaryPGPSecretKey
of this key ring or null if the key ring is not aPGPSecretKeyRing
.- Returns:
- primary secret key or null if the key ring is public
-
getSecretKey
public org.bouncycastle.openpgp.PGPSecretKey getSecretKey(OpenPgpV4Fingerprint fingerprint)
Return the secret key with the given fingerprint.- Parameters:
fingerprint
- fingerprint- Returns:
- secret key or null
-
getSecretKey
public org.bouncycastle.openpgp.PGPSecretKey getSecretKey(long keyId)
Return the secret key with the given key id.- Parameters:
keyId
- key id- Returns:
- secret key or null
-
getSecretKeys
public java.util.List<org.bouncycastle.openpgp.PGPSecretKey> getSecretKeys()
Return all secret keys of the key ring. If the key ring is aPGPPublicKeyRing
, then return an empty list. Note that the list is unmodifiable.- Returns:
- list of secret keys
-
getKeyId
public long getKeyId()
Return the key id of the primary key of this key ring.- Returns:
- key id
-
getFingerprint
public OpenPgpV4Fingerprint getFingerprint()
Return theOpenPgpV4Fingerprint
of this key ring.- Returns:
- fingerprint
-
getPrimaryUserId
public java.lang.String getPrimaryUserId()
Return the primary user-id of the key ring. Note: If no user-id is marked as primary key using aPrimaryUserID
packet, this method returns the first valid user-id, otherwise null.- Returns:
- primary user-id or null
-
getUserIds
public java.util.List<java.lang.String> getUserIds()
Return a list of all user-ids of the primary key.- Returns:
- list of user-ids
-
getValidUserIds
public java.util.List<java.lang.String> getValidUserIds()
Return a list of valid user-ids.- Returns:
- valid user-ids
-
isUserIdValid
public boolean isUserIdValid(java.lang.String userId)
Return true if the provided user-id is valid.- Parameters:
userId
- user-id- Returns:
- true if user-id is valid
-
getEmailAddresses
public java.util.List<java.lang.String> getEmailAddresses()
Return a list of all user-ids of the primary key that appear to be email-addresses.- Returns:
- email addresses
-
getLatestDirectKeySelfSignature
public org.bouncycastle.openpgp.PGPSignature getLatestDirectKeySelfSignature()
Return the latest direct-key self signature. Note: This signature might be expired (check withSignatureUtils.isSignatureExpired(PGPSignature)
).- Returns:
- latest direct key self-signature
-
getRevocationSelfSignature
public org.bouncycastle.openpgp.PGPSignature getRevocationSelfSignature()
-
getLatestUserIdCertification
public org.bouncycastle.openpgp.PGPSignature getLatestUserIdCertification(java.lang.String userId)
-
getUserIdRevocation
public org.bouncycastle.openpgp.PGPSignature getUserIdRevocation(java.lang.String userId)
-
getCurrentSubkeyBindingSignature
public org.bouncycastle.openpgp.PGPSignature getCurrentSubkeyBindingSignature(long keyId)
-
getSubkeyRevocationSignature
public org.bouncycastle.openpgp.PGPSignature getSubkeyRevocationSignature(long keyId)
-
getKeyFlagsOf
public java.util.List<KeyFlag> getKeyFlagsOf(long keyId)
-
getKeyFlagsOf
public java.util.List<KeyFlag> getKeyFlagsOf(java.lang.String userId)
-
getAlgorithm
public PublicKeyAlgorithm getAlgorithm()
Return the algorithm of the primary key.- Returns:
- public key algorithm
-
getCreationDate
public java.util.Date getCreationDate()
Return the creation date of the primary key.- Returns:
- creation date
-
getLastModified
public java.util.Date getLastModified()
Return the date on which the key ring was last modified. This date corresponds to the date of the last signature that was made on this key ring by the primary key.- Returns:
- last modification date.
-
getRevocationDate
public java.util.Date getRevocationDate()
Return the date on which the primary key was revoked, or null if it has not yet been revoked.- Returns:
- revocation date or null
-
getPrimaryKeyExpirationDate
public java.util.Date getPrimaryKeyExpirationDate()
Return the date of expiration of the primary key or null if the key has no expiration date.- Returns:
- expiration date
-
getSubkeyExpirationDate
public java.util.Date getSubkeyExpirationDate(OpenPgpV4Fingerprint fingerprint)
-
isSecretKey
public boolean isSecretKey()
Return true if the key ring is aPGPSecretKeyRing
. If it is aPGPPublicKeyRing
return false and if it is neither, throw anAssertionError
.- Returns:
- true if the key ring is a secret key ring.
-
isFullyDecrypted
public boolean isFullyDecrypted()
Returns true when every secret key on the key ring is not encrypted. If there is at least one encrypted secret key on the key ring, returns false. If the key ring is aPGPPublicKeyRing
, returns true. Sub-keys with S2K of a type GNU_DUMMY_S2K do not affect the result.- Returns:
- true if all secret keys are unencrypted.
-
isFullyEncrypted
public boolean isFullyEncrypted()
Returns true when every secret key on the key ring is encrypted. If there is at least one not encrypted secret key on the key ring, returns false. If the key ring is aPGPPublicKeyRing
, returns false. Sub-keys with S2K of a type GNU_DUMMY_S2K do not affect a result.- Returns:
- true if all secret keys are encrypted.
-
getEncryptionSubkeys
public java.util.List<org.bouncycastle.openpgp.PGPPublicKey> getEncryptionSubkeys(EncryptionStream.Purpose purpose)
-
getEncryptionSubkeys
public java.util.List<org.bouncycastle.openpgp.PGPPublicKey> getEncryptionSubkeys(java.lang.String userId, EncryptionStream.Purpose purpose)
-
getSigningSubkeys
public java.util.List<org.bouncycastle.openpgp.PGPPublicKey> getSigningSubkeys()
-
getPreferredHashAlgorithms
public java.util.Set<HashAlgorithm> getPreferredHashAlgorithms(java.lang.String userId, long keyID)
-
-