croc/crypto_test.go

25 lines
485 B
Go
Raw Normal View History

package main
import (
"fmt"
"testing"
)
func TestEncrypt(t *testing.T) {
key := GetRandomName()
fmt.Println(key)
2017-10-18 05:15:48 +02:00
salt, iv, encrypted := Encrypt([]byte("hello, world"), key)
fmt.Println(len(encrypted))
2017-10-18 05:15:48 +02:00
decrypted, err := Decrypt(salt, iv, encrypted, key)
if err != nil {
t.Error(err)
}
if string(decrypted) != "hello, world" {
t.Error("problem decrypting")
}
2017-10-18 05:15:48 +02:00
_, err = Decrypt(salt, iv, encrypted, "wrong passphrase")
if err == nil {
t.Error("should not work!")
}
}