예제 #1
0
 /// <summary>
 ///     Utility method to assist in making sure a set of mappings are correctly registered in CryptoConfig2
 /// </summary>
 private static void CheckMappings(IEnumerable <Mapping> mappings)
 {
     foreach (Mapping mapping in mappings)
     {
         object algorithm = CryptoConfig2.CreateFromName(mapping.Name);
         Assert.IsNotNull(algorithm, "Failed to create algorithm in CryptoConfig2 for " + mapping.Name);
         Assert.AreEqual(mapping.ExpectedType, algorithm.GetType(), "Failed to map CryptoConfig2 for " + mapping.Name);
     }
 }
예제 #2
0
        public void CryptoConfig2CreateFactoryTest()
        {
            // Test that getting an AES factory can produce a delegate for AES types
            Func <object> aesFactory = CryptoConfig2.CreateFactoryFromName("AES");
            Aes           aes        = aesFactory() as Aes;

            Assert.IsNotNull(aes);

            // Ensure the type is the same as the CreateFromName type
            Aes createdAes = CryptoConfig2.CreateFromName("AES") as Aes;

            Assert.AreEqual(createdAes.GetType(), aes.GetType());

            // Ensure the factory returns different instances each time
            Aes aes2 = aesFactory() as Aes;

            Assert.IsNotNull(aes2);
            Assert.AreNotSame(aes, aes2);
        }
예제 #3
0
        public void CryptoConfig2OldNameMapTest()
        {
            Mapping[] cryptoConfigMappings = new Mapping[]
            {
                // Just provide a few selections from mscorlib's crypto config mappings to ensure that they
                // are all working as we expect
                new Mapping {
                    Name = "RSA", ExpectedType = typeof(RSACryptoServiceProvider)
                },
                new Mapping {
                    Name = "System.Security.Cryptography.RSACryptoServiceProvider", ExpectedType = typeof(RSACryptoServiceProvider)
                },
                new Mapping {
                    Name = "System.Security.Cryptography.SHA1Managed", ExpectedType = typeof(SHA1Managed)
                }
            };

            foreach (Mapping mapping in cryptoConfigMappings)
            {
                object algorithm = CryptoConfig2.CreateFromName(mapping.Name);
                Assert.IsNotNull(algorithm, "Failed to create algorithm in CryptoConfig for " + mapping.Name);
                Assert.AreEqual(mapping.ExpectedType, algorithm.GetType(), "Failed to map CryptoConfig for " + mapping.Name);
            }
        }