Package org.bouncycastle.openpgp
Class PGPSecretKeyRing
java.lang.Object
org.bouncycastle.openpgp.PGPKeyRing
org.bouncycastle.openpgp.PGPSecretKeyRing
- All Implemented Interfaces:
Iterable<PGPSecretKey>
,org.bouncycastle.util.Iterable<PGPSecretKey>
- Direct Known Subclasses:
BcPGPSecretKeyRing
,JcaPGPSecretKeyRing
public class PGPSecretKeyRing
extends PGPKeyRing
implements org.bouncycastle.util.Iterable<PGPSecretKey>
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.
-
Constructor Summary
ConstructorsConstructorDescriptionPGPSecretKeyRing
(byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator) PGPSecretKeyRing
(InputStream in, KeyFingerPrintCalculator fingerPrintCalculator) PGPSecretKeyRing
(List<PGPSecretKey> secKeys) Base constructor from a list of keys representing a secret key ring (a master key and its associated sub-keys). -
Method Summary
Modifier and TypeMethodDescriptionstatic PGPSecretKeyRing
copyWithNewPassword
(PGPSecretKeyRing ring, PBESecretKeyDecryptor oldKeyDecryptor, PBESecretKeyEncryptor 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.void
encode
(OutputStream outStream) byte[]
Return an iterator of the public keys in the secret key ring that have no matching private key.getKeysWithSignaturesBy
(long keyID) Return any keys carrying a signature issued by the key represented by keyID.Return the public key for the master key.getPublicKey
(byte[] fingerprint) Return the public key with the passed in fingerprint if it is present.getPublicKey
(long keyID) Return the public key referred to by the passed in keyID if it is present.Return an iterator containing all the public keys.Return the master private key.getSecretKey
(byte[] fingerprint) Return the secret key associated with the passed in fingerprint if it is present.getSecretKey
(long keyID) Return the secret key referred to by the passed in keyID if it is present.Return an iterator containing all the secret keys.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.iterator()
Support method for Iterable where available.static PGPSecretKeyRing
removeSecretKey
(PGPSecretKeyRing secRing, PGPSecretKey secKey) Returns a new key ring with the secret key passed in removed from the key ring.static PGPSecretKeyRing
replacePublicKeys
(PGPSecretKeyRing secretRing, PGPPublicKeyRing publicRing) Replace the public key set on the secret ring with the corresponding key off the public ring.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
-
PGPSecretKeyRing
Base constructor from a list of keys representing a secret key ring (a master key and its associated sub-keys).- Parameters:
secKeys
- the list of keys making up the ring.
-
PGPSecretKeyRing
public PGPSecretKeyRing(byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException - Throws:
IOException
PGPException
-
PGPSecretKeyRing
public PGPSecretKeyRing(InputStream in, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException - Throws:
IOException
PGPException
-
-
Method Details
-
getPublicKey
Return the public key for the master key.- Specified by:
getPublicKey
in classPGPKeyRing
- Returns:
- PGPPublicKey
-
getPublicKey
Return the public key referred to by the passed in keyID if it is present.- Specified by:
getPublicKey
in classPGPKeyRing
- Parameters:
keyID
- the full keyID of the key of interest.- Returns:
- PGPPublicKey with matching keyID, null if it is not present.
-
getPublicKey
Return the public key with the passed in fingerprint if it is present.- Specified by:
getPublicKey
in classPGPKeyRing
- Parameters:
fingerprint
- the full fingerprint of the key of interest.- Returns:
- PGPPublicKey with the matching fingerprint, null if it is not present.
-
getKeysWithSignaturesBy
Return any keys carrying a signature issued by the key represented by keyID.- Specified by:
getKeysWithSignaturesBy
in classPGPKeyRing
- Parameters:
keyID
- the key id to be matched against.- Returns:
- an iterator (possibly empty) of PGPPublicKey objects carrying signatures from keyID.
-
getPublicKeys
Return an iterator containing all the public keys.- Specified by:
getPublicKeys
in classPGPKeyRing
- Returns:
- Iterator
-
getSecretKey
Return the master private key.- Returns:
- PGPSecretKey
-
getSecretKeys
Return an iterator containing all the secret keys.- Returns:
- Iterator
-
getSecretKey
Return the secret key referred to by the passed in keyID if it is present.- Parameters:
keyID
- the full keyID of the key of interest.- Returns:
- PGPSecretKey with matching keyID, null if it is not present.
-
getSecretKey
Return the secret key associated with the passed in fingerprint if it is present.- Parameters:
fingerprint
- the full fingerprint of the key of interest.- Returns:
- PGPSecretKey with the matching fingerprint, null if it is not present.
-
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 of unattached, or extra, public keys.
-
getEncoded
- Specified by:
getEncoded
in classPGPKeyRing
- Throws:
IOException
-
encode
- Specified by:
encode
in classPGPKeyRing
- Throws:
IOException
-
iterator
Support method for Iterable where available.- Specified by:
iterator
in interfaceIterable<PGPSecretKey>
- Specified by:
iterator
in interfaceorg.bouncycastle.util.Iterable<PGPSecretKey>
-
replacePublicKeys
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
- secret ring to be changed.publicRing
- public ring containing the new public key set.
-
copyWithNewPassword
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
- the PGPSecretKeyRing to be copied.oldKeyDecryptor
- the current decryptor based on the current password for key.newKeyEncryptor
- a new encryptor based on a new password for encrypting the secret key material.- Returns:
- the updated key ring.
- Throws:
PGPException
-
insertSecretKey
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
- the secret key ring to be modified.secKey
- the secret key to be added.- Returns:
- a new secret key ring.
-
removeSecretKey
Returns a new key ring with the secret key passed in removed from the key ring.- Parameters:
secRing
- the secret key ring to be modified.secKey
- the secret key to be removed.- Returns:
- a new secret key ring, or null if secKey is not found.
-