如何从----- BEGIN CERTIFICATE -----从.crt和.pem文件获取RSA密钥? [英] How to get RSA key from -----BEGIN CERTIFICATE----- from.crt and .pem file?

查看:4679
本文介绍了如何从----- BEGIN CERTIFICATE -----从.crt和.pem文件获取RSA密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的.crt和.pem文件带有

I'm having .crt and .pem file with

-----BEGIN CERTIFICATE-----

MIIFSDCCBDCg........................................

-----END CERTIFICATE-----

,我想要此文件中的RSA密钥.

and I want RSA key from this file.

任何人都知道我们如何做到这一点.

anyone is having any idea that how we can do that.

我在命令下面一一使用了

I have used below command one by one

openssl rsa -in XXX.crt -out input1.der -outform DER
openssl rsa -in input1.der -inform DER -out key.pem -outform PEM

但是,它给出了错误:

无法加载私钥140331982231200:错误:0906D06C:PEM
例程:PEM_read_bio:无起始行:pem_lib.c:703:期望:任何 私钥

unable to load Private Key 140331982231200:error:0906D06C:PEM
routines:PEM_read_bio:no start line:pem_lib.c:703:Expecting: ANY PRIVATE KEY

我也使用了不同的命令,但是它给出了以上错误.

and I have also used different command but it give above error.

推荐答案

-----BEGIN CERTIFICATE-----

MIIFSDCCBDCg........................................

-----END CERTIFICATE-----

这是pem格式的证书,是公钥的包装.证书应该是公开的并且可以分发,但是私钥(顾名思义)应该保密.因此,证书永远不能包含私钥.

This is a certificate in pem format which is a wrapper over public key. A Certificate is supposed to be public and can be distributed, but private key (as the name suggest) is supposed to be kept secret. So a certificate can never contain a private key.

您提到,您也有一个".pem"文件.内容是什么?它是否以-----BEGIN RSA PRIVATE KEY-----开头.如果是的话,那将是您的私钥.

You mentioned, you have a ´.pem´ file too. What is it's content? Does it start with -----BEGIN RSA PRIVATE KEY-----. If yes, it would be your private key.

您正在尝试的命令: openssl rsa 它在输入中需要一个私钥,但是您正在为其提供证书.因此是错误.

The command you are trying: openssl rsa It expects a private key in input, but you are supplying it a certificate. Hence the error.

这篇关于如何从----- BEGIN CERTIFICATE -----从.crt和.pem文件获取RSA密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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