route/vendor/github.com/brandur/simplebox/example_test.go

31 lines
484 B
Go
Raw Normal View History

2017-10-06 15:29:20 +00:00
package simplebox_test
import (
"crypto/rand"
"fmt"
"github.com/brandur/simplebox"
)
func ExampleSimpleBox() {
message := "hello"
var secretKey [simplebox.KeySize]byte
rand.Reader.Read(secretKey[:])
box := simplebox.NewFromSecretKey(&secretKey)
// Encrypt
ciphertext := box.Encrypt([]byte(message))
// Decrypt
decrypted, err := box.Decrypt(ciphertext)
if err != nil {
panic(err)
}
// Prints:
//
// Decrypted: hello
fmt.Printf("Decrypted: %v\n", decrypted)
}