openssl - 生成私钥和公钥 OpenSSL

标签 openssl rsa private-key public-key

我有以下命令用于 OpenSSL 生成私钥和公钥:

openssl genrsa –aes-128-cbc –out priv.pem –passout pass:[privateKeyPass] 2048


openssl req –x509 –new –key priv.pem –passin pass:[privateKeyPass] -days 3650 –out cert.cer

......但他们没有工作。对于第一个命令,我收到以下错误:
usage: genrsa [args] [numbits]
 -des            encrypt the generated key with DES in cbc mode
 -des3           encrypt the generated key with DES in ede cbc mode (168 bit key)
 -seed
                 encrypt PEM output with cbc seed
 -aes128, -aes192, -aes256
                 encrypt PEM output with cbc aes
 -camellia128, -camellia192, -camellia256
                 encrypt PEM output with cbc camellia
 -out file       output the key to 'file
 -passout arg    output file pass phrase source
 -f4             use F4 (0x10001) for the E value
 -3              use 3 for the E value
 -engine e       use engine e, possibly a hardware device.
 -rand file:file:...
                 load the file (or the files in the directory) into
                 the random number generator

我做错了什么?

编辑:
我解决了第一个命令:
openssl genrsa -aes128 -out privkey.pem 2048

但是现在我遇到了第二个错误:
unknown option –x509

最佳答案

'genrsa' 只生成一个 RSA key 。

'req' 然后使用该键发出 x509 样式的请求。

如果您只需要一个 rsa key 对 - 使用 genrsa。

如果您需要 key 对和签名的 x509 请求,请使用“genrsa”,然后使用“req”。

可选地,'req' 也可以为您生成该 key (即它封装了 'genrsa' 命令(和 gendh)。

所以:

 openssl genrsa -aes128 -out privkey.pem 2048
 openssl req -new -x509 -key privkey.pem 

几乎相当于
 openssl req -new -x509 -keyout privkey.pem  -newkey rsa:2048

除了与 'genrsa' 不同,'req' 不允许您指定 aes128 作为加密。

因此,在许多企业设置中,可以通过两个步骤来充分控制所应用的 key 加密。

关于openssl - 生成私钥和公钥 OpenSSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12637171/

相关文章:

python - 使用自定义 openssl 版本编译 python 时的 Coredump

ruby - mysql2 版本 0.5.2 安装失败

c++ - 与/usr/bin/openssl 输出相同的 C/C++ 程序

java - OpenSSL 和 Java 产生不同的 SHA256 RSA 签名

r - 在 R 代码中传递 pfx 证书或在 R 中将 pfx 证书转换为 pem

使用 RSA 进行 Java AES key 交换期间抛出 java.security.InvalidKeyException

jQuery AJAX post 收到 405 错误(不允许 HTTP 动词 POST)

java - 如何在java中将 key 对导入到 keystore 并使 key 不可导出

c# - 支持 PuTTY 私钥 (PPK) 的 SFTP C# 库

ssh - 如果私钥丢失,如何访问服务器