org.bouncycastle.openpgp

Class PGPPublicKey

public class PGPPublicKey extends Object implements PublicKeyAlgorithmTags

general class to handle a PGP public key object.
Constructor Summary
PGPPublicKey(int algorithm, PublicKey pubKey, Date time, String provider)
Create a PGPPublicKey from the passed in JCA one.
Method Summary
static PGPPublicKeyaddCertification(PGPPublicKey key, String id, PGPSignature certification)
Add a certification to the given public key.
static PGPPublicKeyaddCertification(PGPPublicKey key, PGPSignature certification)
Add a revocation or some other key certification to a key.
voidencode(OutputStream outStream)
intgetAlgorithm()
Return the algorithm code associated with the public key.
intgetBitStrength()
Return the strength of the key in bits.
DategetCreationTime()
byte[]getEncoded()
byte[]getFingerprint()
Return the fingerprint of the key.
PublicKeygetKey(String provider)
Return the public key contained in the object.
longgetKeyID()
Return the keyID associated with the public key.
IteratorgetSignatures()
Return all signatures/certifications associated with this key.
IteratorgetSignaturesForID(String id)
Return any signatures associated with the passed in id.
IteratorgetSignaturesForUserAttribute(PGPUserAttributeSubpacketVector userAttributes)
Return an iterator of signatures associated with the passed in user attributes.
IteratorgetSignaturesOfType(int signatureType)
Return signatures of the passed in type that are on this key.
byte[]getTrustData()
Return the trust data associated with the public key, if present.
IteratorgetUserAttributes()
Return any user attribute vectors associated with the key.
IteratorgetUserIDs()
Return any userIDs associated with the key.
intgetValidDays()
longgetValidSeconds()
intgetVersion()
booleanisEncryptionKey()
Return true if this key is marked as suitable for using for encryption.
booleanisMasterKey()
Return true if this is a master key.
booleanisRevoked()
Check whether this (sub)key has a revocation signature on it.
static PGPPublicKeyremoveCertification(PGPPublicKey key, String id)
Remove any certifications associated with a given id on a key.
static PGPPublicKeyremoveCertification(PGPPublicKey key, String id, PGPSignature certification)
Remove any certifications associated with a given id on a key.

Constructor Detail

PGPPublicKey

public PGPPublicKey(int algorithm, PublicKey pubKey, Date time, String provider)
Create a PGPPublicKey from the passed in JCA one.

Note: the time passed in affects the value of the key's keyID, so you probably only want to do this once for a JCA key, or make sure you keep track of the time you used.

Parameters: algorithm asymmetric algorithm type representing the public key. pubKey actual public key to associate. time date of creation. provider provider to use for underlying digest calculations.

Throws: PGPException on key creation problem. NoSuchProviderException if the specified provider is required and cannot be found.

Method Detail

addCertification

public static PGPPublicKey addCertification(PGPPublicKey key, String id, PGPSignature certification)
Add a certification to the given public key.

Parameters: key the key the certification is to be added to. id the id the certification is associated with. certification the new certification.

Returns: the re-certified key.

addCertification

public static PGPPublicKey addCertification(PGPPublicKey key, PGPSignature certification)
Add a revocation or some other key certification to a key.

Parameters: key the key the revocation is to be added to. certification the key signature to be added.

Returns: the new changed public key object.

encode

public void encode(OutputStream outStream)

getAlgorithm

public int getAlgorithm()
Return the algorithm code associated with the public key.

Returns: int

getBitStrength

public int getBitStrength()
Return the strength of the key in bits.

Returns: bit strenght of key.

getCreationTime

public Date getCreationTime()

Returns: creation time of key.

getEncoded

public byte[] getEncoded()

getFingerprint

public byte[] getFingerprint()
Return the fingerprint of the key.

Returns: key fingerprint.

getKey

public PublicKey getKey(String provider)
Return the public key contained in the object.

Parameters: provider provider to construct the key for.

Returns: a JCE/JCA public key.

Throws: PGPException if the key algorithm is not recognised. NoSuchProviderException if the provider cannot be found.

getKeyID

public long getKeyID()
Return the keyID associated with the public key.

Returns: long

getSignatures

public Iterator getSignatures()
Return all signatures/certifications associated with this key.

Returns: an iterator (possibly empty) with all signatures/certifications.

getSignaturesForID

public Iterator getSignaturesForID(String id)
Return any signatures associated with the passed in id.

Parameters: id the id to be matched.

Returns: an iterator of PGPSignature objects.

getSignaturesForUserAttribute

public Iterator getSignaturesForUserAttribute(PGPUserAttributeSubpacketVector userAttributes)
Return an iterator of signatures associated with the passed in user attributes.

Parameters: userAttributes the vector of user attributes to be matched.

Returns: an iterator of PGPSignature objects.

getSignaturesOfType

public Iterator getSignaturesOfType(int signatureType)
Return signatures of the passed in type that are on this key.

Parameters: signatureType the type of the signature to be returned.

Returns: an iterator (possibly empty) of signatures of the given type.

getTrustData

public byte[] getTrustData()
Return the trust data associated with the public key, if present.

Returns: a byte array with trust data, null otherwise.

getUserAttributes

public Iterator getUserAttributes()
Return any user attribute vectors associated with the key.

Returns: an iterator of PGPUserAttributeSubpacketVector objects.

getUserIDs

public Iterator getUserIDs()
Return any userIDs associated with the key.

Returns: an iterator of Strings.

getValidDays

public int getValidDays()

Returns: number of valid days from creation time - zero means no expiry.

getValidSeconds

public long getValidSeconds()

Returns: number of valid seconds from creation time - zero means no expiry.

getVersion

public int getVersion()

Returns: the version of this key.

isEncryptionKey

public boolean isEncryptionKey()
Return true if this key is marked as suitable for using for encryption.

Returns: true if this key is marked as suitable for using for encryption.

isMasterKey

public boolean isMasterKey()
Return true if this is a master key.

Returns: true if a master key.

isRevoked

public boolean isRevoked()
Check whether this (sub)key has a revocation signature on it.

Returns: boolean indicating whether this (sub)key has been revoked.

removeCertification

public static PGPPublicKey removeCertification(PGPPublicKey key, String id)
Remove any certifications associated with a given id on a key.

Parameters: key the key the certifications are to be removed from. id the id that is to be removed.

Returns: the re-certified key, null if the id was not found on the key.

removeCertification

public static PGPPublicKey removeCertification(PGPPublicKey key, String id, PGPSignature certification)
Remove any certifications associated with a given id on a key.

Parameters: key the key the certifications are to be removed from. id the id that the certfication is to be removed from. certification the certfication to be removed.

Returns: the re-certified key, null if the certification was not found.