appcore/crypto/encryption_test.go

41 lines
773 B
Go
Raw Normal View History

2025-06-16 22:26:47 +05:30
// Copyright 2024 Patial Tech (Ankit Patial).
//
// This file is part of code.patial.tech/go/appcore, which is MIT licensed.
// See http://opensource.org/licenses/MIT
2025-06-16 22:19:00 +05:30
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")
}
}