forked from shikanon/socks5proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcryptogram_test.go
More file actions
51 lines (48 loc) · 828 Bytes
/
cryptogram_test.go
File metadata and controls
51 lines (48 loc) · 828 Bytes
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
39
40
41
42
43
44
45
46
47
48
49
50
51
package socks5proxy
import (
"github.com/stretchr/testify/assert"
"log"
"testing"
)
func TestSampleCipher(t *testing.T) {
auth, err := CreateSimpleCipher("abc")
if err != nil {
log.Panic(err)
}
b := []byte{0x05, 0x01, 0x04}
c := []byte{0x05, 0x01, 0x04}
// 加密
err = auth.Encrypt(b)
if err != nil {
log.Panic(err)
}
// 解密
err = auth.Decrypt(b)
if err != nil {
log.Panic(err)
}
assert.Equal(t, b, c)
}
func TestRandomCipher(t *testing.T) {
auth, err := CreateRandomCipher("123456")
if err != nil {
log.Panic(err)
}
var b []byte
var c []byte
for i := 0; i < 256; i++ {
b = append(b, byte(i))
c = append(c, byte(i))
}
// 加密
err = auth.Encrypt(b)
if err != nil {
log.Panic(err)
}
// 解密
err = auth.Decrypt(b)
if err != nil {
log.Panic(err)
}
assert.Equal(t, b, c)
}