Skip to content

Commit

Permalink
feat: Add example code for ECIES encryption and decryption
Browse files Browse the repository at this point in the history
This commit adds example code for ECIES encryption and decryption using the `ecies-bls12381` package. It demonstrates how to generate key pairs, encrypt a message, and decrypt the ciphertext. The code also includes error handling for encryption and decryption operations.
  • Loading branch information
rafagomes committed Aug 10, 2024
1 parent 0fcbad6 commit 408e8e4
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,37 @@ go get github.com/rafagomes/ecies-bls12381
### Import the package

```go
package main

import (
"github.com/rafagomes/ecies-bls12381"
"fmt"

eciesbls12381 "github.com/rafagomes/ecies-bls12381"
)

func main() {
// Generate key pair
publicKey, privateKey := eciesbls12381.GenerateECKeypair()
fmt.Println("Public Key:", publicKey)
fmt.Println("Private Key:", privateKey)

// Encrypt a message
message := []byte("Hello, BLS12381!")
ciphertext, err := eciesbls12381.EncryptWithEC(publicKey, message)
if err != nil {
fmt.Println("Encryption error:", err)
return
}
fmt.Println("Ciphertext:", ciphertext)

// Decrypt the message
plaintext, err := eciesbls12381.DecryptWithEC(privateKey, ciphertext)
if err != nil {
fmt.Println("Decryption error:", err)
return
}
fmt.Println("Plaintext:", string(plaintext))
}
```

### Code Examples
Expand Down

0 comments on commit 408e8e4

Please sign in to comment.