The following example walks you through how to get started by creating and importing a keystore file, extracting and importing the public keys in the required formats and verifying the contents of a sample data file using both implementations in Rust and Node.js.
The workflow to be used:
- Creates a pair of 4096-bit RSA private and public keys, in both PEM and DER formats
- Imports a signature persisted in HEX format and a file with plain text contents
- Recreates the original byte array representation and hashes it using SHA-256
- And finally uses the public key provided to verify the data contents matches the signature provided
In order to get us started, we will need a set of keys to be used for signing and verifing the contents of the dataprovided.
Create a private/public key pair based on RSA in PEM format.
openssl genrsa -out key.pem 4096
Output the DER representation of the private key, needed for the Rust signing implementation.
openssl rsa -in key.pem \
-inform PEM \
-outform DER \
-out key.der
Extract a public key from the private one in DER representation to be used by the Rust verification implementation.
openssl rsa -in key.der \
-inform DER \
-RSAPublicKey_out \
-outform DER \
-out key.pub.der
Extract a public key from the private one in PEM representation to be used by the Node.js verification implementation.
openssl rsa -in key.pem \
-inform PEM \
-RSAPublicKey_out \
-outform PEM \
-out key.pub.pem
- Sign the
data.txt
with the private key and create thedata.txt.sign
file by running the Rust sign implementation.
cargo run -- sign
Note: This example already comes with data.txt
and data.txt.sign
files, but feel free to change the contents of the first one to verify the correct behavior of the implementations.
-
Verify the contents in
data.txt.sign
using the public key and the contents ofdata.txt
. For this, one of the following options can be used:- Run the Rust verification implementation under the
/rust
directory:
cargo run -- verify
- Run the Node.js verification implementation under the
/ts
directory:
npm start
- Run the Rust verification implementation under the
Runs an example making a request to the Blowfish scan Solana transactions API and verifies the returned signature against the response body with the public key.
For this example to work, you need to provide a valid Blowfish API_KEY
to the terminal command.
API_KEY={your-key-here} cargo run -- request