Skip to content

Commit b37d9ee

Browse files
committed
fix #217
1 parent 120914d commit b37d9ee

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Source/FikaAmazonAPI/Utils/EasyMD5.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Globalization;
23
using System.IO;
4+
using System.Security.Cryptography;
35
using System.Text;
46

57
namespace FikaAmazonAPI.Utils
@@ -21,17 +23,18 @@ public static string GetMD5HashFromFile(string filepath)
2123
return GetMD5HashFromBytes(bytes);
2224
}
2325

24-
public static string GetMD5HashFromBytes(byte[] bytes)
26+
private static string GetMD5HashFromBytes(byte[] bytes)
2527
{
26-
if (bytes == null)
27-
throw new ArgumentNullException("bytes");
2828

29-
StringBuilder sb = new StringBuilder();
30-
for (int i = 0; i < bytes.Length; i++)
29+
using var md5 = MD5.Create();
30+
var hash = md5.ComputeHash(bytes);
31+
var hashString = new StringBuilder();
32+
foreach (var t in hash)
3133
{
32-
sb.Append(bytes[i].ToString("x2"));
34+
hashString.Append(t.ToString("x2", CultureInfo.InvariantCulture));
3335
}
34-
return sb.ToString();
36+
37+
return hashString.ToString();
3538
}
3639
}
3740
}

0 commit comments

Comments
 (0)