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.

50<br />

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

Code test case Implemented? Feature that is implemented<br />

Verify that the<br />

application block<br />

can either use an<br />

absolute path or<br />

a relative path to<br />

read the key file.<br />

Yes<br />

In the configuration source, the ProtectedKeyFilename<br />

property supports both relative and absolute paths.<br />

This is shown in the following configuration example.<br />

<br />

<br />

Verify that the<br />

application block<br />

validates the input<br />

at all the entry<br />

points, such as<br />

the Cryptographer<br />

façade.<br />

Verify that the<br />

application block<br />

reads the symmetric<br />

key only once<br />

from the input<br />

stream and then<br />

caches it so that<br />

it can be used for<br />

the cryptography<br />

operations.<br />

Verify that the<br />

symmetric key is<br />

cached in memory<br />

in a thread safe<br />

manner.<br />

Yes<br />

Yes<br />

Yes<br />

<br />

<br />

The following code is an example of how the application<br />

block checks whether the input is valid. If the<br />

input is invalid, the application block throws an exception.<br />

public static string DecryptSymmetric(string<br />

symmetricInstance, string ciphertextBase64)<br />

{<br />

if (string.IsNullOrEmpty(symmetricInstance))<br />

throw new ArgumentException(…);<br />

if (string.IsNullOrEmpty(ciphertextBase64))<br />

throw new ArgumentException(…);<br />

}<br />

The KeyManager.Read method reads an encrypted<br />

key from the input stream and then caches it. This is<br />

shown in the following code example.<br />

public static ProtectedKey Read(…)<br />

{<br />

if (cache[completeFileName] != null)<br />

return cache[completeFileName];<br />

}<br />

The ProtectedKeyCache class locks the cache before<br />

it stores the key. This is shown in the following code<br />

example.<br />

public ProtectedKey this[string keyFileName]<br />

{<br />

set<br />

{<br />

lock (cache)<br />

{<br />

cache[keyFileName] = value;<br />

}<br />

}<br />

}

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

Saved successfully!

Ooh no, something went wrong!