RSA2 Key Generation Tools and Validation

Merchants can use Alipay API Tool on window or use command line on macOS / Linux to generate key pairs, and validate whether the public key and private matches.

The following video explains how to generate and validate key pairs with Alipay API Tool:

Key pair generation

Window:

Complete the following steps to generate a key pair:

  1. Download Alipay API Tool.
  2. Extract AlipayApiTool.zip.
  3. Depending on your operating system, execute Run_Windows.bat.
  4. Click New to generate a key pair.
macOS / Linux:
  1. Install OpenSSL

Linux:

copy
sudo apt install openssl

macOS:

copy
brew install openssl
  1. Generate RSA2 key pair
copy
openssl genrsa -out rsa_private_key.pem 2048 ##Generate private key
openssl pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM - nocrypt ##Transform private key into PKCS8 format
openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem ##Generate public key

Key pair validation

Window:

Complete the following steps to validate your key pair:

  1. Depending on your operating system, execute Run_Windows.bat.
  2. Enter your private key and public key in the fields.
  3. Click Validate to see whether the private key and public key matches.
macOS / Linux:
  1. Install OpenSSL
  2. Use the following command to validate the key pair
copy
echo "test data" > test.txt
openssl dgst -sha256 -sign rsa_private_key.key -out signature.bin test.txt
openssl dgst -sha256 -verify rsa_public_key.key -signature signature.bin test.txt