使用RSA加密的过程中,经常涉及密钥及公钥的生成,下面是生成方法

1.使用openssl
openssl
2.生成1024位私钥(PEM格式)
genrsa -out test.pem 1024
3.根据私钥生成对应的公钥
rsa -in test.pem -pubout -out testpub.pem
4.转换PEM格式私钥为DER格式私钥
rsa -in test.pem -inform PEM -out test.der -outform DER
5.转换PEM格式公钥为DER格式公钥
rsa -pubin -in testpub.pem -inform PEM -pubout -out testpub.der -outform DER
通过以上步骤,可以得到4个key(PEM和DER各一对).