36 lines
605 B
Go
36 lines
605 B
Go
package crypto
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewEncryptionKey(t *testing.T) {
|
|
if key, err := NewEncryptionKey(32); err != nil {
|
|
t.Error(err)
|
|
} else {
|
|
fmt.Println(key)
|
|
}
|
|
}
|
|
|
|
func TestEncryptDecrypt(t *testing.T) {
|
|
text := "Hellp World!"
|
|
key := "Laumw6mvWwrc8Q1SZQYCdiVr/dDBpjDdpaI6v4WvWSw="
|
|
|
|
// crypt
|
|
crypted, err := Encrypt(key, text)
|
|
if err != nil {
|
|
t.Errorf("Encrypt failed: %v", err)
|
|
}
|
|
|
|
decrypted, err := Decrypt(key, crypted)
|
|
if err != nil {
|
|
t.Errorf("Decrypt failed: %v", err)
|
|
}
|
|
|
|
if string(decrypted) != text {
|
|
t.Errorf("Decrypted text does not match original")
|
|
}
|
|
|
|
}
|