首页 » 信息技术 »

利用openssl生成RSA私钥和公钥

2019年4月16日 / 55次阅读
加密解密

  • 打开支付宝,搜索“ 529018372 ”,领取专属红包!每日支付每日领。

openssl(不是openssh)是一个很有用的工具包,提供了很多功能,比如生成RSA私钥和公钥。

生成私钥:

xinlin@ubuntu:~/atts$ openssl genrsa
Generating RSA private key, 2048 bit long modulus
............................+++
..............................................................+++
e is 65537 (0x010001)
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAr1pf6TPzOF1aY7YvbpT8P4CTxQRVuOucm8fYT2KOWbsYA8IE
12K7rbzzppBYKuoE3bS5k0/u7BzAIeJQD2Qj6Ozu42LLN/UiC96S4chpCf58DK8Y
5G8mPAeAIRVIMh4WFCVGDpsxajQOKqG/wkLQsloqf984tPPLLVkPF07O5tKAI9NN
aZYAM0EIamE30c86WMkc1Yn6I/cgjUoMF+1YtIMkMr85/aAjsMSh7vEH+W/OB4q/
T6E0ZUlTNBuUO2SakUpjlfeDbaEiQ+2SsscGN9BD19wVTn7gwok9tROsB9TA1Oe5
rkshYZ0KrslhFfb3QN1tyu1ZeVso0yGbVmcuVQIDAQABAoH/X+UMjnvahviGdgEr
702KpS+roBK+zmILQyYHJWLAdlHa0DNKcn+MI3cxx+UoUk+oWZZ75hPQlU8jw2QA
ZGpfOQJZogBlIjTsaZFOwirXRp/lNwqKkmI2hp2TdIQu9zl82YeIyHQWkf3lwWqz
c4kWmHK2yzdHy62Hb0VE+3odrByKNeStRri+Vlo2niy9N2eJWAQufZQOpnq3gIEs
AfGtsEa7X+VTdB9WisYxMu5zUckKV4XXUJKMh27REZfyHg8Io9lAtUeQGUlzrbT6
1+sZur1cslqySdHMW+qbOicDAqpbGYdiEg7Z0zAoMfBKhWLmGayxnq7ENYjoa/as
4BIBAoGBANaF+MMAWji6Dg/Yug9zFhjTQzTCaZYS1OHR/J4Nx0okT3sAVKvsEZ0n
Qk//onEYf8h6pBgf7iwiD17vVhAE4hLQHVKpVsMtOCGYV3nZLmD5Cxa1Pc76k00r
aR7RuvvxINE8+7b80N4wlA5kV4vcfcqyBz7g8orp6tXL43kllwPhAoGBANFBog+W
OBX+gmvSxZcyky7IK1iE79itaONWU4MLw+NZbWgBubsk2eDAKTS6DWbggaY7afnE
4tMMZwlLVfJ0rE+epfKmKzoS+HPu8/qWIA/yQy4qc3+qv4hK2N6gIWTRzrHZ9hle
YqJ9w4hj3qh/jIVEpTA0Qz5NDzIxiO1073j1AoGBALZMKtUrG4BRO1nkBljSp9h4
zweqnidV4Wn1FAMMGmq66H/SDCH8/graLdPlnJkXBJ/M+F035SHD3+QA5tW+EI+E
Iyb3mC9L4gNKfiuhj3QArpehdODKtxpA5Ze3CnrGseidNhqORMBL78U7J9pGiO8S
0m1woyvBFDqShL+SXf6BAoGAXij8dasQ3cTChyY2x0x4skpcRt661nNhiTqlJYi7
wqfQ9UYhfzab2+hcIl+9/Bb2AAkoLL4Nmw4vpx0BNbKOft1SqxdeyCkVJ4XUv2Oi
VcqbtEBh7Ia23OthHvxLSoSmT51Wgh/Ynmmc/NiDrqqGXsl+02wQ/g3K0rk7di5y
O6kCgYEAgbpkHidKx0NvKTwGjD412lD9cg4eAwwiNgSoUYuO9cXlC3dS9sp5buDF
PlX7QUokj8Vgd2bUlYt/oTnNxJX6F/mJG5kAm2y8shs2FtArHF71wLln+sa3tbbl
aCYarEUfS2X1zXfqNZ4XY1hxsN24PElVBoNuvdrh4FHsNASB6P4=
-----END RSA PRIVATE KEY-----
xinlin@ubuntu:~/atts$
xinlin@ubuntu:~/atts$ openssl genrsa 4096 > private.key
Generating RSA private key, 4096 bit long modulus
.++
..........................................................++
e is 65537 (0x010001)

第二个命令,指定了密钥的长度为4096.

生成不加密的私钥。

或者还可以这样:

xinlin@ubuntu:~/atts$ openssl genrsa --help
Usage: genrsa [options]
Valid options are:
-help Display this summary
-3 Use 3 for the E value
-F4 Use F4 (0x10001) for the E value
-f4 Use F4 (0x10001) for the E value
-out val Output the key to specified file
-rand val Load the file(s) into the random number generator
-passout val Output file pass phrase source
-* Encrypt the output with any supported cipher
-engine val Use engine, possibly a hardware device
xinlin@ubuntu:~/atts$
xinlin@ubuntu:~/atts$ openssl genrsa -out private.key 1024
Generating RSA private key, 1024 bit long modulus
...++++++
..++++++
e is 65537 (0x010001)

然后,我们用私钥文件再来导出对应的公钥:

xinlin@ubuntu:~/atts$ openssl rsa --help
Usage: rsa [options]
Valid options are:
-help Display this summary
-inform format Input format, one of DER NET PEM
-outform format Output format, one of DER NET PEM PVK
-in val Input file
-out outfile Output file
-pubin Expect a public key in input file
-pubout Output a public key
-passout val Output file pass phrase source
-passin val Input file pass phrase source
-RSAPublicKey_in Input is an RSAPublicKey
-RSAPublicKey_out Output is an RSAPublicKey
-noout Don't print key out
-text Print the key in text
-modulus Print the RSA key modulus
-check Verify key consistency
-* Any supported cipher
-pvk-strong Enable 'Strong' PVK encoding level (default)
-pvk-weak Enable 'Weak' PVK encoding level
-pvk-none Don't enforce PVK encoding
-engine val Use engine, possibly a hardware device
xinlin@ubuntu:~/atts$ openssl rsa -in private.key -pubout -out public.key
writing RSA key

这样就获得了私钥private.key,以及对应的公钥public.key。

本文链接:https://www.maixj.net/ict/openssl-rsa-20993

相关文章

留言区

《利用openssl生成RSA私钥和公钥》有1条留言

  • 麦新杰

    从私钥生成公钥 []


前一篇:
后一篇:
推一篇:可靠正规,长期稳定,网络兼职项目!!

栏目精选

云上小悟,麦新杰的独立博客

Ctrl+D 收藏本页

栏目


©Copyright 麦新杰 Since 2014 云上小悟独立博客版权所有 备案号:苏ICP备14045477号-1。云上小悟网站部分内容来源于网络,转载目的是为了整合信息,收藏学习,服务大家,有些转载内容也难以判断是否有侵权问题,如果侵犯了您的权益,请及时联系站长,我会立即删除。

网站二维码
go to top