public void SignHashInvalidHashAlgorithmThrows()
        {
            byte[] hashVal;
            using (Gost3411 gostHash = Gost3411.Create())
            {
                hashVal = gostHash.ComputeHash(bytesToHash);
            }

            using (var gost = GetGostProvider())
            {
                Assert.ThrowsAny <CryptographicException>(() => gost.SignHash(hashVal, HashAlgorithmName.SHA256));
            }
        }
        public void SignHashDefaultAlgorithmSuccess()
        {
            byte[] hashVal;
            using (Gost3411 gostHash = Gost3411.Create())
            {
                hashVal = gostHash.ComputeHash(bytesToHash);
            }

            using (var gost = GetGostProvider())
            {
                byte[] signVal = gost.SignHash(hashVal);
                Assert.True(gost.VerifyHash(hashVal, signVal));
            }
        }
Ejemplo n.º 3
0
 public static IEnumerable <object[]> ReusabilityHashAlgorithms()
 {
     return(new[]
     {
         new object[] { MD5.Create(), },
         new object[] { SHA1.Create(), },
         new object[] { SHA256.Create(), },
         new object[] { SHA384.Create(), },
         new object[] { SHA512.Create(), },
         new object[] { Gost3411.Create(), },
         new object[] { Gost3411_2012_256.Create(), },
         new object[] { Gost3411_2012_512.Create(), },
         new object[] { new HMACSHA1(), },
         new object[] { new HMACSHA256(), },
         new object[] { new HMACSHA384(), },
         new object[] { new HMACSHA512(), },
         new object[] { new HMACGost3411(), },
         new object[] { new HMACGost3411_2012_256(), },
         new object[] { new HMACGost3411_2012_512(), },
     });
 }
Ejemplo n.º 4
0
 public sealed override HashAlgorithm CreateDigest()
 {
     return(Gost3411.Create());
 }
Ejemplo n.º 5
0
 protected override HashAlgorithm Create()
 {
     return(Gost3411.Create());
 }
Ejemplo n.º 6
0
        public static object CreateFromKnownName(string name)
        {
            switch (name)
            {
            case "http://www.w3.org/TR/2001/REC-xml-c14n-20010315":
                return(new XmlDsigC14NTransform());

            case "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments":
                return(new XmlDsigC14NWithCommentsTransform());

            case "http://www.w3.org/2001/10/xml-exc-c14n#":
                return(new XmlDsigExcC14NTransform());

            case "http://www.w3.org/2001/10/xml-exc-c14n#WithComments":
                return(new XmlDsigExcC14NWithCommentsTransform());

            case "http://www.w3.org/2000/09/xmldsig#base64":
                return(new XmlDsigBase64Transform());

            case "http://www.w3.org/TR/1999/REC-xpath-19991116":
                return(new XmlDsigXPathTransform());

            case "http://www.w3.org/TR/1999/REC-xslt-19991116":
                return(new XmlDsigXsltTransform());

            case "http://www.w3.org/2000/09/xmldsig#enveloped-signature":
                return(new XmlDsigEnvelopedSignatureTransform());

            case "http://www.w3.org/2002/07/decrypt#XML":
                return(new XmlDecryptionTransform());

            case "urn:mpeg:mpeg21:2003:01-REL-R-NS:licenseTransform":
                return(new XmlLicenseTransform());

            case "http://www.w3.org/2000/09/xmldsig# X509Data":
                return(new KeyInfoX509Data());

            case "http://www.w3.org/2000/09/xmldsig# KeyName":
                return(new KeyInfoName());

            case "http://www.w3.org/2000/09/xmldsig# KeyValue/DSAKeyValue":
                return(new DSAKeyValue());

            case "http://www.w3.org/2000/09/xmldsig# KeyValue/RSAKeyValue":
                return(new RSAKeyValue());

            case "http://www.w3.org/2000/09/xmldsig# RetrievalMethod":
                return(new KeyInfoRetrievalMethod());

            case "http://www.w3.org/2001/04/xmlenc# EncryptedKey":
                return(new KeyInfoEncryptedKey());

            case "http://www.w3.org/2000/09/xmldsig#dsa-sha1":
                return(new DSASignatureDescription());

            case "System.Security.Cryptography.DSASignatureDescription":
                return(new DSASignatureDescription());

            case "http://www.w3.org/2000/09/xmldsig#rsa-sha1":
                return(new RSAPKCS1SHA1SignatureDescription());

            case "System.Security.Cryptography.RSASignatureDescription":
                return(new RSAPKCS1SHA1SignatureDescription());

            case "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256":
                return(new RSAPKCS1SHA256SignatureDescription());

            case "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384":
                return(new RSAPKCS1SHA384SignatureDescription());

            case "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512":
                return(new RSAPKCS1SHA512SignatureDescription());

            // begin: gost
            case "urn://smev-gov-ru/xmldsig/transform":
                return(new XmlDsigSmevTransform());

            // end: gost

            // workarounds for issue https://github.com/dotnet/corefx/issues/16563
            // remove attribute from this method when removing them
            case "http://www.w3.org/2000/09/xmldsig#sha1":
                return(SHA1.Create());

            case "MD5":
                return(MD5.Create());

            case "http://www.w3.org/2001/04/xmldsig-more#hmac-md5":
                return(new HMACMD5());

            case "http://www.w3.org/2001/04/xmlenc#tripledes-cbc":
                return(TripleDES.Create());

            // begin: gost
            case SignedXml.XmlDsigGost3411Url:
#pragma warning disable 612
            //warning CS0612: 'SignedXml.XmlDsigGost3411UrlObsolete' is obsolete
            case SignedXml.XmlDsigGost3411UrlObsolete:
#pragma warning restore 612
                return(Gost3411.Create());

            case SignedXml.XmlDsigGost3411_2012_256Url:
                return(Gost3411_2012_256.Create());

            case SignedXml.XmlDsigGost3411_2012_512Url:
                return(Gost3411_2012_512.Create());

            case SignedXml.XmlDsigGost3410Url:
#pragma warning disable 612
            //warning CS0612: 'SignedXml.XmlDsigGost3410UrlObsolete' is obsolete
            case SignedXml.XmlDsigGost3410UrlObsolete:
#pragma warning restore 612
                return(new GostSignatureDescription());

            case SignedXml.XmlDsigGost3410_2012_256Url:
                return(new Gost2012_256SignatureDescription());

            case SignedXml.XmlDsigGost3410_2012_512Url:
                return(new Gost2012_512SignatureDescription());
                // end: gost
            }

            return(null);
        }