Bouncy Castle Cryptography Library 1.45

## org.bouncycastle.openpgp
Class PGPPublicKey

    java.lang.Object
      org.bouncycastle.openpgp.PGPPublicKey

All Implemented Interfaces:
  PublicKeyAlgorithmTags

    public class PGPPublicKey

extends java.lang.Object
implements PublicKeyAlgorithmTags

general class to handle a PGP public key object.

Field Summary

Fields inherited from interface org.bouncycastle.bcpg.PublicKeyAlgorithmTags
`DIFFIE_HELLMAN, DSA, EC, ECDSA, 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`

Constructor Summary
`PGPPublicKey(int algorithm, java.security.PublicKey pubKey, java.util.Date time)`
`PGPPublicKey(int algorithm, java.security.PublicKey pubKey, java.util.Date time, java.lang.String provider)` Create a PGPPublicKey from the passed in JCA one.

Method Summary
`static PGPPublicKey` `addCertification(PGPPublicKey key, PGPSignature certification)` Add a revocation or some other key certification to a key.
`static PGPPublicKey` `addCertification(PGPPublicKey key, PGPUserAttributeSubpacketVector userAttributes, PGPSignature certification)` Add a certification for the given UserAttributeSubpackets to the given public key.
`static PGPPublicKey` `addCertification(PGPPublicKey key, java.lang.String id, PGPSignature certification)` Add a certification for an id to the given public key.
`void` `encode(java.io.OutputStream outStream)`
`int` `getAlgorithm()` Return the algorithm code associated with the public key.
`int` `getBitStrength()` Return the strength of the key in bits.
`java.util.Date` `getCreationTime()`
`byte[]` `getEncoded()`
`byte[]` `getFingerprint()` Return the fingerprint of the key.
`java.security.PublicKey` `getKey(java.security.Provider provider)`
`java.security.PublicKey` `getKey(java.lang.String provider)` Return the public key contained in the object.
`long` `getKeyID()` Return the keyID associated with the public key.
`java.util.Iterator` `getSignatures()` Return all signatures/certifications associated with this key.
`java.util.Iterator` `getSignaturesForID(java.lang.String id)` Return any signatures associated with the passed in id.
`java.util.Iterator` `getSignaturesForUserAttribute(PGPUserAttributeSubpacketVector userAttributes)` Return an iterator of signatures associated with the passed in user attributes.
`java.util.Iterator` `getSignaturesOfType(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.
`java.util.Iterator` `getUserAttributes()` Return any user attribute vectors associated with the key.
`java.util.Iterator` `getUserIDs()` Return any userIDs associated with the key.
`int` `getValidDays()`
`long` `getValidSeconds()`
`int` `getVersion()`
`boolean` `isEncryptionKey()` Return true if this key has an algorithm type that makes it suitable to use for encryption.
`boolean` `isMasterKey()` Return true if this is a master key.
`boolean` `isRevoked()` Check whether this (sub)key has a revocation signature on it.
`static PGPPublicKey` `removeCertification(PGPPublicKey key, PGPSignature certification)` Remove a certification from the key.
`static PGPPublicKey` `removeCertification(PGPPublicKey key, PGPUserAttributeSubpacketVector userAttributes)` Remove any certifications associated with a given user attribute subpacket on a key.
`static PGPPublicKey` `removeCertification(PGPPublicKey key, PGPUserAttributeSubpacketVector userAttributes, PGPSignature certification)` Remove a certification associated with a given user attributes on a key.
`static PGPPublicKey` `removeCertification(PGPPublicKey key, java.lang.String id)` Remove any certifications associated with a given id on a key.
`static PGPPublicKey` `removeCertification(PGPPublicKey key, java.lang.String id, PGPSignature certification)` Remove a certification associated with a given id on a key.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### PGPPublicKey

    public PGPPublicKey(int algorithm,
                        java.security.PublicKey pubKey,
                        java.util.Date time,
                        java.lang.String provider)
                 throws PGPException,
                        java.security.NoSuchProviderException

  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.
    `java.security.NoSuchProviderException` - if the specified provider is required and cannot be found.

### PGPPublicKey

    public PGPPublicKey(int algorithm,
                        java.security.PublicKey pubKey,
                        java.util.Date time)
                 throws PGPException

Throws:
  `PGPException`

Method Detail

### getVersion

    public int getVersion()

  Returns:
    the version of this key.

### getCreationTime

    public java.util.Date getCreationTime()

  Returns:
    creation time of key.

### getValidDays

    public int getValidDays()

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

### getTrustData

    public byte[] getTrustData()

  Return the trust data associated with the public key, if present.

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

### getValidSeconds

    public long getValidSeconds()

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

### getKeyID

    public long getKeyID()

  Return the keyID associated with the public key.

  Returns:
    long

### getFingerprint

    public byte[] getFingerprint()

  Return the fingerprint of the key.

  Returns:
    key fingerprint.

### isEncryptionKey

    public boolean isEncryptionKey()

  Return true if this key has an algorithm type that makes it suitable to use for encryption.

  Note: with version 4 keys KeyFlags subpackets should also be considered when present for determining the preferred use of the key.

  Returns:
    true if the key algorithm is suitable for encryption.

### isMasterKey

    public boolean isMasterKey()

  Return true if this is a master key.

  Returns:
    true if a master key.

### 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.

### getKey

    public java.security.PublicKey getKey(java.lang.String provider)
                                   throws PGPException,
                                          java.security.NoSuchProviderException

  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.
    `java.security.NoSuchProviderException` - if the provider cannot be found.

### getKey

    public java.security.PublicKey getKey(java.security.Provider provider)
                                   throws PGPException

  Throws:
    `PGPException`

### getUserIDs

    public java.util.Iterator getUserIDs()

  Return any userIDs associated with the key.

  Returns:
    an iterator of Strings.

### getUserAttributes

    public java.util.Iterator getUserAttributes()

  Return any user attribute vectors associated with the key.

  Returns:
    an iterator of PGPUserAttributeSubpacketVector objects.

### getSignaturesForID

    public java.util.Iterator getSignaturesForID(java.lang.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 java.util.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 java.util.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.

### getSignatures

    public java.util.Iterator getSignatures()

  Return all signatures/certifications associated with this key.

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

### getEncoded

    public byte[] getEncoded()
                      throws java.io.IOException

  Throws:
    `java.io.IOException`

### encode

    public void encode(java.io.OutputStream outStream)
                throws java.io.IOException

  Throws:
    `java.io.IOException`

### 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.

### addCertification

    public static PGPPublicKey addCertification(PGPPublicKey key,
                                                java.lang.String id,
                                                PGPSignature certification)

  Add a certification for an id 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,
                                                PGPUserAttributeSubpacketVector userAttributes,
                                                PGPSignature certification)

  Add a certification for the given UserAttributeSubpackets to the given public key.

  Parameters:
    `key` - the key the certification is to be added to.
    `userAttributes` - the attributes the certification is associated with.
    `certification` - the new certification.
  Returns:
    the re-certified key.

### removeCertification

    public static PGPPublicKey removeCertification(PGPPublicKey key,
                                                   PGPUserAttributeSubpacketVector userAttributes)

  Remove any certifications associated with a given user attribute subpacket on a key.

  Parameters:
    `key` - the key the certifications are to be removed from.
    `userAttributes` - the attributes to be removed.
  Returns:
    the re-certified key, null if the user attribute subpacket was not found on the key.

### removeCertification

    public static PGPPublicKey removeCertification(PGPPublicKey key,
                                                   java.lang.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,
                                                   java.lang.String id,
                                                   PGPSignature certification)

  Remove a certification associated with a given id on a key.

  Parameters:
    `key` - the key the certifications are to be removed from.
    `id` - the id that the certification is to be removed from.
    `certification` - the certification to be removed.
  Returns:
    the re-certified key, null if the certification was not found.

### removeCertification

    public static PGPPublicKey removeCertification(PGPPublicKey key,
                                                   PGPUserAttributeSubpacketVector userAttributes,
                                                   PGPSignature certification)

  Remove a certification associated with a given user attributes on a key.

  Parameters:
    `key` - the key the certifications are to be removed from.
    `userAttributes` - the user attributes that the certification is to be removed from.
    `certification` - the certification to be removed.
  Returns:
    the re-certified key, null if the certification was not found.

### 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.

### removeCertification

    public static PGPPublicKey removeCertification(PGPPublicKey key,
                                                   PGPSignature certification)

  Remove a certification from the key.

  Parameters:
    `key` - the key the certifications are to be removed from.
    `certification` - the certification to be removed.
  Returns:
    the modified key, null if the certification was not found.

Bouncy Castle Cryptography Library 1.45