2018-07-16 20:20:29 +00:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2015-12-26 22:44:43 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Security;
|
|
|
|
|
|
|
|
|
|
namespace DSInternals.Common.Cryptography.Test
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class NTHashTester
|
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
2016-07-15 16:10:55 +00:00
|
|
|
|
public void NTHash_SecureString_EmptyInput()
|
2015-12-26 22:44:43 +00:00
|
|
|
|
{
|
|
|
|
|
SecureString password = string.Empty.ToSecureString();
|
|
|
|
|
string result = NTHash.ComputeHash(password).ToHex(true);
|
|
|
|
|
string expected = "31D6CFE0D16AE931B73C59D7E0C089C0";
|
|
|
|
|
Assert.AreEqual(expected, result);
|
|
|
|
|
}
|
2016-07-15 16:10:55 +00:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void NTHash_String_EmptyInput()
|
|
|
|
|
{
|
|
|
|
|
string result = NTHash.ComputeHash(string.Empty).ToHex(true);
|
|
|
|
|
string expected = "31D6CFE0D16AE931B73C59D7E0C089C0";
|
|
|
|
|
Assert.AreEqual(expected, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
[ExpectedException(typeof(ArgumentNullException))]
|
|
|
|
|
public void NTHash_SecureString_NullInput()
|
|
|
|
|
{
|
|
|
|
|
NTHash.ComputeHash((SecureString)null);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-26 22:44:43 +00:00
|
|
|
|
[TestMethod]
|
|
|
|
|
[ExpectedException(typeof(ArgumentNullException))]
|
2016-07-15 16:10:55 +00:00
|
|
|
|
public void NTHash_String_NullInput()
|
2015-12-26 22:44:43 +00:00
|
|
|
|
{
|
2016-07-15 16:10:55 +00:00
|
|
|
|
NTHash.ComputeHash((string)null);
|
2015-12-26 22:44:43 +00:00
|
|
|
|
}
|
2016-07-15 16:10:55 +00:00
|
|
|
|
|
2015-12-26 22:44:43 +00:00
|
|
|
|
[TestMethod]
|
|
|
|
|
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
2016-07-15 16:10:55 +00:00
|
|
|
|
public void NTHash_SecureString_LongInput()
|
2015-12-26 22:44:43 +00:00
|
|
|
|
{
|
|
|
|
|
SecureString password = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789".ToSecureString();
|
|
|
|
|
string result = NTHash.ComputeHash(password).ToHex(true);
|
|
|
|
|
}
|
2016-07-15 16:10:55 +00:00
|
|
|
|
|
2018-07-16 20:20:29 +00:00
|
|
|
|
[TestMethod]
|
|
|
|
|
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
|
|
|
|
public void NTHash_String_LongInput()
|
|
|
|
|
{
|
|
|
|
|
string password = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
|
|
|
|
|
string result = NTHash.ComputeHash(password).ToHex(true);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-26 22:44:43 +00:00
|
|
|
|
[TestMethod]
|
2016-07-15 16:10:55 +00:00
|
|
|
|
public void NTHash_SecureString_TestVector1()
|
2015-12-26 22:44:43 +00:00
|
|
|
|
{
|
|
|
|
|
SecureString password = "Pa$$w0rd".ToSecureString();
|
|
|
|
|
string result = NTHash.ComputeHash(password).ToHex(true);
|
|
|
|
|
string expected = "92937945B518814341DE3F726500D4FF";
|
|
|
|
|
Assert.AreEqual(expected, result);
|
|
|
|
|
}
|
2016-07-15 16:10:55 +00:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void NTHash_String_TestVector1()
|
|
|
|
|
{
|
|
|
|
|
string result = NTHash.ComputeHash("Pa$$w0rd").ToHex(true);
|
|
|
|
|
string expected = "92937945B518814341DE3F726500D4FF";
|
|
|
|
|
Assert.AreEqual(expected, result);
|
|
|
|
|
}
|
2018-07-19 11:23:36 +00:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void NTHash_GenerateRandom()
|
|
|
|
|
{
|
|
|
|
|
byte[] randomHash1 = NTHash.GetRandom();
|
|
|
|
|
byte[] randomHash2 = NTHash.GetRandom();
|
|
|
|
|
|
|
|
|
|
// Check hash size
|
|
|
|
|
Assert.AreEqual(NTHash.HashSize, randomHash1.Length);
|
|
|
|
|
|
|
|
|
|
// Check that the hashes are not the same
|
|
|
|
|
Assert.AreNotEqual(randomHash1.ToHex(), randomHash2.ToHex());
|
|
|
|
|
}
|
2015-12-26 22:44:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|