2017-10-18 05:19:09 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEncrypt(t *testing.T) {
|
|
|
|
key := GetRandomName()
|
|
|
|
fmt.Println(key)
|
2017-10-18 06:15:48 +03:00
|
|
|
salt, iv, encrypted := Encrypt([]byte("hello, world"), key)
|
2017-10-18 05:19:09 +03:00
|
|
|
fmt.Println(len(encrypted))
|
2017-10-18 06:15:48 +03:00
|
|
|
decrypted, err := Decrypt(salt, iv, encrypted, key)
|
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 06:15:48 +03:00
|
|
|
_, err = Decrypt(salt, iv, encrypted, "wrong passphrase")
|
2017-10-18 05:19:09 +03:00
|
|
|
if err == nil {
|
|
|
|
t.Error("should not work!")
|
|
|
|
}
|
|
|
|
}
|