croc/crypto_test.go

22 lines
431 B
Go
Raw Normal View History

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