-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMD5Hash.fs
31 lines (25 loc) · 1.09 KB
/
MD5Hash.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace AVPRIndex
open System
open System.IO
open System.Text
open System.Security.Cryptography
type Hash =
// This is the function used as the first point of entry, as it is used when parsing packages that do not exist in the prioduction DB
// unifying line endings is crucial to ensure that the hash is the same on all platforms
/// calculates a md5 hash of the given byte array and returns it as a hex string
static member hashContent (content: byte array) =
let md5 = MD5.Create()
content
|> md5.ComputeHash
|> Convert.ToHexString
/// calculates a md5 hash of the given string with line endings unified to `\n` and returns it as a hex string
static member hashString (content: string) =
content
|> fun s -> s.ReplaceLineEndings("\n")
|> Encoding.UTF8.GetBytes
|> Hash.hashContent
/// calculates a md5 hash of the file at the given path with line endings unified to `\n` and returns it as a hex string
static member hashFile (path: string) =
path
|> File.ReadAllText
|> Hash.hashString