Cloak/cmd/ck-server/keygen.go

22 lines
543 B
Go
Raw Normal View History

2018-12-17 22:12:38 +00:00
package main
import (
"crypto/rand"
2020-04-08 23:37:59 +00:00
"encoding/base64"
2020-04-14 00:53:28 +00:00
"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/Cloak/internal/ecdh"
2018-12-17 22:12:38 +00:00
)
func generateUID() string {
2019-06-16 01:08:51 +00:00
UID := make([]byte, 16)
2020-04-14 00:53:28 +00:00
common.CryptoRandRead(UID)
2020-04-08 23:37:59 +00:00
return base64.StdEncoding.EncodeToString(UID)
2018-12-17 22:12:38 +00:00
}
func generateKeyPair() (string, string) {
staticPv, staticPub, _ := ecdh.GenerateKey(rand.Reader)
marshPub := ecdh.Marshal(staticPub)
2018-12-17 22:12:38 +00:00
marshPv := staticPv.(*[32]byte)[:]
2020-04-08 23:37:59 +00:00
return base64.StdEncoding.EncodeToString(marshPub), base64.StdEncoding.EncodeToString(marshPv)
2018-12-17 22:12:38 +00:00
}