This commit is contained in:
Stash Dev
2019-02-14 15:42:52 -08:00
parent 1d00b2b36f
commit b488c1ed7d
111 changed files with 141 additions and 141 deletions

28
pkg/utils/crypto.go Normal file
View File

@@ -0,0 +1,28 @@
package utils
import (
"crypto/md5"
"fmt"
"io"
"os"
)
func MD5FromBytes(data []byte) string {
result := md5.Sum(data)
return fmt.Sprintf("%x", result)
}
func MD5FromFilePath(filePath string) (string, error) {
f, err := os.Open(filePath)
if err != nil {
return "", err
}
defer f.Close()
h := md5.New()
if _, err := io.Copy(h, f); err != nil {
return "", err
}
checksum := h.Sum(nil)
return fmt.Sprintf("%x", checksum), nil
}