22 lines
493 B
Go
22 lines
493 B
Go
package crypto
|
|
|
|
import (
|
|
"crypto/ed25519"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
)
|
|
|
|
// GenerateHash gera um hash SHA-256 de qualquer estrutura
|
|
func GenerateHash(v interface{}) string {
|
|
b, _ := json.Marshal(v)
|
|
h := sha256.Sum256(b)
|
|
return hex.EncodeToString(h[:])
|
|
}
|
|
|
|
// SignMessage assina uma string com uma chave privada
|
|
func SignMessage(message string, privateKey ed25519.PrivateKey) string {
|
|
sig := ed25519.Sign(privateKey, []byte(message))
|
|
return hex.EncodeToString(sig)
|
|
}
|