Table of Contents

Class PgpSecretKeyRing

Namespace
Org.BouncyCastle.Bcpg.OpenPgp
Assembly
BouncyCastle.Cryptography.dll
public class PgpSecretKeyRing : PgpKeyRing
Inheritance
PgpSecretKeyRing
Inherited Members

Remarks

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 PgpSecretKeyRingBundle class.

Constructors

PgpSecretKeyRing(byte[])

public PgpSecretKeyRing(byte[] encoding)

Parameters

encoding byte[]

PgpSecretKeyRing(Stream)

public PgpSecretKeyRing(Stream inputStream)

Parameters

inputStream Stream

Methods

CopyWithNewPassword(PgpSecretKeyRing, char[], char[], SymmetricKeyAlgorithmTag, SecureRandom)

Return a copy of the passed in secret key ring, with the master key and sub keys encrypted using a new password and the passed in algorithm.

public static PgpSecretKeyRing CopyWithNewPassword(PgpSecretKeyRing ring, char[] oldPassPhrase, char[] newPassPhrase, SymmetricKeyAlgorithmTag newEncAlgorithm, SecureRandom rand)

Parameters

ring PgpSecretKeyRing

The PgpSecretKeyRing to be copied.

oldPassPhrase char[]

The current password for key.

newPassPhrase char[]

The new password for the key.

newEncAlgorithm SymmetricKeyAlgorithmTag

The algorithm to be used for the encryption.

rand SecureRandom

Source of randomness.

Returns

PgpSecretKeyRing

Encode(Stream)

public void Encode(Stream outStr)

Parameters

outStr Stream

GetEncoded()

public byte[] GetEncoded()

Returns

byte[]

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.

public IEnumerable<PgpPublicKey> GetExtraPublicKeys()

Returns

IEnumerable<PgpPublicKey>

An IEnumerable of unattached, or extra, public keys.

GetKeysWithSignaturesBy(long)

public IEnumerable<PgpPublicKey> GetKeysWithSignaturesBy(long keyID)

Parameters

keyID long

Returns

IEnumerable<PgpPublicKey>

GetPublicKey()

Return the public key for the master key.

public PgpPublicKey GetPublicKey()

Returns

PgpPublicKey

GetPublicKey(byte[])

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

public PgpPublicKey GetPublicKey(byte[] fingerprint)

Parameters

fingerprint byte[]

Returns

PgpPublicKey

GetPublicKey(long)

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

public PgpPublicKey GetPublicKey(long keyID)

Parameters

keyID long

Returns

PgpPublicKey

GetPublicKeys()

public IEnumerable<PgpPublicKey> GetPublicKeys()

Returns

IEnumerable<PgpPublicKey>

GetSecretKey()

Return the master private key.

public PgpSecretKey GetSecretKey()

Returns

PgpSecretKey

GetSecretKey(byte[])

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

public PgpSecretKey GetSecretKey(byte[] fingerprint)

Parameters

fingerprint byte[]

Returns

PgpSecretKey

GetSecretKey(long)

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

public PgpSecretKey GetSecretKey(long keyId)

Parameters

keyId long

Returns

PgpSecretKey

GetSecretKeys()

Allows enumeration of the secret keys.

public IEnumerable<PgpSecretKey> GetSecretKeys()

Returns

IEnumerable<PgpSecretKey>

An IEnumerable of PgpSecretKey objects.

InsertSecretKey(PgpSecretKeyRing, PgpSecretKey)

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

public static PgpSecretKeyRing InsertSecretKey(PgpSecretKeyRing secRing, PgpSecretKey secKey)

Parameters

secRing PgpSecretKeyRing

The secret key ring to be modified.

secKey PgpSecretKey

The secret key to be inserted.

Returns

PgpSecretKeyRing

A new PgpSecretKeyRing

RemoveSecretKey(PgpSecretKeyRing, PgpSecretKey)

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

public static PgpSecretKeyRing RemoveSecretKey(PgpSecretKeyRing secRing, PgpSecretKey secKey)

Parameters

secRing PgpSecretKeyRing

The secret key ring to be modified.

secKey PgpSecretKey

The secret key to be removed.

Returns

PgpSecretKeyRing

A new PgpSecretKeyRing, or null if secKey is not found.

ReplacePublicKeys(PgpSecretKeyRing, PgpPublicKeyRing)

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

public static PgpSecretKeyRing ReplacePublicKeys(PgpSecretKeyRing secretRing, PgpPublicKeyRing publicRing)

Parameters

secretRing PgpSecretKeyRing

Secret ring to be changed.

publicRing PgpPublicKeyRing

Public ring containing the new public key set.

Returns

PgpSecretKeyRing