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