mirror of
https://github.com/net-byte/vtun
synced 2024-03-14 10:50:03 +08:00
33 lines
515 B
Go
33 lines
515 B
Go
package cipher
|
|
|
|
import (
|
|
"crypto/rc4"
|
|
"log"
|
|
)
|
|
|
|
var _key = []byte("8pUsXuZw4z6B9EhGdKgNjQnjmVsYv2x5")
|
|
|
|
func GenerateKey(key string) {
|
|
_key = []byte(key)
|
|
}
|
|
|
|
func Encrypt(data []byte) []byte {
|
|
c, err := rc4.NewCipher(_key)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
dst := make([]byte, len(data))
|
|
c.XORKeyStream(dst, data)
|
|
return dst
|
|
}
|
|
|
|
func Decrypt(data []byte) []byte {
|
|
c, err := rc4.NewCipher(_key)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
dst := make([]byte, len(data))
|
|
c.XORKeyStream(dst, data)
|
|
return dst
|
|
}
|