gpt4 book ai didi

openssl - openssl RSA私钥和公钥

转载 作者:行者123 更新时间:2023-12-04 13:23:58 25 4
gpt4 key购买 nike

如果我使用open ssl命令

sudo openssl genrsa -out privkey.pem 2048

要生成rsa key ,它仅生成1个文件。这是私钥。我如何获得公钥。

最佳答案

回答您的问题:用sudo openssl genrsa -out privkey.pem 2048生成的文件包含私钥和公钥。
openssl genrsa generates a key pair。公用 key 是模数(n)公用指数(e):

$ openssl genrsa 2048 > dummy.key
$ openssl rsa -in dummy.key -noout -text

Private-Key: (2048 bit)
modulus:
00:d4:4a:3c:8c:41:b3:9b:a3:26:2d:4b:8c:62:08:
c0:fc:ad:6c:5e:5f:3f:28:e6:a3:7c:3d:43:5e:98:
[...]
publicExponent: 65537 (0x10001)
privateExponent:
00:c7:6e:f6:72:cd:46:6e:70:56:ed:36:8c:2b:8d:
0d:c0:53:2b:fb:7c:7f:59:6d:53:28:e4:64:e5:f9:
d6:84:64:7e:e4:be:20:64:7d:5b:50:06:ba:1f:df:
[...]

您可以使用 -puboutopenssl rsa选项仅提取公钥:
$ openssl rsa -in dummy.key -pubout
writing RSA key
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1Eo8jEGzm6MmLUuMYgjA
[...]
gW6qhadXVsKWQhEhVU9s7V9vJOhfeSSahvuZR0zjursTm6PSJWo7lKNgFCFC0NXO
LQIDAQAB
-----END PUBLIC KEY-----

如果将数据提取到文件中并重新读取,则会看到它包含模数和指数:
$ openssl rsa -in dummy.key -pubout > public.key
$ openssl rsa -in public.key -pubin -noout -text
Public-Key: (2048 bit)
Modulus:
00:d4:4a:3c:8c:41:b3:9b:a3:26:2d:4b:8c:62:08:
c0:fc:ad:6c:5e:5f:3f:28:e6:a3:7c:3d:43:5e:98:
[...]
6f:24:e8:5f:79:24:9a:86:fb:99:47:4c:e3:ba:bb:
13:9b:a3:d2:25:6a:3b:94:a3:60:14:21:42:d0:d5:
ce:2d
Exponent: 65537 (0x10001)
$

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com