问题描述
我正在使用以下openssl命令将我的公钥存储到.pem文件中.
I am using the below openssl command for storing my public key into a .pem file.
openssl> x509 -in E:/mycert.pem -pubkey -out E:/mypubkey.pem
但是当我尝试使用此命令时,它会将整个证书信息存储在mypubkey.pem文件中.
But when i try to use this command, it is storing the whole certificate info in the mypubkey.pem file.
我已经知道我可以使用保存我的公共密钥
I have seen that i can save my public key using
openssl> x509 -pubkey -noout -in cert.pem > pubkey.pem
但是它抛出一个错误.我不能使用>"运算符.
But it is throwing an error. I can't use ">" operator.
推荐答案
有两种方法可以做到这一点.
There are a couple ways to do this.
首先,无需进入openssl命令提示符模式,只需在Windows提示符下的一个命令行中输入所有内容即可:
First, instead of going into openssl command prompt mode, just enter everything on one command line from the Windows prompt:
E:\> openssl x509 -pubkey -noout -in cert.pem > pubkey.pem
如果由于某种原因,您必须使用openssl命令提示符,只需输入所有内容,直到>".然后,OpenSSL将在屏幕上打印出公钥信息.然后,您可以将其复制并粘贴到名为pubkey.pem的文件中.
If for some reason, you have to use the openssl command prompt, just enter everything up to the ">". Then OpenSSL will print out the public key info to the screen. You can then copy this and paste it into a file called pubkey.pem.
openssl> x509 -pubkey -noout -in cert.pem
输出看起来像这样:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAryQICCl6NZ5gDKrnSztO
3Hy8PEUcuyvg/ikC+VcIo2SFFSf18a3IMYldIugqqqZCs4/4uVW3sbdLs/6PfgdX
7O9D22ZiFWHPYA2k2N744MNiCD1UE+tJyllUhSblK48bn+v1oZHCM0nYQ2NqUkvS
j+hwUU3RiWl7x3D2s9wSdNt7XUtW05a/FXehsPSiJfKvHJJnGOX0BgTvkLnkAOTd
OrUZ/wK69Dzu4IvrN4vs9Nes8vbwPa/ddZEzGR0cQMt0JBkhk9kU/qwqUseP1QRJ
5I1jR4g8aYPL/ke9K35PxZWuDp3U0UPAZ3PjFAh+5T+fc7gzCs9dPzSHloruU+gl
FQIDAQAB
-----END PUBLIC KEY-----
这篇关于如何以.pem格式保存证书中的公钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!