|
1 | 1 | using System;
|
2 |
| -using System.Collections.Generic; |
3 |
| -using System.IO; |
4 |
| -using System.Security.Cryptography; |
5 | 2 |
|
6 | 3 | namespace Padding_Oracle_Attack
|
7 | 4 | {
|
| 5 | + using static ByteUtils; |
| 6 | + |
8 | 7 | class PaddingOracleAttack
|
9 | 8 | {
|
10 | 9 | private static RemoteServerMock server = new RemoteServerMock();
|
| 10 | + |
11 | 11 | public static void Main()
|
12 | 12 | {
|
13 | 13 | string hiddenMessage = "I'd just like to interject for a moment. What you’re referring to as Linux, is in fact, GNU/Linux, or as I’ve recently taken to calling it, GNU plus Linux.";
|
14 | 14 |
|
15 |
| - using (Aes aes = Aes.Create()) |
16 |
| - { |
17 |
| - byte[] encrypted = server.Encrypt(hiddenMessage); |
18 |
| - var blocks = sliceBytesIntoBlocks(encrypted); |
19 |
| - |
20 |
| - Console.WriteLine("Plaintext:\n{0}", hiddenMessage); |
21 |
| - Console.WriteLine("\nCiphertext:\n{0}", String.Join("\n", blocks.ConvertAll(block => Convert.ToBase64String(block)))); |
22 |
| - Console.WriteLine("\nAttack results:\nTODO"); |
23 |
| - |
24 |
| - encrypted[encrypted.Length - 1] = 22; |
| 15 | + byte[] encrypted = server.Encrypt(hiddenMessage); |
| 16 | + var blocks = sliceBytesIntoBlocks(encrypted); |
25 | 17 |
|
26 |
| - Console.WriteLine("\nPadding is {0}", server.IsPaddingCorrect(encrypted) ? "correct" : "incorrect"); |
27 |
| - } |
28 |
| - } |
29 |
| - |
30 |
| - static List<byte[]> sliceBytesIntoBlocks(byte[] bytes, int blockSizeBytes = 16) |
31 |
| - { |
32 |
| - var blocks = new List<byte[]>(); |
| 18 | + Console.WriteLine("Plaintext:\n{0}", hiddenMessage); |
| 19 | + Console.WriteLine("\nCiphertext:\n{0}", String.Join("\n", blocks.ConvertAll(block => Convert.ToBase64String(block)))); |
| 20 | + Console.WriteLine("\nAttack results:\nTODO"); |
33 | 21 |
|
34 |
| - for (var i = 0; i < bytes.Length; i += blockSizeBytes) |
35 |
| - { |
36 |
| - byte[] block = new byte[blockSizeBytes]; |
37 |
| - Array.Copy(bytes, i, block, 0, blockSizeBytes); |
38 |
| - blocks.Add(block); |
39 |
| - } |
| 22 | + encrypted[encrypted.Length - 1] = 22; |
40 | 23 |
|
41 |
| - return blocks; |
| 24 | + Console.WriteLine("\nPadding is {0}", server.IsPaddingCorrect(encrypted) ? "correct" : "incorrect"); |
42 | 25 | }
|
43 | 26 | }
|
44 | 27 | }
|
0 commit comments