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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

208<br />

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

Table 20: Cryptography Application Block <strong>Test</strong> Code<br />

ID Scenario <strong>Test</strong> code<br />

1 Hash protected void ButtonHash_Click(object sender, EventArgs e)<br />

plaintext<br />

and byte[] b = new byte[Int32.Parse(TextBox1.Text)];<br />

{<br />

compare<br />

byte[] hs=Cryptographer.CreateHash(ddlSymmetricProvider.SelectedValue,<br />

strEncryptedText);<br />

hashed<br />

Cryptographer.CompareHash("ddlSymmetricProvider.SelectedValue,<br />

value with<br />

b, hs);<br />

plaintext. // Optionally, the factory is created<br />

// instead of using the static CreateHash CompareHash.<br />

HashProviderFactory factory = new HashProviderFactory();<br />

IHashProvider hashProvider = factory.Create(ddlSymmetricProvide<br />

r.SelectedValue);<br />

hashProvider.CreateHash(b);<br />

HashProviderFactory factory = new HashProviderFactory();<br />

IHashProvider hashProvider = factory.Create(ddlSymmetricProvide<br />

r.SelectedValue);<br />

hashProvider.CompareHash(b);<br />

}<br />

23 Encrypt<br />

and<br />

decrypt<br />

plaintext<br />

with a<br />

symmetric<br />

algorithm<br />

provider.<br />

protected void ButtonCrypto_Click(object sender, EventArgs e)<br />

{<br />

// The size of the byte array is read<br />

// from the text box.<br />

byte[] b = new byte[long.Parse(TextBox1.Text)];<br />

// The factory is created for each iteration.<br />

// The static EncryptSymmetric method creates the factory.<br />

byte[] enc = =Cryptographer.EncryptSymmetric(ddlSymmetric<br />

Provider.SelectedValue b);<br />

ISymmetricCryptoProvider symmprovider =<br />

factory.Create(ddlSymmetricProvider.SelectedValue);<br />

Cryptographer.DecryptSymmetric(ddlSymmetricProvider.Selected-<br />

Value, enc);<br />

// Or, optionally, the factory is created.<br />

SymmetricCryptoProviderFactory factoryEncrypt = new<br />

SymmetricCryptoProviderFactory();<br />

byte[] result = symmprovider.Encrypt(b);<br />

SymmetricCryptoProviderFactory factoryDecrypt = new<br />

SymmetricCryptoProviderFactory();<br />

byte[] result = symmprovider.Decrypt(b);<br />

}<br />

Table 21 lists the .NET Framework test code.

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

Saved successfully!

Ooh no, something went wrong!