開源工具 DotnetRSA 快速生成和轉換RSA祕鑰

一.簡介

DotnetRSA 是一個利用 .NET Core 2.1 開發的 .NET Global Tool,是能夠想npm全局安裝同樣,安裝在你的系統中,只需敲一行命令即可以快速生成RSA加密算法所需的祕鑰,目前支持三種格式的祕鑰,分別爲:xml、pkcs一、pkcs8。它還支持三種格式祕鑰的相互轉換。git

二.安裝

使用 DotnetRSA 須要你的系統具有.NET Core >=2.1 的環境,若沒有請訪問官網,按照提示進行安裝:https://www.microsoft.com/net/learn/get-started/windowsgithub

輸入一句命令即可以安裝:算法

dotnet tool install -g dotnetrsa

安裝成功會有以下提示:shell

1528035457178

同時輸入命令 dotnetrsa 會出現以下提示:npm

1528035498598

三.使用

1.生成祕鑰

生成祕鑰使用命令 dontetrsa gen,加入 -h 獲取幫助:windows

Generate xml, pkcs1, pkcs8 keys.

Usage: dotnetrsa gen [options]

Options:
  -h|--help           Show help information
  -f|--format         Required.Gen keys's format.The value must be xml, pkcs1 ,pkcs8.
  -s|--size <int>     Key Size.Default 2048.
  --pem               Pem Format. true of false.Default false.
  -o|--output <path>  File output path.If you do not specify it will be output in the current directory.

-f 或者 --format:指須要生成的格式,能夠爲 xml、pkcs一、pkcs8ui

-s 或者 --size :指須要生成的祕鑰長度,默認爲2048加密

--pem :只是否帶有pem格式,值爲 true 或者 false,默認爲 falsecode

-o 或者 --output :指祕鑰保存的路徑,默認保存在當前文件夾orm

生成一個長度爲2048的xml格式的祕鑰示例:

dotnetrsa gen -s 2048 -f xml

2.轉換祕鑰

轉換祕鑰使用命令 dontetrsa convert ,加入-h` 獲取幫助:

Usage: dotnetrsa convert [arguments] [options]

Arguments:
  KeyFilePath         Required.Secret key file path.

Options:
  -h|--help           Show help information
  -f|--from <format>  Required.Source format.The value must be xml, pkcs1,pkcs8.
  -t|--to <format>    Required.Target format.The value must be xml, pkcs1,pkcs8.
  -k                  Required.Key type.The value must be pri, pub.'pub' represents the public key.
  -o|--output <path>  File output path.If you do not specify it will be output in the current directory.

KeyFilePath:指定被轉換的祕鑰的路徑

-f 或者 --from :該字段爲必須指定,指被轉換的祕鑰的格式,值只能爲 xml、pkcs一、pkcs8

-t 或者 --to:該字段爲必須指定,指須要轉換的目標格式,值只能爲 xml、pkcs一、pkcs8

-k :指被轉換的祕鑰的類型,公鑰或者私鑰,值只能爲 pri 或者 pub ,分別表明公鑰和私鑰

-o :轉換的祕鑰的輸出路徑,默認爲當前目錄

將一個格式爲xml的私鑰轉換爲pkcs1,示例:

dotnetrsa convert c:\xml_private.key -f xml -t pkcs1 -k pri

四.參考資料

DotnetRSA 生成和轉換祕鑰使用了開源項目 RSAUtil :https://github.com/stulzq/RSAUtil

DotnetRSA 的開源地址:https://github.com/stulzq/dotnetrsa

相關文章
相關標籤/搜索