You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
391 B
23 lines
391 B
package crypto |
|
|
|
import ( |
|
"bytes" |
|
"crypto/sha256" |
|
"encoding/gob" |
|
"encoding/hex" |
|
) |
|
|
|
func CalculateHash(obj interface{}) string { |
|
var buffer bytes.Buffer |
|
encoder := gob.NewEncoder(&buffer) |
|
if err := encoder.Encode(obj); err != nil { |
|
panic(err) |
|
} |
|
hasher := sha256.New() |
|
bytes := buffer.Bytes() |
|
hasher.Write(bytes) |
|
|
|
sum := hex.EncodeToString(hasher.Sum(nil)) |
|
|
|
return string(sum) |
|
}
|
|
|