public void Initialize() { byte[] originalHash = defaultHashProvider.CreateHash(this.plainText); KeyedHashAlgorithmProvider hash2 = (KeyedHashAlgorithmProvider)CreateProvider(this.data); Assert.IsTrue(hash2.CompareHash(this.plainText, originalHash)); }
/// <summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// Builds a <see cref="KeyedHashAlgorithmProvider"/> based on an instance of <see cref="KeyedHashAlgorithmProviderData"/>. /// </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="KeyedHashAlgorithmProviderData"/>.</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="KeyedHashAlgorithmProvider"/>.</returns> public IHashProvider Assemble(IBuilderContext context, HashProviderData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { KeyedHashAlgorithmProviderData castedObjectConfiguration = (KeyedHashAlgorithmProviderData)objectConfiguration; IHashProvider createdObject = new KeyedHashAlgorithmProvider( castedObjectConfiguration.AlgorithmType, castedObjectConfiguration.SaltEnabled, castedObjectConfiguration.ProtectedKeyFilename, castedObjectConfiguration.ProtectedKeyProtectionScope); return(createdObject); }
public void SetUp() { // create a new random plain text secret this.plainText = new byte[12]; RNGCryptoServiceProvider.Create().GetNonZeroBytes(this.plainText); this.data = new KeyedHashAlgorithmProviderData(); this.data.Name = "name"; this.data.AlgorithmType = typeof(HMACSHA1).AssemblyQualifiedName; this.data.SaltEnabled = false; this.data.Key = new byte[] { 1, 2, 3, 4 }; this.defaultHashProvider = (KeyedHashAlgorithmProvider)CreateProvider(this.data); }
public void SetUp() { // create a new random plain text secret this.plainText = new byte[12]; RNGCryptoServiceProvider.Create().GetNonZeroBytes(this.plainText); this.data = new KeyedHashAlgorithmProviderData(); this.data.Name = "name"; this.data.AlgorithmType = typeof(HMACSHA1).AssemblyQualifiedName; this.data.SaltEnabled = false; this.data.Key = new byte[] {1, 2, 3, 4}; this.defaultHashProvider = (KeyedHashAlgorithmProvider)CreateProvider(this.data); }