mirror of
https://github.com/XrayR-project/XrayR.git
synced 2025-06-08 05:19:54 +00:00
"Add option to input private key for x25519 command"
Added a command line flag to allow the user to provide an input for the private key while utilizing the x25519 command. The function `x25519` was also modified to account for the possibility of a user-inputted private key. If no private key is provided, random bytes will be generated for the private key as before. This feature provides flexibility for the user in key management.
This commit is contained in:
parent
b1bfd04895
commit
fd0a23bf6c
@ -9,8 +9,9 @@ import (
|
|||||||
"golang.org/x/crypto/curve25519"
|
"golang.org/x/crypto/curve25519"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
var (
|
||||||
rootCmd.AddCommand(&cobra.Command{
|
priKey string
|
||||||
|
x25519Cmd = &cobra.Command{
|
||||||
Use: "x25519",
|
Use: "x25519",
|
||||||
Short: "Generate key pair for x25519 key exchange",
|
Short: "Generate key pair for x25519 key exchange",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
@ -18,14 +19,27 @@ func init() {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
x25519Cmd.PersistentFlags().StringVarP(&priKey, "input", "i", "", "Input private key (base64.RawURLEncoding)")
|
||||||
|
rootCmd.AddCommand(x25519Cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func x25519() error {
|
func x25519() error {
|
||||||
var publicKey []byte
|
|
||||||
privateKey := make([]byte, curve25519.ScalarSize)
|
privateKey := make([]byte, curve25519.ScalarSize)
|
||||||
if _, err := rand.Read(privateKey); err != nil {
|
|
||||||
return err
|
if priKey == "" {
|
||||||
|
if _, err := rand.Read(privateKey); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
p, err := base64.RawURLEncoding.DecodeString(priKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
privateKey = p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify random bytes using algorithm described at:
|
// Modify random bytes using algorithm described at:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user