Top Description Fields Constructors Methods
org.bouncycastle.openpgp

public Class PGPSecretKeyRing

extends PGPKeyRing
implements Iterable<PGPSecretKey>
Class Inheritance
All Implemented Interfaces
org.bouncycastle.util.Iterable, java.lang.Iterable
Known Direct Subclasses
org.bouncycastle.openpgp.bc.BcPGPSecretKeyRing, org.bouncycastle.openpgp.jcajce.JcaPGPSecretKeyRing
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .EOFException, .IOException, .InputStream, .OutputStream, java.util.ArrayList, .Collections, .Iterator, .List, java.util.logging.Level, .Logger, org.bouncycastle.bcpg.ArmoredInputException, .BCPGInputStream, .BCPGOutputStream, .KeyIdentifier, .PacketFormat, .PacketTags, .PublicSubkeyPacket, .SecretKeyPacket, .SecretSubkeyPacket, .TrustPacket, .UserDataPacket, org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator, .PBESecretKeyDecryptor, .PBESecretKeyEncryptor, org.bouncycastle.util.Iterable

Class to hold a single master secret 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 PGPSecretKeyRingCollection class.

Field Summary

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

Constructor Summary

AccessConstructor and Description
public
PGPSecretKeyRing(List<PGPSecretKey>
the list of keys making up the ring.
secKeys
)

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

private
public
PGPSecretKeyRing(byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator)

public

Method Summary

Modifier and TypeMethod and Description
private static List<PGPSecretKey>
public static PGPSecretKeyRing

Returns:

the updated key ring.
copyWithNewPassword
(PGPSecretKeyRing
the PGPSecretKeyRing to be copied.
ring
,
PBESecretKeyDecryptor
the current decryptor based on the current password for key.
oldKeyDecryptor
,
PBESecretKeyEncryptor
a new encryptor based on a new password for encrypting the secret key material.
newKeyEncryptor
)

Return a copy of the passed in secret key ring, with the private keys (where present) associated with the master key and sub keys are encrypted using a new password and the passed in algorithm.

public void
public byte[]
public byte[]
public Iterator<PGPPublicKey>

Returns:

iterator of unattached, or extra, public keys.
getExtraPublicKeys
()

Return an iterator of the public keys in the secret key ring that have no matching private key.

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 Iterator<PGPPublicKey>
public PGPPublicKey

Returns:

PGPPublicKey
getPublicKey
()

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

Return the public key for the master key.

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 PGPPublicKey
public Iterator<PGPPublicKey>
public Iterator<PGPPublicKey>

Returns:

Iterator
getPublicKeys
()

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

Return an iterator containing all the public keys.

public PGPSecretKey
public PGPSecretKey

Returns:

PGPSecretKey
getSecretKey
()

Return the master private key.

public PGPSecretKey

Returns:

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

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

public PGPSecretKey

Returns:

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

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

public Iterator<PGPSecretKey>
public Iterator<PGPSecretKey>

Returns:

Iterator
getSecretKeys
()

Return an iterator containing all the secret keys.

public static PGPSecretKeyRing

Returns:

secret key ring
insertOrReplacePublicKey
(PGPSecretKeyRing
secret key ring
secretRing
,
PGPPublicKey
public key to insert or replace
publicKey
)

Either replace the public key on the corresponding secret key in the key ring if present, or insert the public key as an extra public key in case that the secret ring does not contain the corresponding secret key.

public static PGPSecretKeyRing

Returns:

a new secret key ring.
insertSecretKey
(PGPSecretKeyRing
the secret key ring to be modified.
secRing
,
PGPSecretKey
the secret key to be added.
secKey
)

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

public Iterator<PGPSecretKey>
iterator()

Implements org.bouncycastle.util.Iterable.iterator.

Support method for Iterable where available.

public static PGPSecretKeyRing

Returns:

a new secret key ring, or null if secKey is not found.
removeSecretKey
(PGPSecretKeyRing
the secret key ring to be modified.
secRing
,
PGPSecretKey
the secret key to be removed.
secKey
)

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

public static PGPSecretKeyRing
replacePublicKeys(PGPSecretKeyRing
secret ring to be changed.
secretRing
,
PGPPublicKeyRing
public ring containing the new public key set.
publicRing
)

Replace the public key set on the secret ring with the corresponding key off the public ring.

public int

Returns:

number of keys (master key + subkey).
size
()

Implements abstract org.bouncycastle.openpgp.PGPKeyRing.size.

Return the number of keys in the key ring.

public PGPPublicKeyRing

Returns:

certificate
toCertificate
()

Return the OpenPGP certificate (Transferable Public Key) of this key.

Inherited from org.bouncycastle.openpgp.PGPKeyRing:
readOptionalTrustPacketreadSignaturesAndTrustreadUserIDs

Field Detail

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

Hides org.bouncycastle.openpgp.PGPKeyRing.LOG.

Constructor Detail

PGPSecretKeyRingback to summary
public PGPSecretKeyRing(List<PGPSecretKey> secKeys)

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

Parameters
secKeys:List<PGPSecretKey>

the list of keys making up the ring.

