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:
- Download Alipay API Tool.
- Extract AlipayApiTool.zip.
- Depending on your operating system, execute Run_Windows.bat.
- Click New to generate a key pair.
macOS / Linux:
- Install OpenSSL
Linux:
copy
sudo apt install opensslmacOS:
copy
brew install openssl- 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 keyKey pair validation
Window:
Complete the following steps to validate your key pair:
- Depending on your operating system, execute Run_Windows.bat.
- Enter your private key and public key in the fields.
- Click Validate to see whether the private key and public key matches.
macOS / Linux:
- Install OpenSSL
- 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