forked from blues/jsonata-go
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add hash256 func * add hash hasStr function --------- Co-authored-by: tbal999 <[email protected]>
- Loading branch information
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package jlib | ||
|
||
import ( | ||
"crypto/md5" | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"strings" | ||
) | ||
|
||
// Hash a input string into a sha256 string | ||
// for deduplication purposes | ||
func Hash(hashType, input string) string { | ||
switch strings.ToLower(hashType) { | ||
case "sha256": | ||
hasher := sha256.New() | ||
|
||
hasher.Write([]byte(input)) | ||
|
||
hashedBytes := hasher.Sum(nil) | ||
|
||
hashedString := hex.EncodeToString(hashedBytes) | ||
|
||
return hashedString | ||
case "md5": | ||
hash := md5.Sum([]byte(input)) | ||
|
||
hashedString := hex.EncodeToString(hash[:]) | ||
|
||
return hashedString | ||
} | ||
|
||
hash := md5.Sum([]byte(input)) | ||
|
||
hashedString := hex.EncodeToString(hash[:]) | ||
|
||
return hashedString | ||
} |