forked from sipt/shuttle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher_test.go
More file actions
71 lines (61 loc) · 1.4 KB
/
Copy pathcipher_test.go
File metadata and controls
71 lines (61 loc) · 1.4 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package shuttle
import (
"testing"
"crypto/cipher"
"crypto/md5"
"crypto/rc4"
"io"
"crypto/rand"
"fmt"
)
func TestCheckCipher(t *testing.T) {
cipher := ciphers["rc4-md5"]
key := evpBytesToKey("07071818w", cipher.KeyLen())
iv := make([]byte, cipher.IVLen())
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
panic(err)
}
//cipherConn.iv = []byte{203, 63, 174, 189, 49, 139, 9, 54, 159, 146, 88, 224, 30, 9, 12, 238}
fmt.Println("iv -> ", iv)
fmt.Println("key -> ", key)
var err error
enc, err := cipher.NewEncrypter(key, iv)
if err != nil {
panic(err)
}
dec, _ := cipher.NewDecrypter(key, iv)
src := []byte{3, 14, 119, 119, 119, 46, 103, 111, 111, 103, 108, 101, 46, 99, 111, 109, 80, 0}
dst := make([]byte, len(src))
enc.XORKeyStream(dst, src)
fmt.Println(dst)
dst2 := make([]byte, len(src))
dec.XORKeyStream(dst2, dst)
fmt.Println(dst2)
}
func init() {
RegisterCipher("rc4-md5", &rc4_md5{16, 16})
}
type rc4_md5 struct {
keyLen int
ivLen int
}
func (a *rc4_md5) KeyLen() int {
return a.keyLen
}
func (a *rc4_md5) IVLen() int {
return a.ivLen
}
func (a *rc4_md5) NewEncrypter(key, iv []byte) (cipher.Stream, error) {
h := md5.New()
h.Write(key)
h.Write(iv)
rc4key := h.Sum(nil)
return rc4.NewCipher(rc4key)
}
func (a *rc4_md5) NewDecrypter(key, iv []byte) (cipher.Stream, error) {
h := md5.New()
h.Write(key)
h.Write(iv)
rc4key := h.Sum(nil)
return rc4.NewCipher(rc4key)
}