.NET Foundation RSA algorithm supporting data encryption, decryption, signature and verification. It supports xml, pkcs1, pkcs8 and pem formats. It also supports key conversion between pkcs1, pkcs8 and xml formats.
Install-Package BWRSAUtilities
Use class
RsaKeyGenerator
. The result returned is a list of two-element strings, Element 1 is the private key and element 2 is the public key.
List<string> keyList = RsaKeyGenerator.XmlKey(2048);
string privateKey = keyList[0];
string publicKey = keyList[1];
List<string> keyList = RsaKeyGenerator.Pkcs1Key(2048);
string privateKey = keyList[0];
string publicKey = keyList[1];
List<string> keyList = RsaKeyGenerator.Pkcs8Key(2048);
string privateKey = keyList[0];
string publicKey = keyList[1];
Use class
RsaKeyConvert
. It supports key conversion for xml, pkcs1 and pkcs8.
- Private Key :
RsaKeyConvert.PrivateKeyXmlToPkcs1()
- Public Key :
RsaKeyConvert.PublicKeyXmlToPem()
- Private Key :
RsaKeyConvert.PrivateKeyXmlToPkcs8()
- Public Key :
RsaKeyConvert.PublicKeyXmlToPem()
- Private Key :
RsaKeyConvert.PrivateKeyPkcs1ToXml()
- Public Key :
RsaKeyConvert.PublicKeyPemToXml()
- Private Key :
RsaKeyConvert.PrivateKeyPkcs1ToPkcs8()
- Public Key : No conversion required
- Private Key :
RsaKeyConvert.PrivateKeyPkcs8ToXml()
- Public Key :
RsaKeyConvert.PublicKeyPemToXml()
- Private Key :
RsaKeyConvert.PrivateKeyPkcs8ToPkcs1()
- Public Key : No conversion required
XML, Pkcs1, Pkcs8 respectively corresponding categories:
RsaXmlUtil
,RsaPkcs1Util
,RsaPkcs8Util
. They inherit from the abstract classRSAUtilBase
- Encrypt:
RSAUtilBase.Encrypt()
- Decrypt:
RSAUtilBase.Decrypt()
- Sign:
RSAUtilBase.SignData()
- Verify:
RSAUtilBase.VerifyData()
Use class
RsaPemFormatHelper
.
-
Format Pkcs1 format private key:
RsaPemFormatHelper.Pkcs1PrivateKeyFormat()
-
Remove the Pkcs1 format private key format:
RsaPemFormatHelper.Pkcs1PrivateKeyFormatRemove()
-
Format Pkcs8 format private key:
RsaPemFormatHelper.Pkcs8PrivateKeyFormat()
-
Remove the Pkcs8 format private key format:
RsaPemFormatHelper.Pkcs8PrivateKeyFormatRemove()