Table of Contents

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

algorithm PublicKeyAlgorithmTag

Asymmetric algorithm type representing the public key.

pubKey AsymmetricKeyParameter

Actual public key to associate.

time DateTime

Date 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 pubKey is not public.

PgpException

On key creation problem.

PgpPublicKey(PublicKeyPacket)

public PgpPublicKey(PublicKeyPacket publicPk)

Parameters

publicPk PublicKeyPacket

Properties

Algorithm

The algorithm code associated with the public key.

public PublicKeyAlgorithmTag Algorithm { get; }

Property Value

PublicKeyAlgorithmTag

BitStrength

The strength of the key in bits.

public int BitStrength { get; }

Property Value

int

CreationTime

The creation time of this key.

public DateTime CreationTime { get; }

Property Value

DateTime

IsEncryptionKey

Check if this key has an algorithm type that makes it suitable to use for encryption.

public bool IsEncryptionKey { get; }

Property Value

bool

true if 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

bool

KeyId

The key ID associated with the public key.

public long KeyId { get; }

Property Value

long

PublicKeyPacket

public PublicKeyPacket PublicKeyPacket { get; }

Property Value

PublicKeyPacket

Version

The version of this key.

public int Version { get; }

Property Value

int

Methods

AddCertification(PgpPublicKey, PgpSignature)

Add a revocation or some other key certification to a key.

public static PgpPublicKey AddCertification(PgpPublicKey key, PgpSignature certification)

Parameters

key PgpPublicKey

The key the revocation is to be added to.

certification PgpSignature

The 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

key PgpPublicKey

The key the certification is to be added to.

userAttributes PgpUserAttributeSubpacketVector

The attributes the certification is associated with.

certification PgpSignature

The 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

key PgpPublicKey

The key the certification is to be added to.

id string

The ID the certification is associated with.

certification PgpSignature

The new certification.

Returns

PgpPublicKey

The re-certified key.

CalculateFingerprint(PublicKeyPacket)

public static byte[] CalculateFingerprint(PublicKeyPacket publicPk)

Parameters

publicPk PublicKeyPacket

Returns

byte[]

Encode(Stream)

public void Encode(Stream outStr)

Parameters

outStr Stream

Encode(Stream, bool)

public void Encode(Stream outStr, bool forTransfer)

Parameters

outStr Stream
forTransfer bool

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

IEnumerable<PgpSignature>

GetRawUserIds()

Return any userIDs associated with the key in raw byte form.

public IEnumerable<byte[]> GetRawUserIds()

Returns

IEnumerable<byte[]>

An IEnumerable of byte[].

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 IEnumerable with all signatures/certifications.

GetSignaturesForId(byte[])

public IEnumerable<PgpSignature> GetSignaturesForId(byte[] rawId)

Parameters

rawId byte[]

Returns

IEnumerable<PgpSignature>

GetSignaturesForId(string)

Allows enumeration of any signatures associated with the passed in id.

public IEnumerable<PgpSignature> GetSignaturesForId(string id)

Parameters

id string

The ID to be matched.

Returns

IEnumerable<PgpSignature>

An IEnumerable of PgpSignature objects.

GetSignaturesForKeyID(long)

Return any signatures associated with the passed in key identifier keyID.

public IEnumerable<PgpSignature> GetSignaturesForKeyID(long keyID)

Parameters

keyID long

the key id to be matched.

Returns

IEnumerable<PgpSignature>

An IEnumerable of PgpSignature objects 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

userAttributes PgpUserAttributeSubpacketVector

The vector of user attributes to be matched.

Returns

IEnumerable<PgpSignature>

An IEnumerable of PgpSignature objects.

GetSignaturesOfType(int)

Allows enumeration of signatures of the passed in type that are on this key.

public IEnumerable<PgpSignature> GetSignaturesOfType(int signatureType)

Parameters

signatureType int

The type of the signature to be returned.

Returns

IEnumerable<PgpSignature>

An IEnumerable of PgpSignature objects.

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 IEnumerable of PgpUserAttributeSubpacketVector objects.

GetUserIds()

Allows enumeration of any user IDs associated with the key.

public IEnumerable<string> GetUserIds()

Returns

IEnumerable<string>

An IEnumerable of string objects.

GetValidSeconds()

The number of valid seconds from creation time - zero means no expiry.

public long GetValidSeconds()

Returns

long

HasFingerprint(byte[])

public bool HasFingerprint(byte[] fingerprint)

Parameters

fingerprint byte[]

Returns

bool

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

key PgpPublicKey

local public key.

copy PgpPublicKey

copy of the public key (e.g. from a key server).

joinTrustPackets bool

if true, trust packets from the copy are copied over into the resulting key.

allowSubkeySigsOnNonSubkey bool

if 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

key PgpPublicKey

The key the certifications are to be removed from.

certification PgpSignature

The 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

key PgpPublicKey

The key the certifications are to be removed from.

userAttributes PgpUserAttributeSubpacketVector

The 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

key PgpPublicKey

The key the certifications are to be removed from.

userAttributes PgpUserAttributeSubpacketVector

The user attributes that the certfication is to be removed from.

certification PgpSignature

The 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

key PgpPublicKey

The key the certifications are to be removed from.

rawId byte[]

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

key PgpPublicKey

The key the certifications are to be removed from.

id byte[]

The ID that the certfication is to be removed from (in its raw byte form).

certification PgpSignature

The 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

key PgpPublicKey

The key the certifications are to be removed from.

id string

The 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

key PgpPublicKey

The key the certifications are to be removed from.

id string

The ID that the certfication is to be removed from.

certification PgpSignature

The certfication to be removed.

Returns

PgpPublicKey

The re-certified key, or null if the certification was not found.