-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pasta.go
58 lines (48 loc) · 1.5 KB
/
pasta.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
package pasta
import (
"encoding/base64"
"flag"
"fmt"
"github.com/benji-vesterby/pasta/crypt"
"github.com/gtank/cryptopasta"
)
func main() {
var err error
// Setting up config arguments for starting the job runner
generateKey := flag.Bool("g", false, "Generate new key to use for encryption")
decrypt := flag.Bool("d", false, "Decrypt the value passed in through the -v flag")
key := flag.String("k", "", "The encryption key to use for encryption or decryption")
value := flag.String("v", "", "The value to be encrypted or decrypted")
flag.Parse()
if *generateKey {
// Generate a new encryption key to be used
if ekey := cryptopasta.NewEncryptionKey(); ekey != nil {
var outKey []byte
if outKey, err = crypt.ConvertToByteSlice(ekey); err == nil {
fmt.Printf("Encryption Key: [%s]\n", base64.StdEncoding.EncodeToString(outKey))
} else {
fmt.Printf("Error while converting key to byte slice | Error: [%s]\n", err.Error())
}
} else {
fmt.Printf("Error while generating encryption key\n")
}
} else {
// Default to encryption
if *decrypt {
// Decrypt
var decryptedValue string
if decryptedValue, err = crypt.Decrypt(*key, *value); err == nil {
fmt.Printf("Decrypted Value: [%s]\n", decryptedValue)
} else {
fmt.Println(err.Error())
}
} else {
var encryptedValue string
if encryptedValue, err = crypt.Encrypt(*key, *value); err == nil {
fmt.Printf("Encrypted Value: [%s]\n", encryptedValue)
} else {
fmt.Println(err.Error())
}
}
}
}