Package org.bouncycastle.openpgp
Class PGPPublicKeyRing
java.lang.Object
org.bouncycastle.openpgp.PGPKeyRing
org.bouncycastle.openpgp.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.
-
Constructor Summary
ConstructorsConstructorDescriptionPGPPublicKeyRing
(byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator) PGPPublicKeyRing
(InputStream in, KeyFingerPrintCalculator fingerPrintCalculator) PGPPublicKeyRing
(List<PGPPublicKey> pubKeys) Base constructor from a list of keys representing a public key ring (a master key and its associated sub-keys). -
Method Summary
Modifier and TypeMethodDescriptionvoid
encode
(OutputStream outStream) void
encode
(OutputStream outStream, boolean forTransfer) Encode the key ring to outStream, with trust packets stripped out if forTransfer is true.byte[]
byte[]
getEncoded
(boolean forTransfer) Return an encoding of the key ring, with trust packets stripped out if forTransfer is true.getKeysWithSignaturesBy
(long keyID) Return any keys carrying a signature issued by the key represented by keyID.Return the first public key in the ring.getPublicKey
(byte[] fingerprint) Return the public key with the passed in fingerprint if it is present.getPublicKey
(long keyID) Return the public key referred to by the passed in keyID if it is present.Return an iterator containing all the public keys.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.iterator()
Support method for Iterable where available.static PGPPublicKeyRing
removePublicKey
(PGPPublicKeyRing pubRing, PGPPublicKey pubKey) Returns a new key ring with the public key passed in removed from the key ring.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
PGPPublicKeyRing
public PGPPublicKeyRing(byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException - Throws:
IOException
-
PGPPublicKeyRing
Base constructor from a list of keys representing a public key ring (a master key and its associated sub-keys).- Parameters:
pubKeys
- the list of keys making up the ring.
-
PGPPublicKeyRing
public PGPPublicKeyRing(InputStream in, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException - Throws:
IOException
-
-
Method Details
-
getPublicKey
Return the first public key in the ring.- Specified by:
getPublicKey
in classPGPKeyRing
- Returns:
- PGPPublicKey
-
getPublicKey
Return the public key referred to by the passed in keyID if it is present.- Specified by:
getPublicKey
in classPGPKeyRing
- Parameters:
keyID
- the full keyID of the key of interest.- Returns:
- PGPPublicKey with matching keyID, null if it is not present.
-
getPublicKey
Return the public key with the passed in fingerprint if it is present.- Specified by:
getPublicKey
in classPGPKeyRing
- Parameters:
fingerprint
- the full fingerprint of the key of interest.- Returns:
- PGPPublicKey with the matching fingerprint, null if it is not present.
-
getKeysWithSignaturesBy
Return any keys carrying a signature issued by the key represented by keyID.- Specified by:
getKeysWithSignaturesBy
in classPGPKeyRing
- Parameters:
keyID
- the key id to be matched against.- Returns:
- an iterator (possibly empty) of PGPPublicKey objects carrying signatures from keyID.
-
getPublicKeys
Return an iterator containing all the public keys.- Specified by:
getPublicKeys
in classPGPKeyRing
- Returns:
- Iterator
-
iterator
Support method for Iterable where available.- Specified by:
iterator
in interfaceIterable<PGPPublicKey>
- Specified by:
iterator
in interfaceorg.bouncycastle.util.Iterable<PGPPublicKey>
-
getEncoded
- Specified by:
getEncoded
in classPGPKeyRing
- Throws:
IOException
-
getEncoded
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
- Specified by:
encode
in classPGPKeyRing
- Throws:
IOException
-
encode
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
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 modifiedpubKey
- the public key to be inserted.- Returns:
- a new keyRing
-
removePublicKey
Returns a new key ring with the public key passed in removed from the key ring.- Parameters:
pubRing
- the public key ring to be modifiedpubKey
- the public key to be removed.- Returns:
- a new keyRing, null if pubKey is not found.
-