-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypt.go
65 lines (49 loc) · 1.72 KB
/
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
57
58
59
60
61
62
63
64
65
package main
import(
"os"
"fmt"
"path"
"regexp"
"github.com/neoh/usb-encrypt/uti"
"github.com/neoh/usb-encrypt/encryption"
"github.com/neoh/usb-encrypt/compression"
"github.com/neoh/usb-encrypt/values"
)
func main() {
var validatorName = regexp.MustCompile(values.patternValidateName)
var validatorDir = regexp.MustCompile(values.patternValidateDir)
currentDir := uti.GetCurrentPath()
vaultName := uti.TakeInput(values.MessageVaultName)
if !validatorName.MatchString(vaultName) {
panic(values.ErrorVaultName)
}
rootVault := path.Join(currentDir, values.vaultDir)
vaultPath := uti.TakeInput(values.MessageVaultPath)
if !validatorDir.MatchString(vaultPath) {
panic(values.ErrorVaultPath)
}
vaultTarPath := vaultPath
encryptedOutput := path.Join(rootVault, vaultName + ".aes")
if len(vaultPath) > len(currentDir) {
if vaultPath[0:len(currentDir)] == currentDir {
panic(values.ErrorEncryptFromUsb)
}
}
vaultKey := uti.TakeInput("Enter key: ")
if len(vaultKey) < 1 {
uti.ExitPrompt("Error key too short.")
return
}
if err := os.MkdirAll(rootVault, os.FileMode(0755)); err != nil {
panic(err.Error())
}
timestamp := uti.GetUnix()
handler := compression.Handler{}
handler.Init(vaultPath, vaultTarPath)
defer os.Remove(vaultTarPath)
fmt.Println("Compression took", uti.GetUnix() - timestamp, "seconds")
fmt.Println("Encrypting: ", vaultTarPath)
encryption.Crypt(vaultTarPath, vaultKey, encryptedOutput)
fmt.Println("Encrypted output:", encryptedOutput)
fmt.Println("Finished")
}