Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
/.glide
.idea
6 changes: 6 additions & 0 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"crypto/ed25519"
"crypto/elliptic"
"crypto/hmac"
"crypto/md5"
"crypto/rand"
"crypto/rsa"
"crypto/sha1"
Expand Down Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions docs/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
```
1 change: 1 addition & 0 deletions functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ var genericMap = map[string]interface{}{
"sha256sum": sha256sum,
"sha512sum": sha512sum,
"adler32sum": adler32sum,
"md5sum": md5sum,
"toString": strval,

// Wrap Atoi to stop errors.
Expand Down