我想用 RSA 和 AES 256 GCM 生成密钥,但每次都会出现以下错误:
$ openssl genpkey -out mkey.pem -aes-256-gcm -algorithm rsa
.........................++++++
..............++++++
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
Error writing key
140735190483024:error:0D0A7072:asn1 encoding routines:PKCS5_pbe2_set_iv:error setting cipher params:p5_pbev2.c:133:
140735190483024:error:2307D00D:PKCS12 routines:PKCS8_encrypt:ASN1 lib:p12_p8e.c:86:
当我尝试使用时,aes-256-ctr
也会收到错误,但略有不同:
$ openssl genpkey -out mkey.pem -aes-256-ctr -algorithm rsa
.................++++++
.....++++++
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
Error writing key
140735190483024:error:0D0A706C:asn1 encoding routines:PKCS5_pbe2_set_iv:cipher has no object identifier:p5_pbev2.c:104:
140735190483024:error:2307D00D:PKCS12 routines:PKCS8_encrypt:ASN1 lib:p12_p8e.c:86:
OpenSSL 版本OpenSSL 1.0.2g 1 Mar 2016
。最高 OS X 10.11。
答案1
OpenSSL 不支持此功能。
从https://www.openssl.org/docs/manmaster/apps/genpkey.html:
-cipher
This option encrypts the private key with the supplied cipher. Any algorithm name
accepted by EVP_get_cipherbyname() is acceptable such as des3.
从https://www.openssl.org/docs/manmaster/apps/enc.html:
The enc program does not support authenticated encryption modes like CCM and GCM.
The utility does not store or retrieve the authentication tag.
您可以在“支持的密码”部分下找到可以指定的密码列表enc.html
:
https://www.openssl.org/docs/manmaster/apps/enc.html#SUPPORTED-CIPHERS