*
This commit is contained in:
1 parent
35e6e1e904
commit
7f70c2e7f7
1 file changed
+3
-3
@@ -35,7 +35,7 @@ public static class CryptographyUtils {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 计算文件的 Hash。返回 16 进制小写字符串。
|
/// 计算文件的 Hash。返回 16 进制小写字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string ComputeFileHash(string filePath, HashMethod method) {
|
public static string ComputeFileHash(string filePath, HashMethod method = HashMethod.Md5) {
|
||||||
using HashAlgorithm hashImpl = GetHashAlgorithm(method);
|
using HashAlgorithm hashImpl = GetHashAlgorithm(method);
|
||||||
Logger.Trace($"计算文件 {method}:{filePath}");
|
Logger.Trace($"计算文件 {method}:{filePath}");
|
||||||
using var file = FileUtils.ReadAsStream(filePath);
|
using var file = FileUtils.ReadAsStream(filePath);
|
||||||
@@ -45,7 +45,7 @@ public static class CryptographyUtils {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 计算字节数组的 Hash。返回 16 进制小写字符串。
|
/// 计算字节数组的 Hash。返回 16 进制小写字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string ComputeHash(byte[] input, HashMethod method) {
|
public static string ComputeHash(byte[] input, HashMethod method = HashMethod.Md5) {
|
||||||
using HashAlgorithm hashImpl = GetHashAlgorithm(method);
|
using HashAlgorithm hashImpl = GetHashAlgorithm(method);
|
||||||
return BitConverter.ToString(hashImpl.ComputeHash(input)).Replace("-", "").Lower();
|
return BitConverter.ToString(hashImpl.ComputeHash(input)).Replace("-", "").Lower();
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ public static class CryptographyUtils {
|
|||||||
/// 计算字符串的 Hash。返回 16 进制小写字符串。
|
/// 计算字符串的 Hash。返回 16 进制小写字符串。
|
||||||
/// <para/> 使用 UTF-8 将字符串转换为字节数组。
|
/// <para/> 使用 UTF-8 将字符串转换为字节数组。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string ComputeHash(string input, HashMethod method)
|
public static string ComputeHash(string input, HashMethod method = HashMethod.Md5)
|
||||||
=> ComputeHash(Encoding.UTF8.GetBytes(input), method);
|
=> ComputeHash(Encoding.UTF8.GetBytes(input), method);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in new issue
Block a user