Skip to content

Commit

Permalink
add test for encrypt and decrypt functions
Browse files Browse the repository at this point in the history
  • Loading branch information
yemmyharry committed Mar 4, 2024
1 parent 9bbd1a4 commit 1b9b22f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions btcec/ciphering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ package btcec

import (
"bytes"
"encoding/hex"
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)

Expand All @@ -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))

}

0 comments on commit 1b9b22f

Please sign in to comment.