72 lines
2 KiB
C#
72 lines
2 KiB
C#
using MfGames.Cryptography.Extensions;
|
|
using MfGames.Cryptography.Hashes;
|
|
using Xunit;
|
|
|
|
namespace MfGames.Cryptography.Tests;
|
|
|
|
public class CryptographyStringExtensionsTests
|
|
{
|
|
[Fact]
|
|
public void PasswordAsBase64Md5()
|
|
{
|
|
const string Input = "password";
|
|
string? result = Input.ToHashString(HashType.Md5, ByteStringFormat.Base64);
|
|
|
|
Assert.Equal("X03MO1qnZdYdgyfeuILPmQ==", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void PasswordAsBase64Sha512()
|
|
{
|
|
const string Input = "password";
|
|
string? result = Input.ToHashString(HashType.Sha512, ByteStringFormat.Base64);
|
|
|
|
Assert.Equal(
|
|
"sQnzu7wkTrgkQZF+0G1hi5AI3Qmzvv0bXgc5THBqi7mAsdd4Xll27ASbR"
|
|
+ "t9fEyavWi6m0QP9B8lThf+rDKy8hg==",
|
|
result
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
public void PasswordAsLowercaseHexMd5()
|
|
{
|
|
const string Input = "password";
|
|
string? result = Input.ToHashString(HashType.Md5);
|
|
|
|
Assert.Equal("5f4dcc3b5aa765d61d8327deb882cf99", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void PasswordAsLowercaseHexSha512()
|
|
{
|
|
const string Input = "password";
|
|
string? result = Input.ToHashString();
|
|
|
|
Assert.Equal(
|
|
"b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394"
|
|
+ "c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385f"
|
|
+ "fab0cacbc86",
|
|
result
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
public void PasswordAsUppercaseHexMd5()
|
|
{
|
|
const string Input = "password";
|
|
string? result = Input.ToHashString(HashType.Md5, ByteStringFormat.UppercaseHex);
|
|
|
|
Assert.Equal("5F4DCC3B5AA765D61D8327DEB882CF99", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void PasswordAsUppercaseHexSha256()
|
|
{
|
|
const string Input = "password";
|
|
string? result = Input.ToHashString(HashType.Sha256, ByteStringFormat.UppercaseHex);
|
|
|
|
Assert.Equal("5E884898DA28047151D0E56F8DC6292773603D0D6AABBDD62A11EF721D1542D8", result);
|
|
}
|
|
}
|