27 lines
581 B
Go
27 lines
581 B
Go
package helper
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
)
|
|
|
|
func CalculateSHA256(data string) string {
|
|
hash := sha256.New()
|
|
hash.Write([]byte(data))
|
|
return hex.EncodeToString(hash.Sum(nil))
|
|
}
|
|
|
|
// ChecksumFormFile calculates the SHA256 checksum of a multipart form file.
|
|
func CalculateSHA256FromBytes(data []byte) string {
|
|
hash := sha256.Sum256(data)
|
|
return hex.EncodeToString(hash[:])
|
|
}
|
|
|
|
// Sha256 returns the SHA256 hash of the input string as a hex string
|
|
func Sha256(s string) string {
|
|
h := sha256.New()
|
|
h.Write([]byte(s))
|
|
return fmt.Sprintf("%x", h.Sum(nil))
|
|
}
|