MD5CngTest.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // MD5Test.cs - NUnit Test Cases for System.Security.Cryptography.MD5
  3. //
  4. // Authors
  5. // Eduardo Garcia Cebollero ([email protected])
  6. // Sebastien Pouliot <[email protected]>
  7. //
  8. // (C) Eduardo Garcia Cebollero.
  9. // (C) Ximian, Inc. http://www.ximian.com
  10. // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
  11. //
  12. using NUnit.Framework;
  13. using System;
  14. using System.Security.Cryptography;
  15. namespace MonoTests.System.Security.Cryptography {
  16. [TestFixture]
  17. public class MD5Test {
  18. private MD5 md5;
  19. [SetUp]
  20. public void SetUp ()
  21. {
  22. md5 = new MD5Cng ();
  23. }
  24. [Test]
  25. public void ComputeHashNull ()
  26. {
  27. byte [] dato_vacio = {};
  28. string MD5_dato_vacio = "d41d8cd98f00b204e9800998ecf8427e";
  29. string result_str = "";
  30. byte [] result = md5.ComputeHash (dato_vacio);
  31. foreach(byte i in result)
  32. result_str += Convert.ToInt32 (i).ToString ("x2");
  33. Assert.AreEqual (result_str, MD5_dato_vacio, "#01 MD5 Of {} is wrong");
  34. }
  35. [Test]
  36. public void ComputeHashA ()
  37. {
  38. byte [] dato_a = { Convert.ToByte ('a') };
  39. string MD5_dato_a = "0cc175b9c0f1b6a831c399e269772661";
  40. string result_str = "";
  41. byte [] result = md5.ComputeHash (dato_a);
  42. foreach (byte i in result)
  43. result_str += Convert.ToInt32 (i).ToString ("x2");
  44. Assert.AreEqual (result_str, MD5_dato_a, "#02 MD5 Of 'a' is wrong");
  45. }
  46. [Test]
  47. public void ComputeHashB ()
  48. {
  49. byte[] dato_b = { Convert.ToByte ('\u00F1') };
  50. string MD5_dato_b = "edb907361219fb8d50279eabab0b83b1";
  51. string result_str = "";
  52. byte[] result = md5.ComputeHash (dato_b);
  53. foreach(byte i in result)
  54. result_str += Convert.ToInt32 (i).ToString ("x2");
  55. Assert.AreEqual (result_str, MD5_dato_b, "#03 MD5 Of '\u00F1' is wrong");
  56. }
  57. }
  58. }