namespace MonoTests.System.Security.Cryptography {
-#if NET_2_0
public class HS160 : HMACSHA1 {
public int BlockSize {
set { base.BlockSizeValue = value; }
}
}
-#endif
// References:
// a. The Keyed-Hash Message Authentication Code (HMAC)
Assert.AreEqual ("System.Security.Cryptography.HMACSHA1", algo.ToString (), "HMACSHA1.ToString()");
}
-#if NET_2_0
[Test]
public void BlockSize ()
{
HS160 hmac = new HS160 ();
Assert.AreEqual (64, hmac.BlockSize, "BlockSizeValue");
}
-#else
- // this is legal in .NET 2.0 because HMACSHA1 derives from HMAC
- [Test]
- [ExpectedException (typeof (InvalidCastException))]
- public void InvalidHashName ()
- {
- algo = new HMACSHA1 ();
- algo.HashName = "MD5";
- byte[] data = Encoding.Default.GetBytes ("MD5");
- byte[] hmac = algo.ComputeHash (data);
- }
-#endif
public void Check (string testName, byte[] key, byte[] data, byte[] result)
{
public void CheckA (string testName, byte[] key, byte[] data, byte[] result)
{
-#if NET_2_0
algo = new HMACSHA1 (key, true);
-#else
- algo = new HMACSHA1 (key);
-#endif
byte[] hmac = algo.ComputeHash (data);
Assert.AreEqual (result, hmac, testName + "a1");
Assert.AreEqual (result, algo.Hash, testName + "a2");
public void CheckB (string testName, byte[] key, byte[] data, byte[] result)
{
-#if NET_2_0
algo = new HMACSHA1 (key, false);
-#else
- algo = new HMACSHA1 (key);
-#endif
byte[] hmac = algo.ComputeHash (data, 0, data.Length);
Assert.AreEqual (result, hmac, testName + "b1");
Assert.AreEqual (result, algo.Hash, testName + "b2");