Пример #1
0
        // Create a signature deformatter for DSA decryption.
        public static AsymmetricSignatureDeformatter CreateDSADeformatter(DSA dsa)
        {
            // Create a DSA signature deformatter to verify the signature.
            SignatureDescription signatureDescription = new SignatureDescription();

            signatureDescription.DeformatterAlgorithm = "System.Security.Cryptography.DSASignatureDeformatter";

            AsymmetricSignatureDeformatter asymmetricDeformatter = signatureDescription.CreateDeformatter(dsa);

            Console.WriteLine("\nCreated deformatter : " + asymmetricDeformatter.ToString());
            return(asymmetricDeformatter);
        }
        public void DSASignatureDescription()
        {
            // internal class - we cannot create one without CryptoConfig
            SignatureDescription sd = (SignatureDescription)CryptoConfig.CreateFromName("http://www.w3.org/2000/09/xmldsig#dsa-sha1");

            Assert.AreEqual("System.Security.Cryptography.SHA1CryptoServiceProvider", sd.DigestAlgorithm);
            Assert.AreEqual("System.Security.Cryptography.DSASignatureDeformatter", sd.DeformatterAlgorithm);
            Assert.AreEqual("System.Security.Cryptography.DSASignatureFormatter", sd.FormatterAlgorithm);
            Assert.AreEqual("System.Security.Cryptography.DSACryptoServiceProvider", sd.KeyAlgorithm);

            HashAlgorithm hash = sd.CreateDigest();

            Assert.AreEqual("System.Security.Cryptography.SHA1CryptoServiceProvider", hash.ToString());

            Assert.AreEqual(dsa.ToString(), sd.KeyAlgorithm);

            AsymmetricSignatureDeformatter asd = sd.CreateDeformatter(dsa);

            Assert.AreEqual("System.Security.Cryptography.DSASignatureDeformatter", asd.ToString());

            AsymmetricSignatureFormatter asf = sd.CreateFormatter(dsa);

            Assert.AreEqual("System.Security.Cryptography.DSASignatureFormatter", asf.ToString());
        }
        void RSASignatureDescriptionCore(string name, string expectedDigestAlgorithm, string expectedSelectedDigestAlgorithm)
        {
            // internal class - we cannot create one without CryptoConfig
            SignatureDescription sd = (SignatureDescription)CryptoConfig.CreateFromName(name);

            Assert.AreEqual(expectedDigestAlgorithm, sd.DigestAlgorithm);
            Assert.AreEqual("System.Security.Cryptography.RSAPKCS1SignatureDeformatter", sd.DeformatterAlgorithm);
            Assert.AreEqual("System.Security.Cryptography.RSAPKCS1SignatureFormatter", sd.FormatterAlgorithm);
            Assert.AreEqual("System.Security.Cryptography.RSA", sd.KeyAlgorithm);

            HashAlgorithm hash = sd.CreateDigest();

            Assert.AreEqual(expectedSelectedDigestAlgorithm, hash.ToString());

            Assert.AreEqual("System.Security.Cryptography.RSA", sd.KeyAlgorithm);

            AsymmetricSignatureDeformatter asd = sd.CreateDeformatter(rsa);

            Assert.AreEqual("System.Security.Cryptography.RSAPKCS1SignatureDeformatter", asd.ToString());

            AsymmetricSignatureFormatter asf = sd.CreateFormatter(rsa);

            Assert.AreEqual("System.Security.Cryptography.RSAPKCS1SignatureFormatter", asf.ToString());
        }