-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencryption.go
38 lines (32 loc) · 1.02 KB
/
encryption.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
//this is simple function for encryption [ref: https://en.wikipedia.org/wiki/XOR_cipher]
//but its better to have more standard ways (AES,Triple DES,RSA,BlowFish)
func simple_xor(bytes []byte,key []byte) []byte{
var rtn []byte
var i int
len_xor_key:=len(key)
rtn = make([]byte,len(bytes))
for i=0;i<len(bytes);i++{
rtn[i]=key[i%len_xor_key] ^ bytes[i]
}
return rtn
}
// this method decript packet by specified encription
// if there is no encription method we return input bytes array
func DecryptPacket(bytes []byte,config *vpnConfig) ([]byte,error) {
if config.encryptionMethod =="xor" {
return simple_xor(bytes,config.xorKey),nil
} else if (config.encryptionMethod=="des"){
return DesDecrypt(bytes, config.desKey)
}
return bytes,nil
}
//EncryptPacket
func EncryptPacket(bytes []byte,config *vpnConfig) ([]byte,error){
if config.encryptionMethod =="xor" {
return simple_xor(bytes,config.xorKey),nil
} else if config.encryptionMethod=="des"{
return DesEncrypt(bytes,config.desKey)
}
return bytes,nil
}