using System.Security.Cryptography; namespace EnvelopeGenerator.Infrastructure.Crypt.Services; internal static class Pkcs11DigestInfoBuilder { public static byte[] Build(byte[] hash, HashAlgorithmName hashAlgorithm) { byte[] prefix = hashAlgorithm.Name switch { "SHA256" => [ 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20 ], "SHA384" => [ 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30 ], "SHA512" => [ 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40 ], _ => throw new NotSupportedException($"Hash algorithm '{hashAlgorithm.Name}' is not supported.") }; var digestInfo = new byte[prefix.Length + hash.Length]; Buffer.BlockCopy(prefix, 0, digestInfo, 0, prefix.Length); Buffer.BlockCopy(hash, 0, digestInfo, prefix.Length, hash.Length); return digestInfo; } }