MD5CngTest.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #if !MOBILE
  13. using NUnit.Framework;
  14. using System;
  15. using System.Security.Cryptography;
  16. namespace MonoTests.System.Security.Cryptography {
  17. [TestFixture]
  18. public class MD5Test {
  19. private MD5 md5;
  20. [SetUp]
  21. public void SetUp ()
  22. {
  23. md5 = new MD5Cng ();
  24. }
  25. [Test]
  26. public void ComputeHashNull ()
  27. {
  28. byte [] dato_vacio = {};
  29. string MD5_dato_vacio = "d41d8cd98f00b204e9800998ecf8427e";
  30. string result_str = "";
  31. byte [] result = md5.ComputeHash (dato_vacio);
  32. foreach(byte i in result)
  33. result_str += Convert.ToInt32 (i).ToString ("x2");
  34. Assert.AreEqual (result_str, MD5_dato_vacio, "#01 MD5 Of {} is wrong");
  35. }
  36. [Test]
  37. public void ComputeHashA ()
  38. {
  39. byte [] dato_a = { Convert.ToByte ('a') };
  40. string MD5_dato_a = "0cc175b9c0f1b6a831c399e269772661";
  41. string result_str = "";
  42. byte [] result = md5.ComputeHash (dato_a);
  43. foreach (byte i in result)
  44. result_str += Convert.ToInt32 (i).ToString ("x2");
  45. Assert.AreEqual (result_str, MD5_dato_a, "#02 MD5 Of 'a' is wrong");
  46. }
  47. [Test]
  48. public void ComputeHashB ()
  49. {
  50. byte[] dato_b = { Convert.ToByte ('\u00F1') };
  51. string MD5_dato_b = "edb907361219fb8d50279eabab0b83b1";
  52. string result_str = "";
  53. byte[] result = md5.ComputeHash (dato_b);
  54. foreach(byte i in result)
  55. result_str += Convert.ToInt32 (i).ToString ("x2");
  56. Assert.AreEqual (result_str, MD5_dato_b, "#03 MD5 Of '\u00F1' is wrong");
  57. }
  58. }
  59. }
  60. #endif