forked from GoesToEleven/GolangTraining
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
executable file
·28 lines (26 loc) · 808 Bytes
/
main.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
package main
import (
"crypto/rand"
"fmt"
"golang.org/x/crypto/nacl/secretbox"
"io"
)
func main() {
decrypted := "some message that has not yet been encrypted."
// the nonce must be unique for every message encrypted
var nonce [24]byte
io.ReadAtLeast(rand.Reader, nonce[:], 24)
// the password must be unique for every message encrypted
var password [32]byte
io.ReadAtLeast(rand.Reader, password[:], 32)
encrypted := secretbox.Seal(nil, []byte(decrypted), &nonce, &password)
fmt.Println("-----DECRYPTED-----")
fmt.Println(decrypted)
fmt.Println("-----ENCRYPTED-----")
fmt.Println("encrypted", encrypted)
fmt.Println("len", len(encrypted))
fmt.Println("string", string(encrypted))
fmt.Println("nonce", nonce)
fmt.Println("nonce", nonce[:])
fmt.Printf("%x:%x \n", nonce[:], encrypted)
}