-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecrypt.go
46 lines (37 loc) · 880 Bytes
/
decrypt.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
package main
import (
"crypto/aes"
"crypto/cipher"
"fmt"
"io/ioutil"
)
func main() {
fmt.Println("Decryption Program")
key := []byte("secretToSecretIsGoodPastaAndGood")
ciphertext, err := ioutil.ReadFile("encrypt.data")
if err != nil {
panic(err)
}
// Creates cipher block
cblock, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
// Creates a Galois Counter Mode
gcm, err := cipher.NewGCM(cblock)
if err != nil {
panic(err)
}
nonceSize := gcm.NonceSize()
if len(ciphertext) < nonceSize {
fmt.Println("This is not right")
}
nonce, ciphertext := ciphertext[:nonceSize], ciphertext[nonceSize:]
fmt.Printf("The Nonce: %s \n", string(nonce))
fmt.Printf("The CipherText: %s \n", string(ciphertext))
text, err := gcm.Open(nil, nonce, ciphertext, nil)
if err != nil {
fmt.Println(err)
}
fmt.Printf("The secret is: %s ", string(text))
}