+
+
+
+
+
+
+[](?)
+
+[](?)
+
+[](?)
+
+[](?)
+
+[](?)
+
+[](?)
+
+# :open_book:Documentation
+
+## Encryption Paddings
+
+> In the table below, Frame is the support of .NET Framework, Core is the support of .NET Core, and BC is the support of the BouncyCastle encryption enhancement library (can be registered through the RSA_Util.UseBouncyCastle method); √ means support, × means no support, and other values are A certain version starts to support; among them, the mask generation function MGF1 of OAEP uses the same Hash algorithm as OAEP.
+
+Padding|Algorithm|Frame|Core|BC
+:-|:-|:-:|:-:|:-:
+NO|RSA/ECB/NoPadding|√|√|√
+PKCS1 |RSA/ECB/PKCS1Padding|√|√|√
+OAEP+SHA1 |RSA/ECB/OAEPwithSHA-1andMGF1Padding|√|√|√
+OAEP+SHA256|RSA/ECB/OAEPwithSHA-256andMGF1Padding|4.6+|√|√
+OAEP+SHA224|RSA/ECB/OAEPwithSHA-224andMGF1Padding|×|×|√
+OAEP+SHA384|RSA/ECB/OAEPwithSHA-384andMGF1Padding|4.6+|√|√
+OAEP+SHA512|RSA/ECB/OAEPwithSHA-512andMGF1Padding|4.6+|√|√
+OAEP+SHA-512/224|RSA/ECB/OAEPwithSHA-512/224andMGF1Padding|×|×|√
+OAEP+SHA-512/256|RSA/ECB/OAEPwithSHA-512/256andMGF1Padding|×|×|√
+OAEP+SHA3-256|RSA/ECB/OAEPwithSHA3-256andMGF1Padding|×|8+|√
+OAEP+SHA3-224|RSA/ECB/OAEPwithSHA3-224andMGF1Padding|×|×|√
+OAEP+SHA3-384|RSA/ECB/OAEPwithSHA3-384andMGF1Padding|×|8+|√
+OAEP+SHA3-512|RSA/ECB/OAEPwithSHA3-512andMGF1Padding|×|8+|√
+OAEP+MD5 |RSA/ECB/OAEPwithMD5andMGF1Padding|4.6+|√|√
+
+
+
+## Signature Paddings
+
+> In the table below, Frame is the support of .NET Framework, Core is the support of .NET Core, and BC is the support of the BouncyCastle encryption enhancement library (can be registered through the RSA_Util.UseBouncyCastle method); √ means support, × means no support, and other values are A certain version starts to support; the number of salt bytes of PSS is equal to the number of bytes of the hash algorithm used, the mask generation function MGF1 of PSS uses the same hash algorithm as that of PSS, and the value of the trailing attribute TrailerField is fixed at 0xBC.
+
+Padding|Algorithm|Frame|Core|BC
+:-|:-|:-:|:-:|:-:
+SHA1 ... SHA3-512|Same as PKCS1+SHA***|||
+PKCS1+SHA1 |SHA1withRSA|√|√|√
+PKCS1+SHA256|SHA256withRSA|√|√|√
+PKCS1+SHA224|SHA224withRSA|×|×|√
+PKCS1+SHA384|SHA384withRSA|√|√|√
+PKCS1+SHA512|SHA512withRSA|√|√|√
+PKCS1+SHA-512/224|SHA512/224withRSA|×|×|√
+PKCS1+SHA-512/256|SHA512/256withRSA|×|×|√
+PKCS1+SHA3-256|SHA3-256withRSA|×|8+|√
+PKCS1+SHA3-224|SHA3-224withRSA|×|×|√
+PKCS1+SHA3-384|SHA3-384withRSA|×|8+|√
+PKCS1+SHA3-512|SHA3-512withRSA|×|8+|√
+PKCS1+MD5 |MD5withRSA|√|√|√
+PSS+SHA1 |SHA1withRSA/PSS|4.6+|√|√
+PSS+SHA256|SHA256withRSA/PSS|4.6+|√|√
+PSS+SHA224|SHA224withRSA/PSS|×|×|√
+PSS+SHA384|SHA384withRSA/PSS|4.6+|√|√
+PSS+SHA512|SHA512withRSA/PSS|4.6+|√|√
+PSS+SHA-512/224|SHA512/224withRSA/PSS|×|×|√
+PSS+SHA-512/256|SHA512/256withRSA/PSS|×|×|√
+PSS+SHA3-256|SHA3-256withRSA/PSS|×|8+|√
+PSS+SHA3-224|SHA3-224withRSA/PSS|×|×|√
+PSS+SHA3-384|SHA3-384withRSA/PSS|×|8+|√
+PSS+SHA3-512|SHA3-512withRSA/PSS|×|8+|√
+PSS+MD5 |MD5withRSA/PSS|4.6+|√|√
+
+
+
+[](?)
+
+[](?)
+
+## RSA_PEM Class Documentation
+The `RSA_PEM.cs` file does not depend on any files, you can directly copy this file to use in your project; through `FromPEM`, `ToPEM` and `FromXML`, `ToXML` two pairs of methods, you can implement PEM `PKCS#1`, `PKCS#8` mutual conversion, PEM, XML mutual conversion.
+
+Note: `openssl rsa -in privateKey -pubout` exports PKCS#8 format public key (used more), `openssl rsa -pubin -in PKCS#8 publicKey -RSAPublicKey_out` exports PKCS#1 format public key (rarely used).
+
+
+### Static Attributes and Methods
+
+`RSA_PEM` **FromPEM(string pem)**: Create RSA with PEM format key, support PKCS#1, PKCS#8 format PEM, error will throw an exception. pem format such as: `-----BEGIN XXX KEY-----....-----END XXX KEY-----`.
+
+`RSA_PEM` **FromXML(string xml)**: Convert the key in XML format to PEM, support public key xml, private key xml, and an exception will be thrown if an error occurs. xml format such as: `
+
+
+
+
+
+
+[](?)
+
+[](?)
+
+[](?)
+
+[](?)
+
+[](?)
+
+[](?)
+
+# :open_book:文档
+
+## 加密填充方式
+
+> 下表中Frame为.NET Framework支持情况,Core为.NET Core的支持情况,BC为BouncyCastle加密增强库支持情况(可通过RSA_Util.UseBouncyCastle方法注册);√为支持,×为不支持,其他值为某版本开始支持;其中OAEP的掩码生成函数MGF1使用和OAEP相同的Hash算法。
+
+加密填充方式|Algorithm|Frame|Core|BC
+:-|:-|:-:|:-:|:-:
+NO|RSA/ECB/NoPadding|√|√|√
+PKCS1 |RSA/ECB/PKCS1Padding|√|√|√
+OAEP+SHA1 |RSA/ECB/OAEPwithSHA-1andMGF1Padding|√|√|√
+OAEP+SHA256|RSA/ECB/OAEPwithSHA-256andMGF1Padding|4.6+|√|√
+OAEP+SHA224|RSA/ECB/OAEPwithSHA-224andMGF1Padding|×|×|√
+OAEP+SHA384|RSA/ECB/OAEPwithSHA-384andMGF1Padding|4.6+|√|√
+OAEP+SHA512|RSA/ECB/OAEPwithSHA-512andMGF1Padding|4.6+|√|√
+OAEP+SHA-512/224|RSA/ECB/OAEPwithSHA-512/224andMGF1Padding|×|×|√
+OAEP+SHA-512/256|RSA/ECB/OAEPwithSHA-512/256andMGF1Padding|×|×|√
+OAEP+SHA3-256|RSA/ECB/OAEPwithSHA3-256andMGF1Padding|×|8+|√
+OAEP+SHA3-224|RSA/ECB/OAEPwithSHA3-224andMGF1Padding|×|×|√
+OAEP+SHA3-384|RSA/ECB/OAEPwithSHA3-384andMGF1Padding|×|8+|√
+OAEP+SHA3-512|RSA/ECB/OAEPwithSHA3-512andMGF1Padding|×|8+|√
+OAEP+MD5 |RSA/ECB/OAEPwithMD5andMGF1Padding|4.6+|√|√
+
+
+
+## 签名填充方式
+
+> 下表中Frame为.NET Framework支持情况,Core为.NET Core的支持情况,BC为BouncyCastle加密增强库支持情况(可通过RSA_Util.UseBouncyCastle方法注册);√为支持,×为不支持,其他值为某版本开始支持;其中PSS的salt字节数等于使用的Hash算法字节数,PSS的掩码生成函数MGF1使用和PSS相同的Hash算法,跟踪属性TrailerField取值固定为0xBC。
+
+签名填充方式|Algorithm|Frame|Core|BC
+:-|:-|:-:|:-:|:-:
+SHA1 ... SHA3-512|等同于PKCS1+SHA***|||
+PKCS1+SHA1 |SHA1withRSA|√|√|√
+PKCS1+SHA256|SHA256withRSA|√|√|√
+PKCS1+SHA224|SHA224withRSA|×|×|√
+PKCS1+SHA384|SHA384withRSA|√|√|√
+PKCS1+SHA512|SHA512withRSA|√|√|√
+PKCS1+SHA-512/224|SHA512/224withRSA|×|×|√
+PKCS1+SHA-512/256|SHA512/256withRSA|×|×|√
+PKCS1+SHA3-256|SHA3-256withRSA|×|8+|√
+PKCS1+SHA3-224|SHA3-224withRSA|×|×|√
+PKCS1+SHA3-384|SHA3-384withRSA|×|8+|√
+PKCS1+SHA3-512|SHA3-512withRSA|×|8+|√
+PKCS1+MD5 |MD5withRSA|√|√|√
+PSS+SHA1 |SHA1withRSA/PSS|4.6+|√|√
+PSS+SHA256|SHA256withRSA/PSS|4.6+|√|√
+PSS+SHA224|SHA224withRSA/PSS|×|×|√
+PSS+SHA384|SHA384withRSA/PSS|4.6+|√|√
+PSS+SHA512|SHA512withRSA/PSS|4.6+|√|√
+PSS+SHA-512/224|SHA512/224withRSA/PSS|×|×|√
+PSS+SHA-512/256|SHA512/256withRSA/PSS|×|×|√
+PSS+SHA3-256|SHA3-256withRSA/PSS|×|8+|√
+PSS+SHA3-224|SHA3-224withRSA/PSS|×|×|√
+PSS+SHA3-384|SHA3-384withRSA/PSS|×|8+|√
+PSS+SHA3-512|SHA3-512withRSA/PSS|×|8+|√
+PSS+MD5 |MD5withRSA/PSS|4.6+|√|√
+
+
+
+[](?)
+
+[](?)
+
+## RSA_PEM 类文档
+`RSA_PEM.cs`文件不依赖任何文件,可以直接copy这个文件到你项目中用;通过`FromPEM`、`ToPEM` 和`FromXML`、`ToXML`这两对方法,可以实现PEM`PKCS#1`、`PKCS#8`相互转换,PEM、XML的相互转换。
+
+注:`openssl rsa -in 私钥文件 -pubout`导出的是PKCS#8格式公钥(用的比较多),`openssl rsa -pubin -in PKCS#8公钥文件 -RSAPublicKey_out`导出的是PKCS#1格式公钥(用的比较少)。
+
+
+### 静态属性和方法
+
+`RSA_PEM` **FromPEM(string pem)**:用PEM格式密钥对创建RSA,支持PKCS#1、PKCS#8格式的PEM,出错将会抛出异常。pem格式如:`-----BEGIN XXX KEY-----....-----END XXX KEY-----`。
+
+`RSA_PEM` **FromXML(string xml)**:将XML格式密钥转成PEM,支持公钥xml、私钥xml,出错将会抛出异常。xml格式如:`/nSZaBqEGehINeMa805aAqjNOhlHNYGZmF/C4evMvsc=
3/GsDJA/AnKq/lqbpCr1OB5h2wIKsLlPGafPljFzN9s=
+N3qwya7gWN568BuciUwkSlgWVlORusk267Nkkiu3jc=
05o0BiIaDFYtHYNUh5/ROgDSkWqPXjy8Nlmh0S6QdNM=
" + Convert.ToBase64String(Val_P) + "
"); + str.Append("" + Convert.ToBase64String(Val_Q) + ""); + str.Append("
+ ///
null: 等同于PKCS1
+ ///
"": 等同于PKCS1
+ ///
RSA: 等同于PKCS1
+ ///
PKCS: 等同于PKCS1
+ ///
RAW: 等同于NO
+ ///
OAEP: 等同于OAEP+SHA1
+ ///
RSA/ECB/OAEPPadding: 等同于OAEP+SHA1
+ ///
+ ///
NO: RSA/ECB/NoPadding
+ ///
PKCS1: RSA/ECB/PKCS1Padding (默认值,等同于"RSA")
+ ///
OAEP+SHA1 : RSA/ECB/OAEPwithSHA-1andMGF1Padding
+ ///
OAEP+SHA256: RSA/ECB/OAEPwithSHA-256andMGF1Padding
+ ///
OAEP+SHA224: RSA/ECB/OAEPwithSHA-224andMGF1Padding
+ ///
OAEP+SHA384: RSA/ECB/OAEPwithSHA-384andMGF1Padding
+ ///
OAEP+SHA512: RSA/ECB/OAEPwithSHA-512andMGF1Padding
+ ///
OAEP+SHA-512/224: RSA/ECB/OAEPwithSHA-512/224andMGF1Padding (SHA-512/*** 2012年发布)
+ ///
OAEP+SHA-512/256: RSA/ECB/OAEPwithSHA-512/256andMGF1Padding
+ ///
OAEP+SHA3-256: RSA/ECB/OAEPwithSHA3-256andMGF1Padding (SHA3-*** 2015年发布)
+ ///
OAEP+SHA3-224: RSA/ECB/OAEPwithSHA3-224andMGF1Padding
+ ///
OAEP+SHA3-384: RSA/ECB/OAEPwithSHA3-384andMGF1Padding
+ ///
OAEP+SHA3-512: RSA/ECB/OAEPwithSHA3-512andMGF1Padding
+ ///
OAEP+MD5 : RSA/ECB/OAEPwithMD5andMGF1Padding
+ ///
+ ///
如果padding包含RSA字符串,将原样返回此值,用于提供可能支持的任何值
+ ///
非以上取值,将会抛异常
+ ///
+ ///
其中OAEP的掩码生成函数MGF1使用和OAEP相同的Hash算法
+ ///
+ ///
以上填充模式全部可用于BouncyCastle的RSA实现;但如果是使用的.NET自带的RSA实现,将会有部分模式无法支持:不支持全部SHA224、SHA-512/256、SHA-512/224,SHA3需要.NET8以上才支持,.NET Framework 4.5及以下只持OAEP+SHA1不支持其他OAEP
+ ///
+ ///
参考:https://learn.microsoft.com/zh-cn/dotnet/api/system.security.cryptography.rsaencryptionpadding
+ ///
+ ///
+ ///
SHA*** : 等同于PKCS1+SHA***,比如"SHA256" == "PKCS1+SHA256"
+ ///
MD5 : 等同于PKCS1+MD5
+ ///
RSASSA-PSS: 等同于PSS+SHA1
+ ///
+ ///
PKCS1+SHA1 : SHA1withRSA
+ ///
PKCS1+SHA256: SHA256withRSA
+ ///
PKCS1+SHA224: SHA224withRSA
+ ///
PKCS1+SHA384: SHA384withRSA
+ ///
PKCS1+SHA512: SHA512withRSA
+ ///
PKCS1+SHA-512/224: SHA512/224withRSA (SHA-512/*** 2012年发布)
+ ///
PKCS1+SHA-512/256: SHA512/256withRSA
+ ///
PKCS1+SHA3-256: SHA3-256withRSA (SHA3-*** 2015年发布)
+ ///
PKCS1+SHA3-224: SHA3-224withRSA
+ ///
PKCS1+SHA3-384: SHA3-384withRSA
+ ///
PKCS1+SHA3-512: SHA3-512withRSA
+ ///
PKCS1+MD5 : MD5withRSA
+ ///
+ ///
PSS+SHA1 : SHA1withRSA/PSS
+ ///
PSS+SHA256: SHA256withRSA/PSS
+ ///
PSS+SHA224: SHA224withRSA/PSS
+ ///
PSS+SHA384: SHA384withRSA/PSS
+ ///
PSS+SHA512: SHA512withRSA/PSS
+ ///
PSS+SHA-512/224: SHA512/224withRSA/PSS (SHA-512/*** 2012年发布)
+ ///
PSS+SHA-512/256: SHA512/256withRSA/PSS
+ ///
PSS+SHA3-256: SHA3-256withRSA/PSS (SHA3-*** 2015年发布)
+ ///
PSS+SHA3-224: SHA3-224withRSA/PSS
+ ///
PSS+SHA3-384: SHA3-384withRSA/PSS
+ ///
PSS+SHA3-512: SHA3-512withRSA/PSS
+ ///
PSS+MD5 : MD5withRSA/PSS
+ ///
+ ///
如果hash包含RSA字符串,将原样返回此值,用于提供可能支持的任何值
+ ///
非以上取值,将会抛异常
+ ///
+ ///
其中PSS的salt字节数等于使用的Hash算法字节数,PSS的掩码生成函数MGF1使用和PSS相同的Hash算法,跟踪属性TrailerField取值固定为0xBC
+ ///
+ ///
以上填充模式全部可用于BouncyCastle的RSA实现;但如果是使用的.NET自带的RSA实现,将会有部分模式无法支持:不支持全部SHA224、SHA-512/256、SHA-512/224,SHA3需要.NET8以上才支持,.NET Framework 4.5及以下不支持PSS
+ ///
+ ///
参考:https://learn.microsoft.com/zh-cn/dotnet/api/system.security.cryptography.rsasignaturepadding
+ ///
+ ///