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.

148<br />

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

Check<br />

Yes<br />

Description<br />

Clear sensitive data from memory as soon as possible. The Cryptography Application<br />

Block byte arrays contain unencrypted keys. The application block clears them from<br />

memory as soon as it uses them. The following example shows how the application<br />

block uses a key and then removes it.<br />

public byte[] Encrypt(byte[] plaintext)<br />

{<br />

byte[] output = null;<br />

byte[] cipherText = null;<br />

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

using (ICryptoTransform transform =<br />

this.algorithm.CreateEncryptor())<br />

{<br />

cipherText = Transform(transform, plaintext);<br />

}<br />

output = new byte[IVLength + cipherText.Length];<br />

Buffer.BlockCopy(this.algorithm.IV, 0, output, 0,<br />

IVLength);<br />

Buffer.BlockCopy(cipherText, 0, output, IVLength,<br />

cipherText.Length);<br />

CryptographyUtility.ZeroOutBytes(this.algorithm.Key);<br />

}<br />

return output;<br />

public static void ZeroOutBytes(byte[] bytes)<br />

{<br />

if (bytes == null)<br />

{<br />

return;<br />

}<br />

Array.Clear(bytes, 0, bytes.Length);<br />

}<br />

Exception Management Checklist<br />

Table 36 lists the general exception management recommendations.

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

Saved successfully!

Ooh no, something went wrong!