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.

248<br />

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

the connection string without including sensitive information such as the password.<br />

The following is the modified code.<br />

protected internal string ConnectionString<br />

{<br />

get<br />

{<br />

return this.connectionString.ToString();<br />

}<br />

}<br />

public string ConnectionStringWithoutCredentials<br />

{<br />

get<br />

{<br />

return ConnectionStringNoCredentials;<br />

}<br />

}<br />

Verification<br />

Running the test case again after modifying the code verified that the Connection-<br />

StringWithoutCredentials property did not return the password.<br />

<strong>Test</strong>ing the Cryptography Application Block<br />

This test case determined whether the Cryptography Application Block cleared a<br />

decrypted key from memory after using it to encrypt and decrypt data.<br />

<strong>Test</strong> Case<br />

During a code review, the SymmetricCryptographer and HashCryptographer classes<br />

were examined to see if they cleared decrypted keys from memory after using them.<br />

Problem<br />

The code review revealed that the SymmeticCryptographer and HashCryptographer<br />

classes did not clear decrypted keys from memory before returning the data. The following<br />

code shows the SymmetricCryptographer code. The code for the HashCryptographer<br />

class was similar.<br />

public byte[] Decrypt(byte[] encryptedText)<br />

{<br />

byte[] output = null;<br />

byte[] data = ExtractIV(encryptedText);<br />

this.algorithm.Key = Key;<br />

using (ICryptoTransform transform = this.algorithm.CreateDecryptor())<br />

{<br />

output = Transform(transform, data);<br />

}<br />

return output;<br />

}

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

Saved successfully!

Ooh no, something went wrong!