mirror of
https://github.com/XrayR-project/XrayR.git
synced 2025-06-07 21:09:53 +00:00

Updated several Go dependencies for enhanced security and performance. Additionally, a command (`-x25519`) has been added for generating a secure key pair using X25519. This provides an easier and safer way for users to generate keys for secure communication. Further instructions have been reflected in the `config.yml.example` file.
37 lines
815 B
Go
37 lines
815 B
Go
// Package common contains common utilities that are shared among other packages.
|
|
package common
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/base64"
|
|
"fmt"
|
|
|
|
"golang.org/x/crypto/curve25519"
|
|
)
|
|
|
|
func X25519() {
|
|
var publicKey []byte
|
|
privateKey := make([]byte, curve25519.ScalarSize)
|
|
if _, err := rand.Read(privateKey); err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
// Modify random bytes using algorithm described at:
|
|
// https://cr.yp.to/ecdh.html.
|
|
privateKey[0] &= 248
|
|
privateKey[31] &= 127
|
|
privateKey[31] |= 64
|
|
|
|
publicKey, err := curve25519.X25519(privateKey, curve25519.Basepoint)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
output := fmt.Sprintf("Private key: %v\nPublic key: %v",
|
|
base64.RawURLEncoding.EncodeToString(privateKey),
|
|
base64.RawURLEncoding.EncodeToString(publicKey))
|
|
fmt.Println(output)
|
|
}
|