예제 #1
0
        public static void WriteTlsSignature(this SignedStream stream, TLSHashAlgorithm hashAlgorithm, TLSSignatureAlgorithm signatureAlgorithm)
        {
            stream.InnerStream.Write(new[]
            {
                hashAlgorithm.Id,
                signatureAlgorithm.Id
            }, 0, 2);

            var signature = stream.Sign();

            stream.InnerStream.Write(EndianBitConverter.Big.GetBytes((ushort)signature.Length), 0, 2);
            stream.InnerStream.Write(signature, 0, signature.Length);
        }
예제 #2
0
        public static void VerifyTlsSignature(this SignedStream stream, TLSHashAlgorithm hashAlgorithm, TLSSignatureAlgorithm signatureAlgorithm)
        {
            var reader = new EndianBinaryReader(EndianBitConverter.Big, stream.InnerStream);

            var actualHashAlgo = reader.ReadByte();

            SecurityAssert.Assert(actualHashAlgo == hashAlgorithm.Id);
            var actualSignAlgo = reader.ReadByte();

            SecurityAssert.Assert(actualSignAlgo == signatureAlgorithm.Id);

            var signLength = reader.ReadUInt16();
            var actualSign = reader.ReadBytes(signLength);

            SecurityAssert.Assert(stream.Verify(actualSign));
        }