生成方式:使用OpenSSL命令生成。
首先进入OpenSSL工具,再输入以下命令:
OpenSSLgenrsa-outrsa_private_key.pem#生成私钥OpenSSLpkcs8-topk8-informPEM-inrsa_private_key.pem-outformPEM-nocrypt-outrsa_private_key_pkcs8.pem#Java开发者需要将私钥转换成
PKCS8格式
OpenSSLrsa-inrsa_private_key.pem-pubout-outrsa_public_key.pem#生成公OpenSSLexit#退出OpenSSL程序
经过以上步骤,开发者可以在当前文件夹中(OpenSSL运行文件夹),看到rsa_private_key.pem(RSA私钥)、rsa_private_key_pkcs8.pem(pkcs8格式RSA私钥)和rsa_public_key.pem(对应RSA公钥)3个文件。开发者将私钥保留,将公钥提交给百度电商开放平台,用于验证签名。
注意:对于使用Java的开发者,将pkcs8在console中输出的私钥去除头尾、换行和空格,作为开发者私钥,对于.NET和PHP的开发者来说,无需进行pkcs8命令行操作。
标准的私钥文件示例(PHP、.NET使用):
-----BEGINRSAPRIVATEKEY-----IICXQIBAAKBgQCzrQWntOKChNlF9B1l+21rHjALLhUlLgXtvsGFNL3X5KdxUM8PIrXog0tNXiuW8XPoP3o25y/gKNWyUfzyRD/0Eu4NvHH4IzMAte9adj2prq3niDhoCNKf9KsyHYTxvsu3Sw66ejQqKobT74SSZ9EHm1UF7n64muso9ofd+RPFIQIDAQABAoGBAJ30+ya/p+5Uemq8PGgejMgCBvydK6u+9SlYbOr9PfShqO6+uvm0azWYz0eaBToy1NIVlAzWW8l2PMACwhv+EjW4oHe++6UIvAPrWVBnPlPlpaTx+Z/QVdm0GWjm2Jnd1CToB2jeLDfGm9wBvpVCVeLz9wdvNIRnmOaAoD21BAkEA19DHseFLeT4zhNlYXg4Vz9tUhXFm7RL6fTXbUFI8WYpUK7PyCYTirjAuU8jbh5rCpf8MOolH8C5Z9sthM5FWyQJBANUhlPlpjR6LH7lkQ7Oatqp4JpZioaPdo2xGK0vTOT5k9hnpAjRrhPNRZ5ORIM+qkkblOHHFr4RtjbU2DLIIL5kCQAjk/OXy4BZuHtdx0be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fDeuk3I5wMLYM4w2eoy0AQ7QwH6WcTYtUoTHamxeGwJZ7roga8=-----ENDPRIVATEKEY-----
标准的公钥文件示例(PHP、.NET使用):
-----BEGINPUBLICKEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCzrQWntOKChNlF9B1l+21rHjALLhUlLgXtvsGFNL3X5KdxUM8PIrXog0tNXiuW8XPoP3o25y/gKNWyUfzyRD/0Eu4NvHH4IzMAte9adj2prq3niDhoCNKf9KsyHYTxvsu3Sw66ejQqKobT74SSZ9EHm1UF7n64muso9ofd+RPFIQIDAQAB-----ENDPUBLICKEY-----