utils/generators.go

40 lines
716 B
Go
Raw Permalink Normal View History

2023-10-02 23:42:16 +02:00
package utils
import (
"crypto/rand"
"fmt"
"strconv"
"strings"
"time"
"github.com/google/uuid"
)
// GenerateNewSHA256Sum returns a fresh SHA256Sum
func GenerateNewSHA256Sum() string {
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
prime, _ := rand.Prime(rand.Reader, 512)
data := []string{fmt.Sprintf("%d", prime)}
for i := 0; i < 64; i++ {
prime, _ = rand.Prime(rand.Reader, 64)
data = append(
data,
strings.Join(
[]string{
fmt.Sprintf("%d", prime),
GenerateNewUUID(),
timestamp},
"|",
),
)
}
return GetSHA256SumOfString(strings.Join(data, "|||"))
}
// GenerateNewUUID returns a fresh UUID
func GenerateNewUUID() string {
return uuid.New().String()
}