Cloak/cmd/ck-server/keygen.go
2023-03-07 17:09:18 +08:00

23 lines
544 B
Go

package main
import (
"crypto/rand"
"encoding/base64"
"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/Cloak/internal/ecdh"
)
func generateUID() string {
UID := make([]byte, 16)
common.CryptoRandRead(UID)
return base64.StdEncoding.EncodeToString(UID)
}
func generateKeyPair() (string, string) {
staticPv, staticPub, _ := ecdh.GenerateKey(rand.Reader)
marshPub := ecdh.Marshal(staticPub)
marshPv := staticPv.(*[32]byte)[:]
return base64.StdEncoding.EncodeToString(marshPub), base64.StdEncoding.EncodeToString(marshPv)
}