Class PgpSecretKey
- Namespace
- Org.BouncyCastle.Bcpg.OpenPgp
- Assembly
- BouncyCastle.Cryptography.dll
public class PgpSecretKey : PgpObject
- Inheritance
-
PgpSecretKey
- Inherited Members
Remarks
General class to handle a PGP secret key object.
Constructors
PgpSecretKey(int, PgpKeyPair, string, SymmetricKeyAlgorithmTag, HashAlgorithmTag, bool, char[], bool, PgpSignatureSubpacketVector, PgpSignatureSubpacketVector, SecureRandom)
public PgpSecretKey(int certificationLevel, PgpKeyPair keyPair, string id, SymmetricKeyAlgorithmTag encAlgorithm, HashAlgorithmTag hashAlgorithm, bool utf8PassPhrase, char[] passPhrase, bool useSha1, PgpSignatureSubpacketVector hashedPackets, PgpSignatureSubpacketVector unhashedPackets, SecureRandom rand)
Parameters
certificationLevelintkeyPairPgpKeyPairidstringencAlgorithmSymmetricKeyAlgorithmTaghashAlgorithmHashAlgorithmTagutf8PassPhraseboolpassPhrasechar[]useSha1boolhashedPacketsPgpSignatureSubpacketVectorunhashedPacketsPgpSignatureSubpacketVectorrandSecureRandom
Remarks
If utf8PassPhrase is true, conversion of the passphrase to bytes uses Encoding.UTF8.GetBytes(), otherwise the conversion is performed using Convert.ToByte(), which is the historical behaviour of the library (1.7 and earlier).
PgpSecretKey(int, PgpKeyPair, string, SymmetricKeyAlgorithmTag, HashAlgorithmTag, byte[], bool, PgpSignatureSubpacketVector, PgpSignatureSubpacketVector, SecureRandom)
public PgpSecretKey(int certificationLevel, PgpKeyPair keyPair, string id, SymmetricKeyAlgorithmTag encAlgorithm, HashAlgorithmTag hashAlgorithm, byte[] rawPassPhrase, bool useSha1, PgpSignatureSubpacketVector hashedPackets, PgpSignatureSubpacketVector unhashedPackets, SecureRandom rand)
Parameters
certificationLevelintkeyPairPgpKeyPairidstringencAlgorithmSymmetricKeyAlgorithmTaghashAlgorithmHashAlgorithmTagrawPassPhrasebyte[]useSha1boolhashedPacketsPgpSignatureSubpacketVectorunhashedPacketsPgpSignatureSubpacketVectorrandSecureRandom
Remarks
Allows the caller to handle the encoding of the passphrase to bytes.
PgpSecretKey(int, PgpKeyPair, string, SymmetricKeyAlgorithmTag, HashAlgorithmTag, char[], bool, PgpSignatureSubpacketVector, PgpSignatureSubpacketVector, SecureRandom)
public PgpSecretKey(int certificationLevel, PgpKeyPair keyPair, string id, SymmetricKeyAlgorithmTag encAlgorithm, HashAlgorithmTag hashAlgorithm, char[] passPhrase, bool useSha1, PgpSignatureSubpacketVector hashedPackets, PgpSignatureSubpacketVector unhashedPackets, SecureRandom rand)
Parameters
certificationLevelintkeyPairPgpKeyPairidstringencAlgorithmSymmetricKeyAlgorithmTaghashAlgorithmHashAlgorithmTagpassPhrasechar[]useSha1boolhashedPacketsPgpSignatureSubpacketVectorunhashedPacketsPgpSignatureSubpacketVectorrandSecureRandom
Remarks
Conversion of the passphrase characters to bytes is performed using Convert.ToByte(), which is the historical behaviour of the library (1.7 and earlier).
PgpSecretKey(int, PgpKeyPair, string, SymmetricKeyAlgorithmTag, bool, char[], bool, PgpSignatureSubpacketVector, PgpSignatureSubpacketVector, SecureRandom)
public PgpSecretKey(int certificationLevel, PgpKeyPair keyPair, string id, SymmetricKeyAlgorithmTag encAlgorithm, bool utf8PassPhrase, char[] passPhrase, bool useSha1, PgpSignatureSubpacketVector hashedPackets, PgpSignatureSubpacketVector unhashedPackets, SecureRandom rand)
Parameters
certificationLevelintkeyPairPgpKeyPairidstringencAlgorithmSymmetricKeyAlgorithmTagutf8PassPhraseboolpassPhrasechar[]useSha1boolhashedPacketsPgpSignatureSubpacketVectorunhashedPacketsPgpSignatureSubpacketVectorrandSecureRandom
Remarks
If utf8PassPhrase is true, conversion of the passphrase to bytes uses Encoding.UTF8.GetBytes(), otherwise the conversion is performed using Convert.ToByte(), which is the historical behaviour of the library (1.7 and earlier).
PgpSecretKey(int, PgpKeyPair, string, SymmetricKeyAlgorithmTag, byte[], bool, PgpSignatureSubpacketVector, PgpSignatureSubpacketVector, SecureRandom)
public PgpSecretKey(int certificationLevel, PgpKeyPair keyPair, string id, SymmetricKeyAlgorithmTag encAlgorithm, byte[] rawPassPhrase, bool useSha1, PgpSignatureSubpacketVector hashedPackets, PgpSignatureSubpacketVector unhashedPackets, SecureRandom rand)
Parameters
certificationLevelintkeyPairPgpKeyPairidstringencAlgorithmSymmetricKeyAlgorithmTagrawPassPhrasebyte[]useSha1boolhashedPacketsPgpSignatureSubpacketVectorunhashedPacketsPgpSignatureSubpacketVectorrandSecureRandom
Remarks
Allows the caller to handle the encoding of the passphrase to bytes.
PgpSecretKey(int, PgpKeyPair, string, SymmetricKeyAlgorithmTag, char[], bool, PgpSignatureSubpacketVector, PgpSignatureSubpacketVector, SecureRandom)
public PgpSecretKey(int certificationLevel, PgpKeyPair keyPair, string id, SymmetricKeyAlgorithmTag encAlgorithm, char[] passPhrase, bool useSha1, PgpSignatureSubpacketVector hashedPackets, PgpSignatureSubpacketVector unhashedPackets, SecureRandom rand)
Parameters
certificationLevelintkeyPairPgpKeyPairidstringencAlgorithmSymmetricKeyAlgorithmTagpassPhrasechar[]useSha1boolhashedPacketsPgpSignatureSubpacketVectorunhashedPacketsPgpSignatureSubpacketVectorrandSecureRandom
Remarks
Conversion of the passphrase characters to bytes is performed using Convert.ToByte(), which is the historical behaviour of the library (1.7 and earlier).
PgpSecretKey(int, PublicKeyAlgorithmTag, AsymmetricKeyParameter, AsymmetricKeyParameter, DateTime, string, SymmetricKeyAlgorithmTag, char[], PgpSignatureSubpacketVector, PgpSignatureSubpacketVector, SecureRandom)
public PgpSecretKey(int certificationLevel, PublicKeyAlgorithmTag algorithm, AsymmetricKeyParameter pubKey, AsymmetricKeyParameter privKey, DateTime time, string id, SymmetricKeyAlgorithmTag encAlgorithm, char[] passPhrase, PgpSignatureSubpacketVector hashedPackets, PgpSignatureSubpacketVector unhashedPackets, SecureRandom rand)
Parameters
certificationLevelintalgorithmPublicKeyAlgorithmTagpubKeyAsymmetricKeyParameterprivKeyAsymmetricKeyParametertimeDateTimeidstringencAlgorithmSymmetricKeyAlgorithmTagpassPhrasechar[]hashedPacketsPgpSignatureSubpacketVectorunhashedPacketsPgpSignatureSubpacketVectorrandSecureRandom
PgpSecretKey(int, PublicKeyAlgorithmTag, AsymmetricKeyParameter, AsymmetricKeyParameter, DateTime, string, SymmetricKeyAlgorithmTag, char[], bool, PgpSignatureSubpacketVector, PgpSignatureSubpacketVector, SecureRandom)
public PgpSecretKey(int certificationLevel, PublicKeyAlgorithmTag algorithm, AsymmetricKeyParameter pubKey, AsymmetricKeyParameter privKey, DateTime time, string id, SymmetricKeyAlgorithmTag encAlgorithm, char[] passPhrase, bool useSha1, PgpSignatureSubpacketVector hashedPackets, PgpSignatureSubpacketVector unhashedPackets, SecureRandom rand)
Parameters
certificationLevelintalgorithmPublicKeyAlgorithmTagpubKeyAsymmetricKeyParameterprivKeyAsymmetricKeyParametertimeDateTimeidstringencAlgorithmSymmetricKeyAlgorithmTagpassPhrasechar[]useSha1boolhashedPacketsPgpSignatureSubpacketVectorunhashedPacketsPgpSignatureSubpacketVectorrandSecureRandom
Properties
IsMasterKey
True, if this is a master key.
public bool IsMasterKey { get; }
Property Value
IsPrivateKeyEmpty
Detect if the Secret Key's Private Key is empty or not
public bool IsPrivateKeyEmpty { get; }
Property Value
IsSigningKey
Check if this key has an algorithm type that makes it suitable to use for signing.
public bool IsSigningKey { get; }
Property Value
- bool
trueif this key algorithm is suitable for use with signing.
Remarks
Note: with version 4 keys KeyFlags subpackets should also be considered when present for determining the preferred use of the key.
KeyEncryptionAlgorithm
The algorithm the key is encrypted with.
public SymmetricKeyAlgorithmTag KeyEncryptionAlgorithm { get; }
Property Value
KeyId
The key ID of the public key associated with this key.
public long KeyId { get; }
Property Value
PublicKey
The public key associated with this key.
public PgpPublicKey PublicKey { get; }
Property Value
S2k
Return the S2K used to process this key.
public S2k S2k { get; }
Property Value
S2kUsage
Return the S2K usage associated with this key.
public int S2kUsage { get; }
Property Value
UserAttributes
Allows enumeration of any user attribute vectors associated with the key.
public IEnumerable<PgpUserAttributeSubpacketVector> UserAttributes { get; }
Property Value
- IEnumerable<PgpUserAttributeSubpacketVector>
An
IEnumerableofstringobjects.
UserIds
Allows enumeration of any user IDs associated with the key.
public IEnumerable<string> UserIds { get; }
Property Value
- IEnumerable<string>
An
IEnumerableofstringobjects.
Methods
CopyWithNewPassword(PgpSecretKey, char[], char[], SymmetricKeyAlgorithmTag, SecureRandom)
Return a copy of the passed in secret key, encrypted using a new password and the passed in algorithm.
public static PgpSecretKey CopyWithNewPassword(PgpSecretKey key, char[] oldPassPhrase, char[] newPassPhrase, SymmetricKeyAlgorithmTag newEncAlgorithm, SecureRandom rand)
Parameters
keyPgpSecretKeyThe PgpSecretKey to be copied.
oldPassPhrasechar[]The current password for the key.
newPassPhrasechar[]The new password for the key.
newEncAlgorithmSymmetricKeyAlgorithmTagThe algorithm to be used for the encryption.
randSecureRandomSource of randomness.
Returns
Remarks
Conversion of the passphrase characters to bytes is performed using Convert.ToByte(), which is the historical behaviour of the library (1.7 and earlier).
CopyWithNewPasswordRaw(PgpSecretKey, byte[], byte[], SymmetricKeyAlgorithmTag, SecureRandom)
Return a copy of the passed in secret key, encrypted using a new password and the passed in algorithm.
public static PgpSecretKey CopyWithNewPasswordRaw(PgpSecretKey key, byte[] rawOldPassPhrase, byte[] rawNewPassPhrase, SymmetricKeyAlgorithmTag newEncAlgorithm, SecureRandom rand)
Parameters
keyPgpSecretKeyThe PgpSecretKey to be copied.
rawOldPassPhrasebyte[]The current password for the key.
rawNewPassPhrasebyte[]The new password for the key.
newEncAlgorithmSymmetricKeyAlgorithmTagThe algorithm to be used for the encryption.
randSecureRandomSource of randomness.
Returns
Remarks
Allows the caller to handle the encoding of the passphrase to bytes.
CopyWithNewPasswordUtf8(PgpSecretKey, char[], char[], SymmetricKeyAlgorithmTag, SecureRandom)
Return a copy of the passed in secret key, encrypted using a new password and the passed in algorithm.
public static PgpSecretKey CopyWithNewPasswordUtf8(PgpSecretKey key, char[] oldPassPhrase, char[] newPassPhrase, SymmetricKeyAlgorithmTag newEncAlgorithm, SecureRandom rand)
Parameters
keyPgpSecretKeyThe PgpSecretKey to be copied.
oldPassPhrasechar[]The current password for the key.
newPassPhrasechar[]The new password for the key.
newEncAlgorithmSymmetricKeyAlgorithmTagThe algorithm to be used for the encryption.
randSecureRandomSource of randomness.
Returns
Remarks
The passphrase is encoded to bytes using UTF8 (Encoding.UTF8.GetBytes).
Encode(Stream)
public void Encode(Stream outStr)
Parameters
outStrStream
ExtractPrivateKey(char[])
Extract a PgpPrivateKey from this secret key's encrypted contents.
public PgpPrivateKey ExtractPrivateKey(char[] passPhrase)
Parameters
passPhrasechar[]
Returns
Remarks
Conversion of the passphrase characters to bytes is performed using Convert.ToByte(), which is the historical behaviour of the library (1.7 and earlier).
ExtractPrivateKeyRaw(byte[])
Extract a PgpPrivateKey from this secret key's encrypted contents.
public PgpPrivateKey ExtractPrivateKeyRaw(byte[] rawPassPhrase)
Parameters
rawPassPhrasebyte[]
Returns
Remarks
Allows the caller to handle the encoding of the passphrase to bytes.
ExtractPrivateKeyUtf8(char[])
Extract a PgpPrivateKey from this secret key's encrypted contents.
public PgpPrivateKey ExtractPrivateKeyUtf8(char[] passPhrase)
Parameters
passPhrasechar[]
Returns
Remarks
The passphrase is encoded to bytes using UTF8 (Encoding.UTF8.GetBytes).
GetEncoded()
public byte[] GetEncoded()
Returns
- byte[]
GetFingerprint()
The fingerprint of the public key associated with this key.
public byte[] GetFingerprint()
Returns
- byte[]
ParseSecretKeyFromSExpr(Stream, char[])
Parse a secret key from one of the GPG S expression keys.
public static PgpSecretKey ParseSecretKeyFromSExpr(Stream inputStream, char[] passPhrase)
Parameters
Returns
Remarks
Conversion of the passphrase characters to bytes is performed using Convert.ToByte(), which is the historical behaviour of the library (1.7 and earlier).
ParseSecretKeyFromSExpr(Stream, char[], PgpPublicKey)
Parse a secret key from one of the GPG S expression keys associating it with the passed in public key.
public static PgpSecretKey ParseSecretKeyFromSExpr(Stream inputStream, char[] passPhrase, PgpPublicKey pubKey)
Parameters
inputStreamStreampassPhrasechar[]pubKeyPgpPublicKey
Returns
Remarks
Conversion of the passphrase characters to bytes is performed using Convert.ToByte(), which is the historical behaviour of the library (1.7 and earlier).
ParseSecretKeyFromSExprRaw(Stream, byte[])
Parse a secret key from one of the GPG S expression keys.
public static PgpSecretKey ParseSecretKeyFromSExprRaw(Stream inputStream, byte[] rawPassPhrase)
Parameters
Returns
Remarks
Allows the caller to handle the encoding of the passphrase to bytes.
ParseSecretKeyFromSExprRaw(Stream, byte[], PgpPublicKey)
Parse a secret key from one of the GPG S expression keys associating it with the passed in public key.
public static PgpSecretKey ParseSecretKeyFromSExprRaw(Stream inputStream, byte[] rawPassPhrase, PgpPublicKey pubKey)
Parameters
inputStreamStreamrawPassPhrasebyte[]pubKeyPgpPublicKey
Returns
Remarks
Allows the caller to handle the encoding of the passphrase to bytes.
ParseSecretKeyFromSExprUtf8(Stream, char[])
Parse a secret key from one of the GPG S expression keys.
public static PgpSecretKey ParseSecretKeyFromSExprUtf8(Stream inputStream, char[] passPhrase)
Parameters
Returns
Remarks
The passphrase is encoded to bytes using UTF8 (Encoding.UTF8.GetBytes).
ParseSecretKeyFromSExprUtf8(Stream, char[], PgpPublicKey)
Parse a secret key from one of the GPG S expression keys associating it with the passed in public key.
public static PgpSecretKey ParseSecretKeyFromSExprUtf8(Stream inputStream, char[] passPhrase, PgpPublicKey pubKey)
Parameters
inputStreamStreampassPhrasechar[]pubKeyPgpPublicKey
Returns
Remarks
The passphrase is encoded to bytes using UTF8 (Encoding.UTF8.GetBytes).
ReplacePublicKey(PgpSecretKey, PgpPublicKey)
Replace the passed the public key on the passed in secret key.
public static PgpSecretKey ReplacePublicKey(PgpSecretKey secretKey, PgpPublicKey publicKey)
Parameters
secretKeyPgpSecretKeySecret key to change.
publicKeyPgpPublicKeyNew public key.
Returns
- PgpSecretKey
A new secret key.
Exceptions
- ArgumentException
If KeyId's do not match.