File: MD5CngTest.cs

package info (click to toggle)
mono 2.6.7-5.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 327,344 kB
  • ctags: 413,649
  • sloc: cs: 2,471,883; xml: 1,768,594; ansic: 350,665; sh: 13,644; makefile: 8,640; perl: 1,784; asm: 717; cpp: 209; python: 146; sql: 81; sed: 16
file content (73 lines) | stat: -rw-r--r-- 1,743 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// MD5Test.cs - NUnit Test Cases for System.Security.Cryptography.MD5
// 
// Authors
//	Eduardo Garcia Cebollero (kiwnix@yahoo.es)
//	Sebastien Pouliot  <sebastien@ximian.com>
//
// (C)  Eduardo Garcia Cebollero.
// (C)  Ximian, Inc.  http://www.ximian.com
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//

using NUnit.Framework;
using System;
using System.Security.Cryptography;

namespace MonoTests.System.Security.Cryptography {

	[TestFixture]
	public class MD5Test {

		private MD5 md5;

		[SetUp]
		public void SetUp ()
		{
			md5 = new MD5Cng ();
		}

		[Test]
		public void ComputeHashNull () 
		{
			byte [] dato_vacio = {};
			string MD5_dato_vacio = "d41d8cd98f00b204e9800998ecf8427e";

			string result_str = "";
			
			byte [] result = md5.ComputeHash (dato_vacio);
			
			foreach(byte i in result)
				result_str += Convert.ToInt32 (i).ToString ("x2");

			Assert.AreEqual (result_str, MD5_dato_vacio, "#01 MD5 Of {} is wrong");
		}

		[Test]
		public void ComputeHashA ()
		{
			byte [] dato_a = { Convert.ToByte ('a') };
			string MD5_dato_a = "0cc175b9c0f1b6a831c399e269772661";
			string result_str = "";
			byte [] result = md5.ComputeHash (dato_a);
			foreach (byte i in result)
				result_str += Convert.ToInt32 (i).ToString ("x2");

			Assert.AreEqual (result_str, MD5_dato_a, "#02 MD5 Of 'a' is wrong");
		}

		[Test]
		public void ComputeHashB ()
		{
			byte[] dato_b = { Convert.ToByte ('\u00F1') };
			string MD5_dato_b = "edb907361219fb8d50279eabab0b83b1";
			string result_str = "";

			byte[] result = md5.ComputeHash (dato_b);
			foreach(byte i in result)
				result_str += Convert.ToInt32 (i).ToString ("x2");

			Assert.AreEqual (result_str, MD5_dato_b, "#03 MD5 Of '\u00F1' is wrong");
		}
	}
}