RSA
This commit is contained in:
parent
a90cc4eb1b
commit
c26ea0fe41
|
@ -36,6 +36,8 @@ func Start() {
|
|||
dumpConfig()
|
||||
case "domains":
|
||||
showDomains()
|
||||
case "pubkey":
|
||||
showPubkey()
|
||||
case "apply":
|
||||
applyOnce()
|
||||
case "-s":
|
||||
|
@ -190,6 +192,11 @@ func showDomains() {
|
|||
log.Println(string(config))
|
||||
}
|
||||
|
||||
func showPubkey() {
|
||||
key := GetAppConfig().Encrypt.PubKey
|
||||
log.Println(key)
|
||||
}
|
||||
|
||||
/*
|
||||
守护进程接收名称
|
||||
*/
|
||||
|
|
30
src/util.go
30
src/util.go
|
@ -4,7 +4,7 @@ import (
|
|||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"encoding/base64"
|
||||
)
|
||||
|
||||
func GenRsa() (priKey string, pubKey string, err error) {
|
||||
|
@ -13,23 +13,27 @@ func GenRsa() (priKey string, pubKey string, err error) {
|
|||
return "", "", err
|
||||
}
|
||||
publicKey := &privateKey.PublicKey
|
||||
|
||||
publicKeyBytes, err := x509.MarshalPKIXPublicKey(publicKey)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
pemBlock := &pem.Block{
|
||||
Type: "PUBLIC KEY",
|
||||
Bytes: publicKeyBytes,
|
||||
pubKey = base64.StdEncoding.EncodeToString(publicKeyBytes)
|
||||
//pemBlock := &pem.Block{
|
||||
// Type: "",
|
||||
// Bytes: publicKeyBytes,
|
||||
//}
|
||||
//pubKey = string(pem.EncodeToMemory(pemBlock))
|
||||
//x509.MarshalPKCS8PrivateKey(privateKey)
|
||||
privateKeyBytes, err := x509.MarshalPKCS8PrivateKey(privateKey)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
pubKey = string(pem.EncodeToMemory(pemBlock))
|
||||
|
||||
privateKeyBytes := x509.MarshalPKCS1PrivateKey(privateKey)
|
||||
pemBlock = &pem.Block{
|
||||
Type: "RSA PRIVATE KEY",
|
||||
Bytes: privateKeyBytes,
|
||||
}
|
||||
priKey = string(pem.EncodeToMemory(pemBlock))
|
||||
priKey = base64.StdEncoding.EncodeToString(privateKeyBytes)
|
||||
//pemBlock = &pem.Block{
|
||||
// Type: "",
|
||||
// Bytes: privateKeyBytes,
|
||||
//}
|
||||
//priKey = string(pem.EncodeToMemory(pemBlock))
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user