1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-30 23:52:07 +03:00
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 06:15:48 +03:00
salt, iv, encrypted := Encrypt([]byte("hello, world"), key)
fmt.Println(len(encrypted))
2017-10-18 06:15:48 +03: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 06:15:48 +03:00
_, err = Decrypt(salt, iv, encrypted, "wrong passphrase")
if err == nil {
t.Error("should not work!")
}
}