Top Description Fields Constructors Methods
org.bouncycastle.openpgp

public Class PGPSecretKeyRingCollection

extends Object
implements Iterable<PGPSecretKeyRing>
Class Inheritance
All Implemented Interfaces
org.bouncycastle.util.Iterable, java.lang.Iterable
Known Direct Subclasses
org.bouncycastle.openpgp.jcajce.JcaPGPSecretKeyRingCollection
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .InputStream, .OutputStream, java.util.ArrayList, .Collection, .HashMap, .Iterator, .List, .Map, org.bouncycastle.bcpg.BCPGOutputStream, org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator, org.bouncycastle.util.Iterable, .Strings

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.

Field Summary

Modifier and TypeField and Description
private List<Long>
private Map<Long, PGPSecretKeyRing>

Constructor Summary

AccessConstructor and Description
private
public
PGPSecretKeyRingCollection(byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator)

public
PGPSecretKeyRingCollection(InputStream
input stream containing data
in
,
KeyFingerPrintCalculator fingerPrintCalculator)

Build a PGPSecretKeyRingCollection from the passed in input stream.

public

Method Summary

Modifier and TypeMethod and Description
public static PGPSecretKeyRingCollection

Returns:

a new collection merging the current one with the passed in ring.
addSecretKeyRing
(PGPSecretKeyRingCollection
the collection the ring to be added to.
ringCollection
,
PGPSecretKeyRing
the key ring to be added.
secretKeyRing
)

Return a new collection object containing the contents of the passed in collection and the passed in secret key ring.

public boolean

Returns:

true if keyID present, false otherwise.
contains
(long
key ID to look for.
keyID
)

Return true if a key matching the passed in key ID is present, false otherwise.

public void
encode(OutputStream outStream)

public byte[]
public Iterator<PGPSecretKeyRing>
getKeyRings()

return the secret key rings making up this collection.

public Iterator<PGPSecretKeyRing>

Returns:

an iterator (possibly empty) of key rings which matched.
getKeyRings
(String
the user ID to be matched.
userID
)

Return an iterator of the key rings associated with the passed in userID.

public Iterator<PGPSecretKeyRing>

Returns:

an iterator (possibly empty) of key rings which matched.
getKeyRings
(String
the user ID to be matched.
userID
,
boolean
if true userID need only be a substring of an actual ID string to match.
matchPartial
)

Return an iterator of the key rings associated with the passed in userID.

public Iterator<PGPSecretKeyRing>

Returns:

an iterator (possibly empty) of key rings which matched.
getKeyRings
(String
the user ID to be matched.
userID
,
boolean
if true userID need only be a substring of an actual ID string to match.
matchPartial
,
boolean
if true case is ignored in user ID comparisons.
ignoreCase
)

Return an iterator of the key rings associated with the passed in userID.

public PGPSecretKey

Returns:

the secret key
getSecretKey
(long
id of the secret key
keyID
)

Return the PGP secret key associated with the given key id.

public PGPSecretKeyRing

Returns:

the secret key ring
getSecretKeyRing
(long
id of a secret key
keyID
)

Return the secret key ring which contains the key referred to by keyID.

public Iterator<PGPSecretKeyRing>
iterator()

Implements org.bouncycastle.util.Iterable.iterator.

Support method for Iterable where available.
public static PGPSecretKeyRingCollection

Returns:

a new collection merging the current one with the passed in ring.
removeSecretKeyRing
(PGPSecretKeyRingCollection
the collection the ring to be removed from.
ringCollection
,
PGPSecretKeyRing
the key ring to be removed.
secretKeyRing
)

Return a new collection object containing the contents of this collection with the passed in secret key ring removed.

public int

Returns:

size of the collection
size
()

Return the number of rings in this collection.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

orderback to summary
private List<Long> order
secretRingsback to summary
private Map<Long, PGPSecretKeyRing> secretRings

Constructor Detail

