style: clean code

This commit is contained in:
Fu Diwei
2022-11-09 23:02:53 +08:00
parent 0bf69a19a9
commit e5100effeb
10 changed files with 268 additions and 179 deletions

View File

@@ -7,7 +7,40 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Utilities
/// <summary>
/// SM3 算法工具类。
/// </summary>
public static class SM3Utility
public static partial class SM3Utility
{
/// <summary>
/// 获取 SM3 哈希值。
/// </summary>
/// <param name="bytes">信息字节数组。</param>
/// <returns>哈希字节数组。</returns>
public static byte[] Hash(byte[] bytes)
{
if (bytes == null) throw new ArgumentNullException(nameof(bytes));
SM3Digest sm3 = new SM3Digest();
sm3.BlockUpdate(bytes, 0, bytes.Length);
byte[] hashBytes = new byte[sm3.GetDigestSize()];
sm3.DoFinal(hashBytes, 0);
return hashBytes;
}
/// <summary>
/// 获取 SM3 哈希值。
/// </summary>
/// <param name="message">文本信息。</param>
/// <returns>哈希值。</returns>
public static string Hash(string message)
{
if (message == null) throw new ArgumentNullException(nameof(message));
byte[] msgBytes = Encoding.UTF8.GetBytes(message);
byte[] hashBytes = Hash(msgBytes);
return BitConverter.ToString(hashBytes).Replace("-", string.Empty);
}
}
partial class SM3Utility
{
internal static class BitOperator
{
@@ -336,35 +369,5 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Utilities
return DIGEST_LENGTH;
}
}
/// <summary>
/// 获取 SM3 哈希值。
/// </summary>
/// <param name="bytes">信息字节数组。</param>
/// <returns>哈希字节数组。</returns>
public static byte[] Hash(byte[] bytes)
{
if (bytes == null) throw new ArgumentNullException(nameof(bytes));
SM3Digest sm3 = new SM3Digest();
sm3.BlockUpdate(bytes, 0, bytes.Length);
byte[] hashBytes = new byte[sm3.GetDigestSize()];
sm3.DoFinal(hashBytes, 0);
return hashBytes;
}
/// <summary>
/// 获取 SM3 哈希值。
/// </summary>
/// <param name="message">文本信息。</param>
/// <returns>哈希值。</returns>
public static string Hash(string message)
{
if (message == null) throw new ArgumentNullException(nameof(message));
byte[] msgBytes = Encoding.UTF8.GetBytes(message);
byte[] hashBytes = Hash(msgBytes);
return BitConverter.ToString(hashBytes).Replace("-", string.Empty);
}
}
}