Class PgpPublicKey
- Namespace
- Org.BouncyCastle.Bcpg.OpenPgp
- Assembly
- BouncyCastle.Cryptography.dll
public class PgpPublicKey : PgpObject
- Inheritance
-
PgpPublicKey
- Inherited Members
Remarks
General class to handle a PGP public key object.
Constructors
PgpPublicKey(PublicKeyAlgorithmTag, AsymmetricKeyParameter, DateTime)
Create a PgpPublicKey from the passed in lightweight one.
public PgpPublicKey(PublicKeyAlgorithmTag algorithm, AsymmetricKeyParameter pubKey, DateTime time)
Parameters
algorithmPublicKeyAlgorithmTagAsymmetric algorithm type representing the public key.
pubKeyAsymmetricKeyParameterActual public key to associate.
timeDateTimeDate of creation.
Remarks
Note: the time passed in affects the value of the key's keyId, so you probably only want to do this once for a lightweight key, or make sure you keep track of the time you used.
Exceptions
- ArgumentException
If
pubKeyis not public.- PgpException
On key creation problem.
PgpPublicKey(PublicKeyPacket)
public PgpPublicKey(PublicKeyPacket publicPk)
Parameters
publicPkPublicKeyPacket
Properties
Algorithm
The algorithm code associated with the public key.
public PublicKeyAlgorithmTag Algorithm { get; }
Property Value
BitStrength
The strength of the key in bits.
public int BitStrength { get; }
Property Value
CreationTime
The creation time of this key.
public DateTime CreationTime { get; }
Property Value
IsEncryptionKey
Check if this key has an algorithm type that makes it suitable to use for encryption.
public bool IsEncryptionKey { get; }
Property Value
- bool
trueif this key algorithm is suitable for encryption.
Remarks
Note: with version 4 keys KeyFlags subpackets should also be considered when present for determining the preferred use of the key.
IsMasterKey
True, if this could be a master key.
public bool IsMasterKey { get; }
Property Value
KeyId
The key ID associated with the public key.
public long KeyId { get; }
Property Value
PublicKeyPacket
public PublicKeyPacket PublicKeyPacket { get; }
Property Value
Version
The version of this key.
public int Version { get; }
Property Value
Methods
AddCertification(PgpPublicKey, PgpSignature)
Add a revocation or some other key certification to a key.
public static PgpPublicKey AddCertification(PgpPublicKey key, PgpSignature certification)
Parameters
keyPgpPublicKeyThe key the revocation is to be added to.
certificationPgpSignatureThe key signature to be added.
Returns
- PgpPublicKey
The new changed public key object.
AddCertification(PgpPublicKey, PgpUserAttributeSubpacketVector, PgpSignature)
Add a certification for the given UserAttributeSubpackets to the given public key.
public static PgpPublicKey AddCertification(PgpPublicKey key, PgpUserAttributeSubpacketVector userAttributes, PgpSignature certification)
Parameters
keyPgpPublicKeyThe key the certification is to be added to.
userAttributesPgpUserAttributeSubpacketVectorThe attributes the certification is associated with.
certificationPgpSignatureThe new certification.
Returns
- PgpPublicKey
The re-certified key.
AddCertification(PgpPublicKey, string, PgpSignature)
Add a certification for an id to the given public key.
public static PgpPublicKey AddCertification(PgpPublicKey key, string id, PgpSignature certification)
Parameters
keyPgpPublicKeyThe key the certification is to be added to.
idstringThe ID the certification is associated with.
certificationPgpSignatureThe new certification.
Returns
- PgpPublicKey
The re-certified key.
CalculateFingerprint(PublicKeyPacket)
public static byte[] CalculateFingerprint(PublicKeyPacket publicPk)
Parameters
publicPkPublicKeyPacket
Returns
- byte[]
Encode(Stream)
public void Encode(Stream outStr)
Parameters
outStrStream
Encode(Stream, bool)
public void Encode(Stream outStr, bool forTransfer)
Parameters
GetEncoded()
public byte[] GetEncoded()
Returns
- byte[]
GetFingerprint()
The fingerprint of the public key
public byte[] GetFingerprint()
Returns
- byte[]
GetKey()
The public key contained in the object.
public AsymmetricKeyParameter GetKey()
Returns
- AsymmetricKeyParameter
A lightweight public key.
Exceptions
- PgpException
If the key algorithm is not recognised.
GetKeySignatures()
public IEnumerable<PgpSignature> GetKeySignatures()
Returns
GetRawUserIds()
Return any userIDs associated with the key in raw byte form.
public IEnumerable<byte[]> GetRawUserIds()
Returns
- IEnumerable<byte[]>
An
IEnumerableofbyte[].
Remarks
No attempt is made to convert the IDs into strings.
GetSignatures()
Allows enumeration of all signatures/certifications associated with this key.
public IEnumerable<PgpSignature> GetSignatures()
Returns
- IEnumerable<PgpSignature>
An
IEnumerablewith all signatures/certifications.
GetSignaturesForId(byte[])
public IEnumerable<PgpSignature> GetSignaturesForId(byte[] rawId)
Parameters
rawIdbyte[]
Returns
GetSignaturesForId(string)
Allows enumeration of any signatures associated with the passed in id.
public IEnumerable<PgpSignature> GetSignaturesForId(string id)
Parameters
idstringThe ID to be matched.
Returns
- IEnumerable<PgpSignature>
An
IEnumerableofPgpSignatureobjects.
GetSignaturesForKeyID(long)
Return any signatures associated with the passed in key identifier keyID.
public IEnumerable<PgpSignature> GetSignaturesForKeyID(long keyID)
Parameters
keyIDlongthe key id to be matched.
Returns
- IEnumerable<PgpSignature>
An
IEnumerableofPgpSignatureobjects issued by the key with keyID.
GetSignaturesForUserAttribute(PgpUserAttributeSubpacketVector)
Allows enumeration of signatures associated with the passed in user attributes.
public IEnumerable<PgpSignature> GetSignaturesForUserAttribute(PgpUserAttributeSubpacketVector userAttributes)
Parameters
userAttributesPgpUserAttributeSubpacketVectorThe vector of user attributes to be matched.
Returns
- IEnumerable<PgpSignature>
An
IEnumerableofPgpSignatureobjects.
GetSignaturesOfType(int)
Allows enumeration of signatures of the passed in type that are on this key.
public IEnumerable<PgpSignature> GetSignaturesOfType(int signatureType)
Parameters
signatureTypeintThe type of the signature to be returned.
Returns
- IEnumerable<PgpSignature>
An
IEnumerableofPgpSignatureobjects.
GetTrustData()
Return the trust data associated with the public key, if present.
public byte[] GetTrustData()
Returns
- byte[]
A byte array with trust data, null otherwise.
GetUserAttributes()
Allows enumeration of any user attribute vectors associated with the key.
public IEnumerable<PgpUserAttributeSubpacketVector> GetUserAttributes()
Returns
- IEnumerable<PgpUserAttributeSubpacketVector>
An
IEnumerableofPgpUserAttributeSubpacketVectorobjects.
GetUserIds()
Allows enumeration of any user IDs associated with the key.
public IEnumerable<string> GetUserIds()
Returns
- IEnumerable<string>
An
IEnumerableofstringobjects.
GetValidSeconds()
The number of valid seconds from creation time - zero means no expiry.
public long GetValidSeconds()
Returns
HasFingerprint(byte[])
public bool HasFingerprint(byte[] fingerprint)
Parameters
fingerprintbyte[]
Returns
IsRevoked()
Check whether this (sub)key has a revocation signature on it.
public bool IsRevoked()
Returns
- bool
True, if this (sub)key has been revoked.
Join(PgpPublicKey, PgpPublicKey, bool, bool)
Merge the given local public key with another, potentially fresher copy. The resulting public key contains the sum of both keys' user-ids and signatures.
public static PgpPublicKey Join(PgpPublicKey key, PgpPublicKey copy, bool joinTrustPackets, bool allowSubkeySigsOnNonSubkey)
Parameters
keyPgpPublicKeylocal public key.
copyPgpPublicKeycopy of the public key (e.g. from a key server).
joinTrustPacketsboolif true, trust packets from the copy are copied over into the resulting key.
allowSubkeySigsOnNonSubkeyboolif true, subkey signatures on the copy will be present in the merged key, even if key was not a subkey before.
Returns
- PgpPublicKey
joined key.
Remarks
If joinTrustPackets is set to true and the copy carries a trust packet, the joined key will copy the trust-packet from the copy. Otherwise, it will carry the trust packet of the local key.
RemoveCertification(PgpPublicKey, PgpSignature)
Remove a certification from the key.
public static PgpPublicKey RemoveCertification(PgpPublicKey key, PgpSignature certification)
Parameters
keyPgpPublicKeyThe key the certifications are to be removed from.
certificationPgpSignatureThe certfication to be removed.
Returns
- PgpPublicKey
The modified key, null if the certification was not found.
RemoveCertification(PgpPublicKey, PgpUserAttributeSubpacketVector)
Remove any certifications associated with a user attribute subpacket on a key.
public static PgpPublicKey RemoveCertification(PgpPublicKey key, PgpUserAttributeSubpacketVector userAttributes)
Parameters
keyPgpPublicKeyThe key the certifications are to be removed from.
userAttributesPgpUserAttributeSubpacketVectorThe attributes to be removed.
Returns
- PgpPublicKey
The re-certified key, or null if the user attribute subpacket was not found on the key.
RemoveCertification(PgpPublicKey, PgpUserAttributeSubpacketVector, PgpSignature)
Remove a certification associated with a given user attributes on a key.
public static PgpPublicKey RemoveCertification(PgpPublicKey key, PgpUserAttributeSubpacketVector userAttributes, PgpSignature certification)
Parameters
keyPgpPublicKeyThe key the certifications are to be removed from.
userAttributesPgpUserAttributeSubpacketVectorThe user attributes that the certfication is to be removed from.
certificationPgpSignatureThe certification to be removed.
Returns
- PgpPublicKey
The re-certified key, or null if the certification was not found.
RemoveCertification(PgpPublicKey, byte[])
Remove any certifications associated with a given ID on a key.
public static PgpPublicKey RemoveCertification(PgpPublicKey key, byte[] rawId)
Parameters
keyPgpPublicKeyThe key the certifications are to be removed from.
rawIdbyte[]The ID that is to be removed in raw byte form.
Returns
- PgpPublicKey
The re-certified key, or null if the ID was not found on the key.
RemoveCertification(PgpPublicKey, byte[], PgpSignature)
Remove a certification associated with a given ID on a key.
public static PgpPublicKey RemoveCertification(PgpPublicKey key, byte[] id, PgpSignature certification)
Parameters
keyPgpPublicKeyThe key the certifications are to be removed from.
idbyte[]The ID that the certfication is to be removed from (in its raw byte form).
certificationPgpSignatureThe certfication to be removed.
Returns
- PgpPublicKey
The re-certified key, or null if the certification was not found.
RemoveCertification(PgpPublicKey, string)
Remove any certifications associated with a given ID on a key.
public static PgpPublicKey RemoveCertification(PgpPublicKey key, string id)
Parameters
keyPgpPublicKeyThe key the certifications are to be removed from.
idstringThe ID that is to be removed.
Returns
- PgpPublicKey
The re-certified key, or null if the ID was not found on the key.
RemoveCertification(PgpPublicKey, string, PgpSignature)
Remove a certification associated with a given ID on a key.
public static PgpPublicKey RemoveCertification(PgpPublicKey key, string id, PgpSignature certification)
Parameters
keyPgpPublicKeyThe key the certifications are to be removed from.
idstringThe ID that the certfication is to be removed from.
certificationPgpSignatureThe certfication to be removed.
Returns
- PgpPublicKey
The re-certified key, or null if the certification was not found.