如何使用openssl创建公钥和私钥? [英] How to create public and private key with openssl?

查看:185
本文介绍了如何使用openssl创建公钥和私钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是如何在Windows中使用OpenSSL创建公钥和私钥,以及如何将创建的公钥放入.crt文件中,并将私钥放入.pcks8文件中,以便使用这两个密钥进行签名Java中的SAML断言?

My question is how to create a public key and private key with OpenSSL in windows and how to put the created public key in .crt file and the private one in .pcks8 file in order to use this two keys to sign a SAML assertion in Java?

谢谢.

推荐答案

您可以使用genrsa上下文(最后一个数字是密钥长度,以位为单位)生成一个公共-私有密钥对:

You can generate a public-private keypair with the genrsa context (the last number is the keylength in bits):

openssl genrsa -out keypair.pem 2048

要提取公共部分,请使用rsa上下文:

To extract the public part, use the rsa context:

openssl rsa -in keypair.pem -pubout -out publickey.crt

最后,使用pkcs8上下文将原始密钥对转换为PKCS#8格式:

Finally, convert the original keypair to PKCS#8 format with the pkcs8 context:

openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in keypair.pem -out pkcs8.key

这篇关于如何使用openssl创建公钥和私钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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