生成私钥和公钥OpenSSL

生成私钥和公钥OpenSSL,openssl,rsa,private-key,public-key,Openssl,Rsa,Private Key,Public Key,我有以下用于OpenSSL生成私钥和公钥的命令: openssl genrsa –aes-128-cbc –out priv.pem –passout pass:[privateKeyPass] 2048 及 。。。但它们不起作用。对于第一个命令,我得到以下错误: usage: genrsa [args] [numbits] -des encrypt the generated key with DES in cbc mode -des3 encr

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

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

。。。但它们不起作用。对于第一个命令,我得到以下错误:

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

正如我从输出中看到的,您选择了错误的算法。 你不应该通过
-aes128
而不是
-aes-128-cbc


根据手册,我假设
-aes-128-cbc
openssl enc
的合适参数,但我不知道它是否适用于
genrsa
“genrsa”只生成一个RSA密钥

“req”然后使用该键发出x509样式的请求

如果您只需要rsa密钥对,请使用genrsa

如果需要密钥对和签名的x509请求,请使用“genrsa”和“req”

或者,“req”也可以为您生成该密钥(即,它封装了“genrsa”命令(和gendh)

因此:

几乎相当于

 openssl req -new -x509 -keyout privkey.pem  -newkey rsa:2048
除了与“genrsa”不同,“req”不允许您指定aes128作为加密


因此,在许多企业设置中,需要分两步来充分控制应用的密钥加密。

我想知道参数的顺序是否重要?命令中的一些破折号实际上是en破折号(–)而不是连字符(-)。此命令起到了作用:openssl req-new-x509-key new.pem-days 3650-out cert.crt。注意-x509生成自签名证书。如果要生成证书请求,请忽略此选项。
 openssl genrsa -aes128 -out privkey.pem 2048
 openssl req -new -x509 -key privkey.pem 
 openssl req -new -x509 -keyout privkey.pem  -newkey rsa:2048