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

OnePassSignaturePacket

using Org.BouncyCastle.Crypto.Utilities; namespace Org.BouncyCastle.Bcpg { public class OnePassSignaturePacket : ContainedPacket { private readonly int m_version; private readonly int m_sigType; private readonly HashAlgorithmTag m_hashAlgorithm; private readonly PublicKeyAlgorithmTag m_keyAlgorithm; private readonly ulong m_keyID; private readonly int m_nested; public int SignatureType => m_sigType; public PublicKeyAlgorithmTag KeyAlgorithm => m_keyAlgorithm; public HashAlgorithmTag HashAlgorithm => m_hashAlgorithm; public long KeyId => (long)m_keyID; internal OnePassSignaturePacket(BcpgInputStream bcpgIn) { m_version = bcpgIn.RequireByte(); m_sigType = bcpgIn.RequireByte(); m_hashAlgorithm = (HashAlgorithmTag)bcpgIn.RequireByte(); m_keyAlgorithm = (PublicKeyAlgorithmTag)bcpgIn.RequireByte(); m_keyID = StreamUtilities.RequireUInt64BE(bcpgIn); m_nested = bcpgIn.RequireByte(); } public OnePassSignaturePacket(int sigType, HashAlgorithmTag hashAlgorithm, PublicKeyAlgorithmTag keyAlgorithm, long keyId, bool isNested) { m_version = 3; m_sigType = sigType; m_hashAlgorithm = hashAlgorithm; m_keyAlgorithm = keyAlgorithm; m_keyID = (ulong)keyId; m_nested = ((!isNested) ? 1 : 0); } public override void Encode(BcpgOutputStream bcpgOut) { byte[] array = new byte[13] { (byte)m_version, (byte)m_sigType, (byte)m_hashAlgorithm, (byte)m_keyAlgorithm, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Pack.UInt64_To_BE(m_keyID, array, 4); array[12] = (byte)m_nested; bcpgOut.WritePacket(PacketTag.OnePassSignature, array); } } }