RSA
This commit is contained in:
parent
a90cc4eb1b
commit
c26ea0fe41
|
@ -36,6 +36,8 @@ func Start() {
|
||||||
dumpConfig()
|
dumpConfig()
|
||||||
case "domains":
|
case "domains":
|
||||||
showDomains()
|
showDomains()
|
||||||
|
case "pubkey":
|
||||||
|
showPubkey()
|
||||||
case "apply":
|
case "apply":
|
||||||
applyOnce()
|
applyOnce()
|
||||||
case "-s":
|
case "-s":
|
||||||
|
@ -190,6 +192,11 @@ func showDomains() {
|
||||||
log.Println(string(config))
|
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/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
"encoding/base64"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GenRsa() (priKey string, pubKey string, err error) {
|
func GenRsa() (priKey string, pubKey string, err error) {
|
||||||
|
@ -13,23 +13,27 @@ func GenRsa() (priKey string, pubKey string, err error) {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
publicKey := &privateKey.PublicKey
|
publicKey := &privateKey.PublicKey
|
||||||
|
|
||||||
publicKeyBytes, err := x509.MarshalPKIXPublicKey(publicKey)
|
publicKeyBytes, err := x509.MarshalPKIXPublicKey(publicKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
pemBlock := &pem.Block{
|
pubKey = base64.StdEncoding.EncodeToString(publicKeyBytes)
|
||||||
Type: "PUBLIC KEY",
|
//pemBlock := &pem.Block{
|
||||||
Bytes: publicKeyBytes,
|
// 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))
|
priKey = base64.StdEncoding.EncodeToString(privateKeyBytes)
|
||||||
|
//pemBlock = &pem.Block{
|
||||||
privateKeyBytes := x509.MarshalPKCS1PrivateKey(privateKey)
|
// Type: "",
|
||||||
pemBlock = &pem.Block{
|
// Bytes: privateKeyBytes,
|
||||||
Type: "RSA PRIVATE KEY",
|
//}
|
||||||
Bytes: privateKeyBytes,
|
//priKey = string(pem.EncodeToMemory(pemBlock))
|
||||||
}
|
|
||||||
priKey = string(pem.EncodeToMemory(pemBlock))
|
|
||||||
err = nil
|
err = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user