public void HashHMACSHA1FailsUsingHashAlgorithmProvider()
 {
     HashAlgorithmProviderData keyData = new HashAlgorithmProviderData();
     keyData.AlgorithmType = typeof(HMACSHA1).AssemblyQualifiedName;
     keyData.SaltEnabled = false;
     keyData.Name = "BadHMACSHA1";
     IHashProvider hashProvider = new HashAlgorithmProvider();
     hashProvider.Initialize(new TestCryptographyConfigurationView(keyData));
     hashProvider.CreateHash(plainText);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds a <see cref="HashAlgorithmProvider"/> based on an instance of <see cref="HashAlgorithmProviderData"/>.
        /// </summary>
        /// <seealso cref="HashProviderCustomFactory"/>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="HashAlgorithmProviderData"/>.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of <see cref="HashAlgorithmProvider"/>.</returns>
        public IHashProvider Assemble(IBuilderContext context, HashProviderData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            HashAlgorithmProviderData castedObjectConfiguration
                = (HashAlgorithmProviderData)objectConfiguration;

            IHashProvider createdObject
                = new HashAlgorithmProvider(
                      castedObjectConfiguration.AlgorithmType,
                      castedObjectConfiguration.SaltEnabled);

            return(createdObject);
        }
        protected override void Arrange()
        {
            updatableConfigurationSource = new ConfigurationSourceUpdatable();
            cryptoSettings = new CryptographySettings();

            hashProvider = new HashAlgorithmProviderData("hash provider", typeof(MD5), true);
            cryptoSettings.HashProviders.Add(hashProvider);
            cryptoSettings.DefaultHashProviderName = hashProvider.Name;

            symmetricAlgorithmProvider = new CustomSymmetricCryptoProviderData("symm provider", typeof(MockCustomSymmetricProvider));
            cryptoSettings.SymmetricCryptoProviders.Add(symmetricAlgorithmProvider);
            cryptoSettings.DefaultSymmetricCryptoProviderName = symmetricAlgorithmProvider.Name;
            updatableConfigurationSource.Add(CryptographySettings.SectionName, cryptoSettings);

            container = new UnityContainer();
            containerConfigurator = new UnityContainerConfigurator(container);
            EnterpriseLibraryContainer.ConfigureContainer(containerConfigurator, updatableConfigurationSource);
        }
 public void HashWithBadType()
 {
     HashAlgorithmProviderData data = new HashAlgorithmProviderData();
     data.AlgorithmType = "bad type";
     data.Name = "bad";
     IHashProvider hashProvider = new HashAlgorithmProvider();
     hashProvider.Initialize(new TestCryptographyConfigurationView(data));
     hashProvider.CreateHash(plainText);
 }