commit inicial do projeto
This commit is contained in:
21
internal/crypto/crypto.go
Normal file
21
internal/crypto/crypto.go
Normal file
@ -0,0 +1,21 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user