Enterprise Library Test Guide - Willy .Net
Enterprise Library Test Guide - Willy .Net
Enterprise Library Test Guide - Willy .Net
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
46<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 />
Cryptographer<br />
façade uses the<br />
SymmetricCryptoProviderFactory<br />
class and the<br />
HashProviderFactory<br />
class to create<br />
the cryptography<br />
providers.<br />
Yes<br />
The client code calls static methods on the Cryptographer<br />
class to create hashes, compare hashes, encrypt<br />
data, and decrypt data. Each static method instantiates<br />
a factory class and passes the configuration<br />
source to the factory class’s constructor. The factory<br />
uses the configuration data to determine the type of<br />
provider to create. The following code demonstrates<br />
how the Cryptographer.EncryptSymmetric method<br />
calls the SymmetricCryptoProviderFactory class to<br />
create a symmetric provider. The process is similar for<br />
hash providers.<br />
public static byte[] EncryptSymmetric(string<br />
symmetricInstance, byte[] plaintext)<br />
{<br />
…<br />
SymmetricCryptoProviderFactory factory = new<br />
SymmetricCryptoProviderFactory(ConfigurationSo<br />
urceFactory.Create());<br />
…<br />
}<br />
Verify that assembler<br />
classes<br />
that implement<br />
the IAssembler<br />
interface create<br />
the symmetric and<br />
hash providers,<br />
and inject the configuration<br />
object<br />
values into those<br />
domain objects.<br />
Yes<br />
The following code demonstrates how the SymmetricAlgorithmProviderAssember<br />
class, which implements<br />
the IAssembler interface, creates a symmetric<br />
provider. The process is similar for hash providers.<br />
public class SymmetricAlgorithmProviderAssembler<br />
: IAssembler<br />
{<br />
public ISymmetricCryptoProvider<br />
Assemble(IBuilderContext context, SymmetricProviderData<br />
objectConfiguration, IConfigurationSource<br />
configurationSource, ConfigurationReflectionCache<br />
reflectionCache)<br />
{<br />
SymmetricAlgorithmProviderData castedObject-<br />
Configuration = (SymmetricAlgorithmProviderDat<br />
a)objectConfiguration;<br />
ISymmetricCryptoProvider createdObject = new<br />
SymmetricAlgorithmProvider(castedObjectConfigu<br />
ration.AlgorithmType,<br />
castedObjectConfiguration.ProtectedKeyFilename<br />
,castedObjectConfiguration.ProtectedKeyProtectionScope);<br />
return createdObject;<br />
}<br />
}