add encrypt private command

This commit is contained in:
Yuzuki616
2023-07-15 18:13:16 +08:00
parent 15efffba0d
commit 97a420f9f3
3 changed files with 28 additions and 5 deletions

View File

@@ -4,6 +4,9 @@ import (
"crypto/rand"
"encoding/base64"
"fmt"
"strings"
"github.com/Yuzuki616/V2bX/common/crypt"
"github.com/spf13/cobra"
"golang.org/x/crypto/curve25519"
@@ -22,6 +25,19 @@ func init() {
}
func executeX25519() {
var yes, key string
fmt.Println("要对私钥进行加密吗?(Y/n)")
fmt.Scan(&yes)
if strings.ToLower(yes) == "y" {
var temp string
fmt.Println("请输入Api接口地址:")
fmt.Scan(&temp)
key = temp
fmt.Println("请输入Api认证Token:")
fmt.Scan(&temp)
key += temp
key = crypt.GenShaHash([]byte(key))
}
var output string
var err error
defer func() {
@@ -45,9 +61,16 @@ func executeX25519() {
output = Err("gen X25519 error: ", err)
return
}
p := base64.RawURLEncoding.EncodeToString(privateKey)
output = fmt.Sprint("Private key: ",
base64.RawURLEncoding.EncodeToString(privateKey),
p,
"\nPublic key: ",
base64.RawURLEncoding.EncodeToString(publicKey))
if strings.ToLower(yes) == "y" {
key, err = crypt.AesEncrypt([]byte(p), []byte(key[:32]))
if err != nil {
output = Err("encrypt private key error: ", err)
}
output += "\n加密后的Private key" + key
}
}