public static void SignatureAlgorithm_Encoding(string hashAlgorithmName) { string expectedOid; switch (hashAlgorithmName) { case "MD5": expectedOid = "06092A864886F70D010104"; break; case "SHA1": expectedOid = "06092A864886F70D010105"; break; case "SHA256": expectedOid = "06092A864886F70D01010B"; break; case "SHA384": expectedOid = "06092A864886F70D01010C"; break; case "SHA512": expectedOid = "06092A864886F70D01010D"; break; default: throw new ArgumentOutOfRangeException(nameof(hashAlgorithmName)); } string expectedHex = $"30{(expectedOid.Length / 2 + 2):X2}{expectedOid}0500"; using (RSA rsa = RSA.Create()) { RSAParameters parameters = TestData.RsaBigExponentParams; rsa.ImportParameters(parameters); HashAlgorithmName hashAlgorithm = new HashAlgorithmName(hashAlgorithmName); X509SignatureGenerator signatureGenerator = X509SignatureGenerator.CreateForRSA(rsa, RSASignaturePadding.Pkcs1); byte[] sigAlg = signatureGenerator.GetSignatureAlgorithmIdentifier(hashAlgorithm); Assert.Equal(expectedHex, sigAlg.ByteArrayToHex()); } }