Package org.bouncycastle.openpgp
Class PGPSecretKeyRingCollection
java.lang.Object
org.bouncycastle.openpgp.PGPSecretKeyRingCollection
- All Implemented Interfaces:
Iterable<PGPSecretKeyRing>
,org.bouncycastle.util.Iterable<PGPSecretKeyRing>
- Direct Known Subclasses:
BcPGPSecretKeyRingCollection
,JcaPGPSecretKeyRingCollection
public class PGPSecretKeyRingCollection
extends Object
implements org.bouncycastle.util.Iterable<PGPSecretKeyRing>
Often a PGP key ring file is made up of a succession of master/sub-key key rings.
If you want to read an entire secret key file in one hit this is the class for you.
-
Constructor Summary
ConstructorDescriptionPGPSecretKeyRingCollection
(byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator) PGPSecretKeyRingCollection
(InputStream in, KeyFingerPrintCalculator fingerPrintCalculator) Build a PGPSecretKeyRingCollection from the passed in input stream.PGPSecretKeyRingCollection
(Collection<PGPSecretKeyRing> collection) -
Method Summary
Modifier and TypeMethodDescriptionstatic PGPSecretKeyRingCollection
addSecretKeyRing
(PGPSecretKeyRingCollection ringCollection, PGPSecretKeyRing secretKeyRing) Return a new collection object containing the contents of the passed in collection and the passed in secret key ring.boolean
contains
(long keyID) Return true if a key matching the passed in key ID is present, false otherwise.void
encode
(OutputStream outStream) byte[]
return the secret key rings making up this collection.getKeyRings
(String userID) Return an iterator of the key rings associated with the passed in userID.getKeyRings
(String userID, boolean matchPartial) Return an iterator of the key rings associated with the passed in userID.getKeyRings
(String userID, boolean matchPartial, boolean ignoreCase) Return an iterator of the key rings associated with the passed in userID.getSecretKey
(long keyID) Return the PGP secret key associated with the given key id.getSecretKeyRing
(long keyID) Return the secret key ring which contains the key referred to by keyID.iterator()
Support method for Iterable where available.static PGPSecretKeyRingCollection
removeSecretKeyRing
(PGPSecretKeyRingCollection ringCollection, PGPSecretKeyRing secretKeyRing) Return a new collection object containing the contents of this collection with the passed in secret key ring removed.int
size()
Return the number of rings in this collection.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
-
PGPSecretKeyRingCollection
public PGPSecretKeyRingCollection(byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException - Throws:
IOException
PGPException
-
PGPSecretKeyRingCollection
public PGPSecretKeyRingCollection(InputStream in, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException Build a PGPSecretKeyRingCollection from the passed in input stream.- Parameters:
in
- input stream containing data- Throws:
IOException
- if a problem parsing the base stream occursPGPException
- if an object is encountered which isn't a PGPSecretKeyRing
-
PGPSecretKeyRingCollection
-
-
Method Details
-
size
public int size()Return the number of rings in this collection.- Returns:
- size of the collection
-
getKeyRings
return the secret key rings making up this collection. -
getKeyRings
Return an iterator of the key rings associated with the passed in userID.- Parameters:
userID
- the user ID to be matched.- Returns:
- an iterator (possibly empty) of key rings which matched.
-
getKeyRings
Return an iterator of the key rings associated with the passed in userID.- Parameters:
userID
- the user ID to be matched.matchPartial
- if true userID need only be a substring of an actual ID string to match.- Returns:
- an iterator (possibly empty) of key rings which matched.
-
getKeyRings
public Iterator<PGPSecretKeyRing> getKeyRings(String userID, boolean matchPartial, boolean ignoreCase) Return an iterator of the key rings associated with the passed in userID.- Parameters:
userID
- the user ID to be matched.matchPartial
- if true userID need only be a substring of an actual ID string to match.ignoreCase
- if true case is ignored in user ID comparisons.- Returns:
- an iterator (possibly empty) of key rings which matched.
-
getSecretKey
Return the PGP secret key associated with the given key id.- Parameters:
keyID
- id of the secret key- Returns:
- the secret key
-
getSecretKeyRing
Return the secret key ring which contains the key referred to by keyID.- Parameters:
keyID
- id of a secret key- Returns:
- the secret key ring
-
contains
public boolean contains(long keyID) Return true if a key matching the passed in key ID is present, false otherwise.- Parameters:
keyID
- key ID to look for.- Returns:
- true if keyID present, false otherwise.
-
getEncoded
- Throws:
IOException
-
encode
- Throws:
IOException
-
addSecretKeyRing
public static PGPSecretKeyRingCollection addSecretKeyRing(PGPSecretKeyRingCollection ringCollection, PGPSecretKeyRing secretKeyRing) Return a new collection object containing the contents of the passed in collection and the passed in secret key ring.- Parameters:
ringCollection
- the collection the ring to be added to.secretKeyRing
- the key ring to be added.- Returns:
- a new collection merging the current one with the passed in ring.
- Throws:
IllegalArgumentException
- if the keyID for the passed in ring is already present.
-
removeSecretKeyRing
public static PGPSecretKeyRingCollection removeSecretKeyRing(PGPSecretKeyRingCollection ringCollection, PGPSecretKeyRing secretKeyRing) Return a new collection object containing the contents of this collection with the passed in secret key ring removed.- Parameters:
ringCollection
- the collection the ring to be removed from.secretKeyRing
- the key ring to be removed.- Returns:
- a new collection merging the current one with the passed in ring.
- Throws:
IllegalArgumentException
- if the keyID for the passed in ring is not present.
-
iterator
Support method for Iterable where available.- Specified by:
iterator
in interfaceIterable<PGPSecretKeyRing>
- Specified by:
iterator
in interfaceorg.bouncycastle.util.Iterable<PGPSecretKeyRing>
-