File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed
Source/FikaAmazonAPI/Utils Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using System . Globalization ;
2
3
using System . IO ;
4
+ using System . Security . Cryptography ;
3
5
using System . Text ;
4
6
5
7
namespace FikaAmazonAPI . Utils
@@ -21,17 +23,18 @@ public static string GetMD5HashFromFile(string filepath)
21
23
return GetMD5HashFromBytes ( bytes ) ;
22
24
}
23
25
24
- public static string GetMD5HashFromBytes ( byte [ ] bytes )
26
+ private static string GetMD5HashFromBytes ( byte [ ] bytes )
25
27
{
26
- if ( bytes == null )
27
- throw new ArgumentNullException ( "bytes" ) ;
28
28
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 )
31
33
{
32
- sb . Append ( bytes [ i ] . ToString ( "x2" ) ) ;
34
+ hashString . Append ( t . ToString ( "x2" , CultureInfo . InvariantCulture ) ) ;
33
35
}
34
- return sb . ToString ( ) ;
36
+
37
+ return hashString . ToString ( ) ;
35
38
}
36
39
}
37
40
}
You can’t perform that action at this time.
0 commit comments