This commit is contained in:
ZhuoQinghui 2024-10-25 15:04:13 +08:00
parent a90cc4eb1b
commit c26ea0fe41
2 changed files with 24 additions and 13 deletions

View File

@ -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)
}
/*
守护进程接收名称
*/

View File

@ -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
}