07.11.2014 Views

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

54<br />

<strong>Enterprise</strong> <strong>Library</strong> <strong>Test</strong> <strong>Guide</strong><br />

<strong>Test</strong> case Result Automated test<br />

Verify that a<br />

provider that is<br />

configured with<br />

data in a dictionary<br />

configuration<br />

source can encrypt<br />

Passed This example uses a dictionary as the configuration source<br />

for a hash provider. The following code shows the dictionary<br />

configuration source.<br />

DictionaryConfigurationSource section = new DictionaryConfigurationSource();<br />

CryptographySettings setting = new Cryptographydata.<br />

Settings();<br />

setting.HashProviders.Add(new Has<br />

hAlgorithmProviderData("SHA512ManagedWithNoS<br />

alt",Type.GetType("System.Security.Cryptography.SHA512Managed,<br />

mscorlib, Version=2.0.0.0,<br />

Culture=neutral, PublicKeyToken=b77a5c561934e089<br />

"), false));<br />

section.Add("securityCryptographyConfiguration",<br />

setting);<br />

The following is the test case.<br />

[<strong>Test</strong>Method]<br />

public void <strong>Test</strong>HashingWithDicSource()<br />

{<br />

HashProviderFactory factory = new HasProviderFac<br />

tory(section);<br />

IHashProvider provider = (IHashProvider)factory.<br />

Create("SHA512ManagedWithNoSalt");<br />

byte[] hash = provider.CreateHash(PlainByteMessa<br />

ge);<br />

Assert.IsTrue(provider.CompareHash(P<br />

lainByteMessage, hash));<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!