public void ToHashAlgorithm() { foreach (HashAlgorithmName name in this.GetNames()) { HashAlgorithm algorithm = HashAlgorithmConvertor.ToHashAlgorithm(name); Assert.IsNotNull(algorithm); } }
public void ToHashSizeInBytes() { foreach (HashAlgorithmName name in this.GetNames()) { int size = HashAlgorithmConvertor.ToHashSizeInBytes(name); HashAlgorithm algorithm = HashAlgorithmConvertor.ToHashAlgorithm(name); Assert.AreEqual(algorithm.HashSize / 8, size); } }
private static byte[] CreateRawAsn1(IEnumerable <X509Certificate2> signingCertificates, HashAlgorithmName hashAlgorithmName) { if (signingCertificates == null) { throw new ArgumentNullException(nameof(signingCertificates)); } using HashAlgorithm hasher = HashAlgorithmConvertor.ToHashAlgorithm(hashAlgorithmName); Span <byte> hash = stackalloc byte[hasher.HashSize / 8]; using AsnWriter asnWriter = new AsnWriter(AsnEncodingRules.DER); asnWriter.PushSequence(); asnWriter.PushSequence(); foreach (X509Certificate2 signingCertificate in signingCertificates) { hasher.TryComputeHash(signingCertificate.RawData, hash, out _); // Begin essCertIDv2 asnWriter.PushSequence(); // Begin algorithm identifier asnWriter.PushSequence(); asnWriter.WriteObjectIdentifier(HashAlgorithmConvertor.ToOid(hashAlgorithmName)); asnWriter.WriteNull(); asnWriter.PopSequence(); // End Algorithm identifier asnWriter.WriteOctetString(hash); asnWriter.PopSequence(); // End essCertIDv2 } asnWriter.PopSequence(); asnWriter.PopSequence(); return(asnWriter.Encode()); }