Class PGPPublicKeyRing

  • All Implemented Interfaces:
    Iterable<PGPPublicKey>, org.bouncycastle.util.Iterable<PGPPublicKey>
    Direct Known Subclasses:
    BcPGPPublicKeyRing, JcaPGPPublicKeyRing

    public class PGPPublicKeyRing
    extends PGPKeyRing
    implements org.bouncycastle.util.Iterable<PGPPublicKey>
    Class to hold a single master public key and its subkeys.

    Often PGP keyring files consist of multiple master keys, if you are trying to process or construct one of these you should use the PGPPublicKeyRingCollection class.

    • Method Detail

      • getPublicKey

        public PGPPublicKey getPublicKey​(long keyID)
        Return the public key referred to by the passed in keyID if it is present.
        Specified by:
        getPublicKey in class PGPKeyRing
        Parameters:
        keyID - the full keyID of the key of interest.
        Returns:
        PGPPublicKey with matching keyID, null if it is not present.
      • getPublicKey

        public PGPPublicKey getPublicKey​(byte[] fingerprint)
        Return the public key with the passed in fingerprint if it is present.
        Specified by:
        getPublicKey in class PGPKeyRing
        Parameters:
        fingerprint - the full fingerprint of the key of interest.
        Returns:
        PGPPublicKey with the matching fingerprint, null if it is not present.
      • getKeysWithSignaturesBy

        public Iterator<PGPPublicKey> getKeysWithSignaturesBy​(long keyID)
        Return any keys carrying a signature issued by the key represented by keyID.
        Specified by:
        getKeysWithSignaturesBy in class PGPKeyRing
        Parameters:
        keyID - the key id to be matched against.
        Returns:
        an iterator (possibly empty) of PGPPublicKey objects carrying signatures from keyID.
      • getEncoded

        public byte[] getEncoded​(boolean forTransfer)
                          throws IOException
        Return an encoding of the key ring, with trust packets stripped out if forTransfer is true.
        Parameters:
        forTransfer - if the purpose of encoding is to send key to other users.
        Returns:
        a encoded byte array representing the key.
        Throws:
        IOException - in case of encoding error.
      • encode

        public void encode​(OutputStream outStream,
                           boolean forTransfer)
                    throws IOException
        Encode the key ring to outStream, with trust packets stripped out if forTransfer is true.
        Parameters:
        outStream - stream to write the key encoding to.
        forTransfer - if the purpose of encoding is to send key to other users.
        Throws:
        IOException - in case of encoding error.
      • insertPublicKey

        public static PGPPublicKeyRing insertPublicKey​(PGPPublicKeyRing pubRing,
                                                       PGPPublicKey pubKey)
        Returns a new key ring with the public key passed in either added or replacing an existing one.
        Parameters:
        pubRing - the public key ring to be modified
        pubKey - the public key to be inserted.
        Returns:
        a new keyRing
      • removePublicKey

        public static PGPPublicKeyRing removePublicKey​(PGPPublicKeyRing pubRing,
                                                       PGPPublicKey pubKey)
        Returns a new key ring with the public key passed in removed from the key ring.
        Parameters:
        pubRing - the public key ring to be modified
        pubKey - the public key to be removed.
        Returns:
        a new keyRing, null if pubKey is not found.