Skip to content

Commit

Permalink
feat: Added example code
Browse files Browse the repository at this point in the history
  • Loading branch information
rafagomes committed Aug 10, 2024
1 parent e4b399d commit 5c641dc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func main() {
fmt.Println("Plaintext:", string(plaintext))
}
```
This can also be found in the [example](example) directory.

## License

Expand Down
31 changes: 31 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"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))
}

0 comments on commit 5c641dc

Please sign in to comment.