mirror of
https://git.numenor-labs.us/dsfx.git
synced 2025-04-29 08:10:34 +00:00
36 lines
656 B
Go
36 lines
656 B
Go
package encryption_test
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"testing"
|
|
|
|
"koti.casa/numenor-labs/dsfx/internal/lib/crypto/encryption"
|
|
)
|
|
|
|
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
|
|
}
|
|
}
|