org.bouncycastle.openpgp

Class PGPSecretKeyRingCollection


public class PGPSecretKeyRingCollection
extends java.lang.Object

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

PGPSecretKeyRingCollection(Collection collection)
PGPSecretKeyRingCollection(InputStream in)
Build a PGPSecretKeyRingCollection from the passed in input stream.
PGPSecretKeyRingCollection(byte[] encoding)

Method Summary

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.
void
encode(OutputStream outStream)
byte[]
getEncoded()
Iterator
getKeyRings()
return the secret key rings making up this collection.
Iterator
getKeyRings(String userID)
Return an iterator of the key rings associated with the passed in userID.
Iterator
getKeyRings(String userID, boolean matchPartial)
Return an iterator of the key rings associated with the passed in userID.
Iterator
getKeyRings(String userID, boolean matchPartial, boolean ignoreCase)
Return an iterator of the key rings associated with the passed in userID.
PGPSecretKey
getSecretKey(long keyID)
Return the PGP secret key associated with the given key id.
PGPSecretKeyRing
getSecretKeyRing(long keyID)
Return the secret key ring which contains the key referred to by keyID.
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.

Constructor Details

PGPSecretKeyRingCollection

public PGPSecretKeyRingCollection(Collection collection)
            throws IOException,
                   PGPException

PGPSecretKeyRingCollection

public PGPSecretKeyRingCollection(InputStream in)
            throws IOException,
                   PGPException
Build a PGPSecretKeyRingCollection from the passed in input stream.
Parameters:
in - input stream containing data
Throws:
PGPException - if an object is encountered which isn't a PGPSecretKeyRing

PGPSecretKeyRingCollection

public PGPSecretKeyRingCollection(byte[] encoding)
            throws IOException,
                   PGPException

Method Details

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.

encode

public void encode(OutputStream outStream)
            throws IOException

getEncoded

public byte[] getEncoded()
            throws IOException

getKeyRings

public Iterator getKeyRings()
return the secret key rings making up this collection.

getKeyRings

public Iterator getKeyRings(String userID)
            throws PGPException
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.
Throws:
PGPException -

getKeyRings

public Iterator getKeyRings(String userID,
                            boolean matchPartial)
            throws PGPException
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.
Throws:
PGPException -

getKeyRings

public Iterator getKeyRings(String userID,
                            boolean matchPartial,
                            boolean ignoreCase)
            throws PGPException
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.
Throws:
PGPException -

getSecretKey

public PGPSecretKey getSecretKey(long keyID)
            throws PGPException
Return the PGP secret key associated with the given key id.
Parameters:
keyID -
Returns:
the secret key
Throws:
PGPException -

getSecretKeyRing

public PGPSecretKeyRing getSecretKeyRing(long keyID)
            throws PGPException
Return the secret key ring which contains the key referred to by keyID.
Parameters:
keyID -
Returns:
the secret key ring
Throws:
PGPException -

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.

size

public int size()
Return the number of rings in this collection.
Returns:
size of the collection