public bool Verify(PgpKey publicKey, Stream stream, bool ignoreTrailingWhitespace = false) { var helper = new PgpSignatureTransformation(SignatureType, HashAlgorithm, ignoreTrailingWhitespace); new CryptoStream(stream, helper, CryptoStreamMode.Read).CopyTo(Stream.Null); helper.Finish(sigPck.Version, sigPck.KeyAlgorithm, sigPck.CreationTime, sigPck.GetHashedSubPackets()); return(publicKey.Verify(helper.Hash !, sigPck.GetSignature(), helper.HashAlgorithm)); }
/// <summary>Return a signature object containing the current signature state.</summary> internal SignaturePacket Generate() { DateTime creationTime = DateTime.UtcNow; if (version >= 4) { if (!HashedAttributes.SignatureCreationTime.HasValue) { HashedAttributes.SetSignatureCreationTime(false, creationTime); } else { creationTime = HashedAttributes.SignatureCreationTime.Value; } if (!HashedAttributes.IssuerKeyId.HasValue && !UnhashedAttributes.IssuerKeyId.HasValue) { UnhashedAttributes.SetIssuerKeyId(false, privateKey.KeyId); } } var hashedPackets = hashedAttributes == null?Array.Empty <SignatureSubpacket>() : hashedAttributes.ToSubpacketArray(); helper.Finish( version, privateKey.Algorithm, creationTime, hashedPackets); var signature = privateKey.Sign(helper.Hash !, helper.HashAlgorithm); return(new SignaturePacket( version, helper.SignatureType, privateKey.KeyId, privateKey.Algorithm, hashAlgorithm, creationTime, hashedPackets, unhashedAttributes == null ? Array.Empty <SignatureSubpacket>() : unhashedAttributes.ToSubpacketArray(), helper.Hash.AsSpan(0, 2).ToArray(), signature)); }