forked from Mxmilu666/frp
all: now messages between frps and frpc can be encryped when use_encryption set true
This commit is contained in:
@@ -39,7 +39,7 @@ func (pc *Pcrypto) Init(key []byte) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (pc *Pcrypto) Encrypto(src []byte) ([]byte, error) {
|
||||
func (pc *Pcrypto) Encrypt(src []byte) ([]byte, error) {
|
||||
// aes
|
||||
src = pKCS7Padding(src, aes.BlockSize)
|
||||
blockMode := cipher.NewCBCEncrypter(pc.paes, pc.pkey)
|
||||
@@ -57,7 +57,7 @@ func (pc *Pcrypto) Encrypto(src []byte) ([]byte, error) {
|
||||
return []byte(base64.StdEncoding.EncodeToString(zbuf.Bytes())), nil
|
||||
}
|
||||
|
||||
func (pc *Pcrypto) Decrypto(str []byte) ([]byte, error) {
|
||||
func (pc *Pcrypto) Decrypt(str []byte) ([]byte, error) {
|
||||
// base64
|
||||
data, err := base64.StdEncoding.DecodeString(string(str))
|
||||
if err != nil {
|
||||
|
||||
@@ -19,10 +19,10 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEncrypto(t *testing.T) {
|
||||
func TestEncrypt(t *testing.T) {
|
||||
pp := new(Pcrypto)
|
||||
pp.Init([]byte("Hana"))
|
||||
res, err := pp.Encrypto([]byte("Just One Test!"))
|
||||
res, err := pp.Encrypt([]byte("Just One Test!"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -30,15 +30,15 @@ func TestEncrypto(t *testing.T) {
|
||||
fmt.Printf("[%x]\n", res)
|
||||
}
|
||||
|
||||
func TestDecrypto(t *testing.T) {
|
||||
func TestDecrypt(t *testing.T) {
|
||||
pp := new(Pcrypto)
|
||||
pp.Init([]byte("Hana"))
|
||||
res, err := pp.Encrypto([]byte("Just One Test!"))
|
||||
res, err := pp.Encrypt([]byte("Just One Test!"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
res, err = pp.Decrypto(res)
|
||||
res, err = pp.Decrypt(res)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user