如何使用OpenSSL从.cer中提取RSA公钥并将其存储在.pem中? [英] How to extract the RSA public key from a .cer and store it in a .pem using OpenSSL?

查看:1321
本文介绍了如何使用OpenSSL从.cer中提取RSA公钥并将其存储在.pem中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从*.cer文件中提取公钥(RSA).我希望提取密钥并将其存储在.pem文件中,以便可以使用 jsencrypt .

I have the requirement to extract the public key (RSA) from a *.cer file. I wish to extract the key and store it in a .pem file so I can use its value to encrypt values using jsencrypt.

以下命令将.cer转换为.pem:

openssl x509 -inform der -in certificate.cer -out certificate.pem

但是,它不会生成具有公钥的文件,而是具有*.cer文件内容的文件.

Yet it doesn't generate a file with the public key but a file with the contents of the *.cer file.

-----BEGIN CERTIFICATE-----
MIICPDCCAamgAwIBAg............
*lots of extra contents*
-----END CERTIFICATE-----

我应该使用什么命令来提取公钥并将其存储在.pem文件中?

What command should I use to extract the public key and store it in a .pem file?

推荐答案

使用此命令,我可以生成包含公用密钥内容的.pem.

Using this command I was able to generate the .pem with the contents of the public key.

openssl x509 -inform der -in certificate.cer -pubkey -noout > certificate_publickey.pem

哪个会产生:

-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCsM+whXrxmbCkPfkwY2EehYpIp
*blah blah blah blah*
-----END PUBLIC KEY-----

这篇关于如何使用OpenSSL从.cer中提取RSA公钥并将其存储在.pem中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