25.12.2014 Views

Analysis and Evaluation of the Windows Event Log - Bill Buchanan

Analysis and Evaluation of the Windows Event Log - Bill Buchanan

Analysis and Evaluation of the Windows Event Log - Bill Buchanan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Barrie Codona, BSc (Hons) Network Computing, 2007<br />

// The following code is from ‘Public Key RSA Encryption<br />

// in C# .NET’ by Ma<strong>the</strong>w John Schlabaugh.<br />

// Available from <strong>the</strong> http://www.codeproject.com<br />

// Specify <strong>the</strong> size <strong>of</strong> <strong>the</strong> key to be used in bits.<br />

int dwKeySize = 1024;<br />

// Decalre a new instance <strong>of</strong> <strong>the</strong> RSACryptoServiceProvider.<br />

RSACryptoServiceProvider RSAProvider = new<br />

RSACryptoServiceProvider(dwKeySize);<br />

// Read <strong>the</strong> Servers public key from XML.<br />

RSAProvider.FromXmlString(justPublicKey);<br />

// Convert keysize from bits to bytes.<br />

int keySize = dwKeySize / 8;<br />

// Convert message to bytes.<br />

byte[] bytes = Encoding.UTF32.GetBytes(chkMessage);<br />

// Define a size that will be used for calculating a block size.<br />

int maxLength = keySize - 42;<br />

int dataLength = bytes.Length;<br />

int iterations = dataLength / maxLength;<br />

StringBuilder stringBuilder = new StringBuilder();<br />

for (int i = 0; i <br />

maxLength) maxLength : dataLength - maxLength * i];<br />

// Copy <strong>the</strong> smaller message into memory.<br />

Buffer.BlockCopy(bytes, maxLength * i, tempBytes, 0,<br />

tempBytes.Length);<br />

// Encrypt <strong>the</strong> smaller message/section.<br />

byte[] encryptedBytes = RSAProvider.Encrypt(tempBytes, true);<br />

}<br />

// Add <strong>the</strong> encrypted secion to <strong>the</strong> StringBuilder.<br />

stringBuilder.Append(Convert.ToBase64String(encryptedBytes));<br />

5.2.6 Sending to Server<br />

Figure 24: Encrypting Data<br />

For <strong>the</strong> client to be able to send any data to <strong>the</strong> data archiving system it will have to<br />

converted into packet <strong>and</strong> <strong>the</strong>n placed onto <strong>the</strong> TCP stream. Figure 25 shows this.<br />

// Send <strong>the</strong> encrypted message to <strong>the</strong> Server.<br />

server.Send(Encoding.ASCII.GetBytes(encryptedMessage));<br />

// Specify <strong>the</strong> packet size.<br />

Byte[] data = new byte[10240];<br />

// Receive <strong>the</strong> acknowledgement from <strong>the</strong> Server.<br />

int recv = server.Receive(data);<br />

// Convert <strong>the</strong> recieved message to a string.<br />

String stringData = Encoding.ASCII.GetString(data, 0, recv);<br />

Figure 25: Sending Data to a Server<br />

44

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

Saved successfully!

Ooh no, something went wrong!