<PackageReference Include="BouncyCastle.Cryptography" Version="2.7.0-beta.98" />

ECPublicBcpgKey

public abstract class ECPublicBcpgKey : BcpgObject, IBcpgKey
Base class for an EC Public Key.
using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Math; using Org.BouncyCastle.Math.EC; using System.IO; namespace Org.BouncyCastle.Bcpg { public abstract class ECPublicBcpgKey : BcpgObject, IBcpgKey { private readonly DerObjectIdentifier m_oid; private readonly BigInteger m_point; public virtual BigInteger EncodedPoint => m_point; public virtual DerObjectIdentifier CurveOid => m_oid; public string Format => "PGP"; protected ECPublicBcpgKey(BcpgInputStream bcpgIn) { m_oid = DerObjectIdentifier.GetInstance(ReadBytesOfEncodedLength(bcpgIn)); m_point = new MPInteger(bcpgIn).Value; } protected ECPublicBcpgKey(DerObjectIdentifier oid, ECPoint point) { m_point = MPInteger.ToMpiBigInteger(point); m_oid = oid; } protected ECPublicBcpgKey(DerObjectIdentifier oid, BigInteger encodedPoint) { m_point = encodedPoint; m_oid = oid; } public override byte[] GetEncoded() { return BcpgOutputStream.GetEncodedOrNull(this); } public override void Encode(BcpgOutputStream bcpgOut) { byte[] encoded = m_oid.GetEncoded(); bcpgOut.Write(encoded, 1, encoded.Length - 1); MPInteger.Encode(bcpgOut, m_point); } protected static byte[] ReadBytesOfEncodedLength(BcpgInputStream bcpgIn) { int num = bcpgIn.RequireByte(); if (num == 0 || num == 255) throw new IOException("future extensions not yet implemented"); if (num > 127) throw new IOException("unsupported OID"); byte[] array = new byte[2 + num]; bcpgIn.ReadFully(array, 2, array.Length - 2); array[0] = 6; array[1] = (byte)num; return array; } } }