PGPSecretKeyRingCollectionback to summary
private PGPSecretKeyRingCollection(Map<Long, PGPSecretKeyRing> secretRings, List<Long> order)
PGPSecretKeyRingCollectionback to summary
public PGPSecretKeyRingCollection(byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException
PGPSecretKeyRingCollectionback to summary
public PGPSecretKeyRingCollection(InputStream in, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException

Build a PGPSecretKeyRingCollection from the passed in input stream.

Parameters
in:InputStream

input stream containing data

Exceptions
IOException:
if a problem parsing the base stream occurs
PGPException:
if an object is encountered which isn't a PGPSecretKeyRing
PGPSecretKeyRingCollectionback to summary
public PGPSecretKeyRingCollection(Collection<PGPSecretKeyRing> collection)

Method Detail

addSecretKeyRingback to summary
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:PGPSecretKeyRingCollection

the collection the ring to be added to.

secretKeyRing:PGPSecretKeyRing

the key ring to be added.

Returns:PGPSecretKeyRingCollection

a new collection merging the current one with the passed in ring.

Exceptions
IllegalArgumentException:
if the keyID for the passed in ring is already present.
containsback to summary
public boolean contains(long keyID)

Return true if a key matching the passed in key ID is present, false otherwise.

Parameters
keyID:long

key ID to look for.

Returns:boolean

true if keyID present, false otherwise.

encodeback to summary
public void encode(OutputStream outStream) throws IOException
getEncodedback to summary
public byte[] getEncoded() throws IOException
getKeyRingsback to summary
public Iterator<PGPSecretKeyRing> getKeyRings()

return the secret key rings making up this collection.

getKeyRingsback to summary
public Iterator<PGPSecretKeyRing> getKeyRings(String userID)

Return an iterator of the key rings associated with the passed in userID.

Parameters
userID:String

the user ID to be matched.

Returns:Iterator<PGPSecretKeyRing>

an iterator (possibly empty) of key rings which matched.

getKeyRingsback to summary
public Iterator<PGPSecretKeyRing> getKeyRings(String userID, boolean matchPartial)

Return an iterator of the key rings associated with the passed in userID.

Parameters
userID:String

the user ID to be matched.

matchPartial:boolean

if true userID need only be a substring of an actual ID string to match.

Returns:Iterator<PGPSecretKeyRing>

an iterator (possibly empty) of key rings which matched.

getKeyRingsback to summary
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:String

the user ID to be matched.

matchPartial:boolean

if true userID need only be a substring of an actual ID string to match.

ignoreCase:boolean

if true case is ignored in user ID comparisons.

Returns:Iterator<PGPSecretKeyRing>

an iterator (possibly empty) of key rings which matched.

getSecretKeyback to summary
public PGPSecretKey getSecretKey(long keyID)

Return the PGP secret key associated with the given key id.

Parameters
keyID:long

id of the secret key

Returns:PGPSecretKey

the secret key

getSecretKeyRingback to summary
public PGPSecretKeyRing getSecretKeyRing(long keyID)

Return the secret key ring which contains the key referred to by keyID.

Parameters
keyID:long

id of a secret key

Returns:PGPSecretKeyRing

the secret key ring

iteratorback to summary
public Iterator<PGPSecretKeyRing> iterator()

Implements org.bouncycastle.util.Iterable.iterator.

Support method for Iterable where available.

Returns:Iterator<PGPSecretKeyRing>

Doc from org.bouncycastle.util.Iterable.iterator.

an Iterator.

removeSecretKeyRingback to summary
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:PGPSecretKeyRingCollection

the collection the ring to be removed from.

secretKeyRing:PGPSecretKeyRing

the key ring to be removed.

Returns:PGPSecretKeyRingCollection

a new collection merging the current one with the passed in ring.

Exceptions
IllegalArgumentException:
if the keyID for the passed in ring is not present.
sizeback to summary
public int size()

Return the number of rings in this collection.

Returns:int

size of the collection