-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathencrypt.go
56 lines (41 loc) · 819 Bytes
/
encrypt.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"crypto/aes"
"crypto/rand"
"os"
)
var secstoreStart []byte = []byte("store 02")
func EncryptBytes(pass, bytes []byte, file *os.File) error {
var plain, cipher, blockpass []byte
var n, nn int
plain = make([]byte, 16)
cipher = make([]byte, 16)
blockpass = make([]byte, KeySize)
n = 0
copy(blockpass, pass)
copy(plain, secstoreStart)
for {
if _, err := rand.Read(plain[8:]); err != nil {
panic(err)
}
conv, err := aes.NewCipher(blockpass)
if err != nil {
panic(err)
}
conv.Encrypt(cipher, plain)
_, err = file.Write(cipher)
if err != nil {
return err
}
if n >= len(bytes) {
break
}
blockpass = TwoCreateNewPass(blockpass, plain)
nn = copy(plain[:8], bytes[n:])
for i := nn; i < 8; i++ {
plain[i] = 0
}
n += 8
}
return nil
}