diff --git a/.gitignore b/.gitignore index 5e3002f8..2eab085a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor/ /.glide +.idea \ No newline at end of file diff --git a/crypto.go b/crypto.go index b63623e8..39004c1f 100644 --- a/crypto.go +++ b/crypto.go @@ -10,6 +10,7 @@ import ( "crypto/ed25519" "crypto/elliptic" "crypto/hmac" + "crypto/md5" "crypto/rand" "crypto/rsa" "crypto/sha1" @@ -73,6 +74,11 @@ func hashSha(password string) string { return base64.StdEncoding.EncodeToString(passwordSum) } +func md5sum(input string) string { + hash := md5.Sum([]byte(input)) + return hex.EncodeToString(hash[:]) +} + // HashAlgorithm enum for hashing algorithms type HashAlgorithm string diff --git a/crypto_test.go b/crypto_test.go index fc34ee0a..68c1aca2 100644 --- a/crypto_test.go +++ b/crypto_test.go @@ -47,6 +47,13 @@ func TestSha1Sum(t *testing.T) { } } +func TestMd5Sum(t *testing.T) { + tpl := `{{"abc" | md5sum}}` + if err := runt(tpl, "900150983cd24fb0d6963f7d28e17f72"); err != nil { + t.Error(err) + } +} + func TestAdler32Sum(t *testing.T) { tpl := `{{"abc" | adler32sum}}` if err := runt(tpl, "38600999"); err != nil { diff --git a/docs/crypto.md b/docs/crypto.md index 35dbaa9c..93ce4b9d 100644 --- a/docs/crypto.md +++ b/docs/crypto.md @@ -267,3 +267,11 @@ algorithm and returns the decoded text. ``` "30tEfhuJSVRhpG97XCuWgz2okj7L8vQ1s6V9zVUPeDQ=" | decryptAES "secretkey" ``` + +## md5sum + +The `md5sum` function receives a string, and computes it's MD5 digest. + +``` +md5sum "Hello world!" +``` diff --git a/functions.go b/functions.go index cda47d26..6896300e 100644 --- a/functions.go +++ b/functions.go @@ -163,6 +163,7 @@ var genericMap = map[string]interface{}{ "sha256sum": sha256sum, "sha512sum": sha512sum, "adler32sum": adler32sum, + "md5sum": md5sum, "toString": strval, // Wrap Atoi to stop errors.