Top Description Fields Constructors Methods
org.bouncycastle.openpgp

public Class PGPPublicKeyRing

extends PGPKeyRing
implements Iterable<PGPPublicKey>
Class Inheritance
All Implemented Interfaces
org.bouncycastle.util.Iterable, java.lang.Iterable
Known Direct Subclasses
org.bouncycastle.openpgp.jcajce.JcaPGPPublicKeyRing
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .InputStream, .OutputStream, java.util.ArrayList, .Collections, .HashSet, .Iterator, .List, .Set, java.util.logging.Level, .Logger, org.bouncycastle.bcpg.BCPGInputStream, .Packet, .PacketTags, .PublicKeyPacket, .TrustPacket, .UserDataPacket, org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator, org.bouncycastle.util.Arrays, .Iterable

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.

Field Summary

Modifier and TypeField and Description
pack-priv List<PGPPublicKey>
private static final Logger

Constructor Summary

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

public
PGPPublicKeyRing(List<PGPPublicKey>
the list of keys making up the ring.
pubKeys
)

Base constructor from a list of keys representing a public key ring (a master key and its associated sub-keys).

public

Method Summary

Modifier and TypeMethod and Description
private static List<PGPPublicKey>
public void
public void
encode(OutputStream
stream to write the key encoding to.
outStream
,
boolean
if the purpose of encoding is to send key to other users.
forTransfer
)

Encode the key ring to outStream, with trust packets stripped out if forTransfer is true.

public byte[]
public byte[]

Returns:

a encoded byte array representing the key.
getEncoded
(boolean
if the purpose of encoding is to send key to other users.
forTransfer
)

Return an encoding of the key ring, with trust packets stripped out if forTransfer is true.

public Iterator<PGPPublicKey>

Returns:

an iterator (possibly empty) of PGPPublicKey objects carrying signatures from keyID.
getKeysWithSignaturesBy
(long
the key id to be matched against.
keyID
)

Implements abstract org.bouncycastle.openpgp.PGPKeyRing.getKeysWithSignaturesBy.

Return any keys carrying a signature issued by the key represented by keyID.
public PGPPublicKey

Returns:

PGPPublicKey
getPublicKey
()

Implements abstract org.bouncycastle.openpgp.PGPKeyRing.getPublicKey.

Return the first public key in the ring.
public PGPPublicKey

Returns:

PGPPublicKey with matching keyID, null if it is not present.
getPublicKey
(long
the full keyID of the key of interest.
keyID
)

Implements abstract org.bouncycastle.openpgp.PGPKeyRing.getPublicKey.

Return the public key referred to by the passed in keyID if it is present.
public PGPPublicKey

Returns:

PGPPublicKey with the matching fingerprint, null if it is not present.
getPublicKey
(byte[]
the full fingerprint of the key of interest.
fingerprint
)

Implements abstract org.bouncycastle.openpgp.PGPKeyRing.getPublicKey.

Return the public key with the passed in fingerprint if it is present.
public Iterator<PGPPublicKey>

Returns:

Iterator
getPublicKeys
()

Implements abstract org.bouncycastle.openpgp.PGPKeyRing.getPublicKeys.

Return an iterator containing all the public keys.
public static PGPPublicKeyRing

Returns:

a new keyRing
insertPublicKey
(PGPPublicKeyRing
the public key ring to be modified
pubRing
,
PGPPublicKey
the public key to be inserted.
pubKey
)

Returns a new key ring with the public key passed in either added or replacing an existing one.

public Iterator<PGPPublicKey>
iterator()

Implements org.bouncycastle.util.Iterable.iterator.

Support method for Iterable where available.
public static PGPPublicKeyRing

Returns:

joined key ring
join
(PGPPublicKeyRing
local copy of the certificate
first
,
PGPPublicKeyRing
remote copy of the certificate (e.g. from a key server)
second
)

Join two copies of the same certificate.

public static PGPPublicKeyRing

Returns:

joined certificate
join
(PGPPublicKeyRing
local copy of the certificate
first
,
PGPPublicKeyRing
remote copy of the certificate (e.g. from a key server)
second
,
boolean
if true, trust packets from the second certificate copy will be carried over into the joined certificate
joinTrustPackets
,
boolean
if true, the resulting joined certificate may carry subkey signatures on its primary key
allowSubkeySigsOnNonSubkey
)

Join two copies of the same certificate.

pack-priv static PublicKeyPacket
pack-priv static PGPPublicKey
public static PGPPublicKeyRing

Returns:

a new keyRing, null if pubKey is not found.
removePublicKey
(PGPPublicKeyRing
the public key ring to be modified
pubRing
,
PGPPublicKey
the public key to be removed.
pubKey
)

Returns a new key ring with the public key passed in removed from the key ring.

Inherited from org.bouncycastle.openpgp.PGPKeyRing:
readOptionalTrustPacketreadSignaturesAndTrustreadUserIDs

Field Detail

keysback to summary
pack-priv List<PGPPublicKey> keys
LOGback to summary
private static final Logger LOG

Hides org.bouncycastle.openpgp.PGPKeyRing.LOG.

Constructor Detail

