如何从证书中以 .pem 格式保存公钥 [英] How to save public key from a certificate in .pem format

查看:42
本文介绍了如何从证书中以 .pem 格式保存公钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下 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.

我已经看到我可以使用

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 格式保存公钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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