应用公钥生成方法

推荐使用 OpenSSL 工具生成密钥,以下是使用 OpenSSL 工具生成 RSA 公私钥对的方法:

Windows

打开命令行终端(推荐使用 Git Bash,Git官方客户端默认集成了 OpenSSL 工具),分别执行如下命令生成 RSA 公私钥对。

//生成私钥
# openssl.exe genrsa -out /your/path/app_private_key.pem 2048  
//生成对应公钥
# openssl.exe rsa -in /your/path/app_private_key.pem -pubout -out /your/path/app_public_key.pem

Linux和Mac

打开命令行终端,分别执行如下命令生成 RSA 公私钥对。

//生成私钥
$ openssl genrsa -out /your/path/app_private_key.pem 2048  
//生成对应公钥
$ openssl rsa -in /your/path/app_private_key.pem -pubout -out /your/path/app_public_key.pem

在 /your/path/ 文件夹下面可以看到 app_private_key.pem(RSA私钥)和 app_public_key.pem(RSA 公钥)2个文件。将RSA私钥保留,将RSA公钥配置到商米开放平台用于验证签名。以下为私钥文件和公钥文件示例。

RSA 私钥文件示例

-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAtI2kf6XdO09so4Wt+IlZwy4OVpPwYJn4DXtb0bs+Q0WoLi+o
xTwDV9l3fNekUWv5Ux/XOd4D1mNzRb/uBXNWjSckAK0c5n3P3yX2XAfQmHfNdg5F
Cjb78bHQYhm59WiyDXFBXOpfiGejjQCK5yptMzuVOAOGC89kSOVgLKddSxOa+ZSN
bD6g5gexxYY4zpHkyVJwzX2jOVEt+FciMAtxMVxY4HkkVWC19YhMJTBVJRBeHSeH
pdt5xwtvKynOlTgpZSDm+Nx4ifhNVSmuMU7R0pCJFtO9UQx9WKnERCOxRsY/QEHZ
rYBmGTSByzaKsKnk6puG3wEsFFqyBOE8MO29JwIDAQABAoIBAAd2l2cjXwq1lMMJ
opBUdR5pR/RyNwx3MNa106zOtZsoRPRryeklOuolthe1/jfTY8H43fepYrU49Snb
7iXRh7Fb/dP9U+V/K9mIgy94rzmuMhMAMgBjF3T9KaT0dUhcpIeDt/T0RzCnQA5z
CErX6R2mB9wB4UeZsgaFXL1bybJxsjpd55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