PGPPublicKeyRingback to summary
public PGPPublicKeyRing(byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException
PGPPublicKeyRingback to summary
public PGPPublicKeyRing(List<PGPPublicKey> pubKeys)

Base constructor from a list of keys representing a public key ring (a master key and its associated sub-keys).

Parameters
pubKeys:List<PGPPublicKey>

the list of keys making up the ring.

PGPPublicKeyRingback to summary
public PGPPublicKeyRing(InputStream in, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException

Method Detail

checkKeysback to summary
private static List<PGPPublicKey> checkKeys(List<PGPPublicKey> keys)
encodeback to summary
public void encode(OutputStream outStream) throws IOException

Implements abstract org.bouncycastle.openpgp.PGPKeyRing.encode.

encodeback to summary
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:OutputStream

stream to write the key encoding to.

forTransfer:boolean

if the purpose of encoding is to send key to other users.

Exceptions
IOException:
in case of encoding error.
getEncodedback to summary
public byte[] getEncoded() throws IOException

Implements abstract org.bouncycastle.openpgp.PGPKeyRing.getEncoded.

getEncodedback to summary
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:boolean

if the purpose of encoding is to send key to other users.

Returns:byte[]

a encoded byte array representing the key.

Exceptions
IOException:
in case of encoding error.
getKeysWithSignaturesByback to summary
public Iterator<PGPPublicKey> getKeysWithSignaturesBy(long keyID)

Implements abstract org.bouncycastle.openpgp.PGPKeyRing.getKeysWithSignaturesBy.

Return any keys carrying a signature issued by the key represented by keyID.

Parameters
keyID:long

the key id to be matched against.

Returns:Iterator<PGPPublicKey>

an iterator (possibly empty) of PGPPublicKey objects carrying signatures from keyID.

getPublicKeyback to summary
public PGPPublicKey getPublicKey()

Implements abstract org.bouncycastle.openpgp.PGPKeyRing.getPublicKey.

Return the first public key in the ring.

Returns:PGPPublicKey

PGPPublicKey

getPublicKeyback to summary
public PGPPublicKey getPublicKey(long keyID)

Implements abstract org.bouncycastle.openpgp.PGPKeyRing.getPublicKey.

Return the public key referred to by the passed in keyID if it is present.

Parameters
keyID:long

the full keyID of the key of interest.

Returns:PGPPublicKey

PGPPublicKey with matching keyID, null if it is not present.

getPublicKeyback to summary
public PGPPublicKey getPublicKey(byte[] fingerprint)

Implements abstract org.bouncycastle.openpgp.PGPKeyRing.getPublicKey.

Return the public key with the passed in fingerprint if it is present.

Parameters
fingerprint:byte[]

the full fingerprint of the key of interest.

Returns:PGPPublicKey

PGPPublicKey with the matching fingerprint, null if it is not present.

getPublicKeysback to summary
public Iterator<PGPPublicKey> getPublicKeys()

Implements abstract org.bouncycastle.openpgp.PGPKeyRing.getPublicKeys.

Return an iterator containing all the public keys.

Returns:Iterator<PGPPublicKey>

Iterator

insertPublicKeyback to summary
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:PGPPublicKeyRing

the public key ring to be modified

pubKey:PGPPublicKey

the public key to be inserted.

Returns:PGPPublicKeyRing

a new keyRing

iteratorback to summary
public Iterator<PGPPublicKey> iterator()

Implements org.bouncycastle.util.Iterable.iterator.

Support method for Iterable where available.

Returns:Iterator<PGPPublicKey>

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

an Iterator.

joinback to summary
public static PGPPublicKeyRing join(PGPPublicKeyRing first, PGPPublicKeyRing second) throws PGPException

Join two copies of the same certificate. The certificates must have the same primary key, but may carry different subkeys, user-ids and signatures. The resulting certificate will carry the sum of both certificates subkeys, user-ids and signatures.

This method will ignore trust packets on the second copy of the certificate and instead copy the local certificate's trust packets to the joined certificate.

Parameters
first:PGPPublicKeyRing

local copy of the certificate

second:PGPPublicKeyRing

remote copy of the certificate (e.g. from a key server)

Returns:PGPPublicKeyRing

joined key ring

joinback to summary
public static PGPPublicKeyRing join(PGPPublicKeyRing first, PGPPublicKeyRing second, boolean joinTrustPackets, boolean allowSubkeySigsOnNonSubkey) throws PGPException

Join two copies of the same certificate. The certificates must have the same primary key, but may carry different subkeys, user-ids and signatures. The resulting certificate will carry the sum of both certificates subkeys, user-ids and signatures.

For each subkey holds: If joinTrustPackets is set to true and the second key is carrying a trust packet, the trust packet will be copied to the joined key. Otherwise, the joined key will carry the trust packet of the local copy.

Parameters
first:PGPPublicKeyRing

local copy of the certificate

second:PGPPublicKeyRing

remote copy of the certificate (e.g. from a key server)

joinTrustPackets:boolean

if true, trust packets from the second certificate copy will be carried over into the joined certificate

allowSubkeySigsOnNonSubkey:boolean

if true, the resulting joined certificate may carry subkey signatures on its primary key

Returns:PGPPublicKeyRing

joined certificate

readPublicKeyPacketback to summary
pack-priv static PublicKeyPacket readPublicKeyPacket(BCPGInputStream in) throws IOException
readSubkeyback to summary
pack-priv static PGPPublicKey readSubkey(BCPGInputStream in, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException
removePublicKeyback to summary
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:PGPPublicKeyRing

the public key ring to be modified

pubKey:PGPPublicKey

the public key to be removed.

Returns:PGPPublicKeyRing

a new keyRing, null if pubKey is not found.