idecnode/pkg/model/uid.go

20 lines
378 B
Go
Raw Permalink Normal View History

2024-10-20 03:39:07 +03:00
package model
import (
"crypto/sha256"
"encoding/base64"
"strings"
)
func UIDFromMessage(msg *Message) string {
return UIDFromText(msg.PointMessage())
}
func UIDFromText(text string) string {
h := sha256.Sum256([]byte(text))
id := base64.StdEncoding.EncodeToString(h[:])
id = strings.NewReplacer("+", "A", "/", "Z", "-", "A", "_", "Z").Replace(id)
return id[0:20]
}