Cloak/cmd/ck-server/keygen.go
2020-04-14 14:14:51 +01:00

22 lines
543 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)
}