-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
MD5CryptoServiceProviderTests.cs
43 lines (36 loc) · 1.36 KB
/
MD5CryptoServiceProviderTests.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Test.Cryptography;
using Xunit;
namespace System.Security.Cryptography.Encryption.MD5.Tests
{
/// <summary>
/// Since MD5CryptoServiceProvider wraps IncrementalHash from Algorithms assembly, we only test minimally here.
/// </summary>
public class MD5CryptoServiceProviderTests
{
[Fact]
public void MD5_Rfc1321_1()
{
Verify(string.Empty, "d41d8cd98f00b204e9800998ecf8427e");
}
[Fact]
public void MD5_Rfc1321_7()
{
Verify("12345678901234567890123456789012345678901234567890123456789012345678901234567890", "57edf4a22be3c955ac49da2e2107b67a");
}
private void Verify(string rawText, string expected)
{
byte[] inputBytes = ByteUtils.AsciiBytes(rawText);
byte[] expectedBytes = ByteUtils.HexToByteArray(expected);
using (var hash = new MD5CryptoServiceProvider())
{
Assert.True(hash.HashSize > 0);
byte[] actual = hash.ComputeHash(inputBytes, 0, inputBytes.Length);
Assert.Equal(expectedBytes, actual);
actual = hash.Hash;
Assert.Equal(expectedBytes, actual);
}
}
}
}