diff --git a/btcec/ciphering_test.go b/btcec/ciphering_test.go index c6bea3da73..14972bb9c0 100644 --- a/btcec/ciphering_test.go +++ b/btcec/ciphering_test.go @@ -6,6 +6,9 @@ package btcec import ( "bytes" + "encoding/hex" + "fmt" + "github.com/stretchr/testify/assert" "testing" ) @@ -29,3 +32,30 @@ func TestGenerateSharedSecret(t *testing.T) { secret1, secret2) } } + +func TestEncryptAndDecrypt(t *testing.T) { + privateKey, err := NewPrivateKey() + if err != nil { + t.Errorf("private key generation error: %s", err) + return + } + publicKey := privateKey.PubKey() + message := []byte("Hello, this is a test message.") + + encryptedMessage, err := Encrypt(publicKey, message) + if !assert.NoError(t, err) { + return + } + + fmt.Println("Encrypted Message:", hex.EncodeToString(encryptedMessage)) + + decryptedMessage, err := Decrypt(privateKey, encryptedMessage) + if !assert.NoError(t, err) { + return + } + + fmt.Println("Decrypted Message:", string(decryptedMessage)) + + assert.Equal(t, string(message), string(decryptedMessage)) + +}