PGPSecretKeyRingback to summary
private PGPSecretKeyRing(List<PGPSecretKey> keys, List<PGPPublicKey> extraPubKeys)
PGPSecretKeyRingback to summary
public PGPSecretKeyRing(byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException
PGPSecretKeyRingback to summary
public PGPSecretKeyRing(InputStream in, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException

Method Detail

checkKeysback to summary
private static List<PGPSecretKey> checkKeys(List<PGPSecretKey> keys)
copyWithNewPasswordback to summary
public static PGPSecretKeyRing copyWithNewPassword(PGPSecretKeyRing ring, PBESecretKeyDecryptor oldKeyDecryptor, PBESecretKeyEncryptor newKeyEncryptor) throws PGPException

Return a copy of the passed in secret key ring, with the private keys (where present) associated with the master key and sub keys are encrypted using a new password and the passed in algorithm.

Parameters
ring:PGPSecretKeyRing

the PGPSecretKeyRing to be copied.

oldKeyDecryptor:PBESecretKeyDecryptor

the current decryptor based on the current password for key.

newKeyEncryptor:PBESecretKeyEncryptor

a new encryptor based on a new password for encrypting the secret key material.

Returns:PGPSecretKeyRing

the updated key ring.

encodeback to summary
public void encode(OutputStream outStream) throws IOException

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

getEncodedback to summary
public byte[] getEncoded() throws IOException

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

getEncodedback to summary
public byte[] getEncoded(PacketFormat format) throws IOException

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

Annotations
@Override
getExtraPublicKeysback to summary
public Iterator<PGPPublicKey> getExtraPublicKeys()

Return an iterator of the public keys in the secret key ring that have no matching private key. At the moment only personal certificate data appears in this fashion.

Returns:Iterator<PGPPublicKey>

iterator of unattached, or extra, public keys.

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.

getKeysWithSignaturesByback to summary
public Iterator<PGPPublicKey> getKeysWithSignaturesBy(KeyIdentifier identifier)

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

Annotations
@Override
getPublicKeyback to summary
public PGPPublicKey getPublicKey()

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

Return the public key for the master key.

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.

getPublicKeyback to summary
public PGPPublicKey getPublicKey(KeyIdentifier identifier)

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

Annotations
@Override
getPublicKeysback to summary
public Iterator<PGPPublicKey> getPublicKeys(KeyIdentifier identifier)

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

Annotations
@Override
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

getSecretKeyback to summary
public PGPSecretKey getSecretKey(KeyIdentifier identifier)
getSecretKeyback to summary
public PGPSecretKey getSecretKey()

Return the master private key.

Returns:PGPSecretKey

PGPSecretKey

getSecretKeyback to summary
public PGPSecretKey getSecretKey(long keyID)

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

Parameters
keyID:long

the full keyID of the key of interest.

Returns:PGPSecretKey

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

getSecretKeyback to summary
public PGPSecretKey getSecretKey(byte[] fingerprint)

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

Parameters
fingerprint:byte[]

the full fingerprint of the key of interest.

Returns:PGPSecretKey

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

getSecretKeysback to summary
public Iterator<PGPSecretKey> getSecretKeys(KeyIdentifier identifier)
getSecretKeysback to summary
public Iterator<PGPSecretKey> getSecretKeys()

Return an iterator containing all the secret keys.

Returns:Iterator<PGPSecretKey>

Iterator

insertOrReplacePublicKeyback to summary
public static PGPSecretKeyRing insertOrReplacePublicKey(PGPSecretKeyRing secretRing, PGPPublicKey publicKey)

Either replace the public key on the corresponding secret key in the key ring if present, or insert the public key as an extra public key in case that the secret ring does not contain the corresponding secret key.

Parameters
secretRing:PGPSecretKeyRing

secret key ring

publicKey:PGPPublicKey

public key to insert or replace

Returns:PGPSecretKeyRing

secret key ring

insertSecretKeyback to summary
public static PGPSecretKeyRing insertSecretKey(PGPSecretKeyRing secRing, PGPSecretKey secKey)

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

Parameters
secRing:PGPSecretKeyRing

the secret key ring to be modified.

secKey:PGPSecretKey

the secret key to be added.

Returns:PGPSecretKeyRing

a new secret key ring.

iteratorback to summary
public Iterator<PGPSecretKey> iterator()

Implements org.bouncycastle.util.Iterable.iterator.

Support method for Iterable where available.

Returns:Iterator<PGPSecretKey>

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

an Iterator.

removeSecretKeyback to summary
public static PGPSecretKeyRing removeSecretKey(PGPSecretKeyRing secRing, PGPSecretKey secKey)

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

Parameters
secRing:PGPSecretKeyRing

the secret key ring to be modified.

secKey:PGPSecretKey

the secret key to be removed.

Returns:PGPSecretKeyRing

a new secret key ring, or null if secKey is not found.

replacePublicKeysback to summary
public static PGPSecretKeyRing replacePublicKeys(PGPSecretKeyRing secretRing, PGPPublicKeyRing publicRing)

Replace the public key set on the secret ring with the corresponding key off the public ring.

Parameters
secretRing:PGPSecretKeyRing

secret ring to be changed.

publicRing:PGPPublicKeyRing

public ring containing the new public key set.

sizeback to summary
public int size()

Implements abstract org.bouncycastle.openpgp.PGPKeyRing.size.

Return the number of keys in the key ring.

Returns:int

number of keys (master key + subkey).

toCertificateback to summary
public PGPPublicKeyRing toCertificate()

Return the OpenPGP certificate (Transferable Public Key) of this key.

Returns:PGPPublicKeyRing

certificate