2025-03-09 18:04:03 -04:00
|
|
|
package encryption_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"testing"
|
|
|
|
|
2025-03-25 13:14:27 -04:00
|
|
|
"numenor-labs.us/dsfx/internal/lib/crypto/encryption"
|
2025-03-09 18:04:03 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestEncryptDecrypt(t *testing.T) {
|
|
|
|
key := make([]byte, 32)
|
|
|
|
_, err := rand.Read(key)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
plaintext := []byte("Hello, Worlskljfsjflskfjlskjfjslkfjsfjslkfjsfd!")
|
|
|
|
ciphertext, err := encryption.Encrypt(key, plaintext)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
decrypted, err := encryption.Decrypt(key, ciphertext)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if string(decrypted) != string(plaintext) {
|
|
|
|
t.Errorf("decrypted text does not match original plaintext")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|