RsaUtils
Useful .NET Encryption Utils from: https://andrewlocatelliwoodcock.wordpress.com/2011/08/01/implementing-rsa-asymmetric-public-private-key-encryption-in-c-encrypting-under-the-public-key/
Assembly: ServiceStack.Client.dll
View Source
Declaration
public static class RsaUtils
Fields
KeyLength
View Source
Declaration
public static RsaKeyLengths KeyLength
DefaultKeyPair
View Source
Declaration
public static RsaKeyPair DefaultKeyPair
DoOAEPPadding
View Source
Declaration
public static bool DoOAEPPadding
Methods
CreatePublicAndPrivateKeyPair(RsaKeyLengths)
View Source
Declaration
public static RsaKeyPair CreatePublicAndPrivateKeyPair(RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns
Parameters
Type | Name |
---|---|
ServiceStack.RsaKeyLengths | rsaKeyLength |
CreatePrivateKeyParams(RsaKeyLengths)
View Source
Declaration
public static RSAParameters CreatePrivateKeyParams(RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns
System.Security.Cryptography.RSAParameters
Parameters
Type | Name |
---|---|
ServiceStack.RsaKeyLengths | rsaKeyLength |
FromPrivateRSAParameters(RSAParameters)
View Source
Declaration
public static string FromPrivateRSAParameters(this RSAParameters privateKey)
Returns
System.String
Parameters
Type | Name |
---|---|
System.Security.Cryptography.RSAParameters | privateKey |
FromPublicRSAParameters(RSAParameters)
View Source
Declaration
public static string FromPublicRSAParameters(this RSAParameters publicKey)
Returns
System.String
Parameters
Type | Name |
---|---|
System.Security.Cryptography.RSAParameters | publicKey |
ToPrivateRSAParameters(String)
View Source
Declaration
public static RSAParameters ToPrivateRSAParameters(this string privateKeyXml)
Returns
System.Security.Cryptography.RSAParameters
Parameters
Type | Name |
---|---|
System.String | privateKeyXml |
ToPublicRSAParameters(String)
View Source
Declaration
public static RSAParameters ToPublicRSAParameters(this string publicKeyXml)
Returns
System.Security.Cryptography.RSAParameters
Parameters
Type | Name |
---|---|
System.String | publicKeyXml |
ToPublicKeyXml(RSAParameters)
View Source
Declaration
public static string ToPublicKeyXml(this RSAParameters publicKey)
Returns
System.String
Parameters
Type | Name |
---|---|
System.Security.Cryptography.RSAParameters | publicKey |
ToPublicRsaParameters(RSAParameters)
View Source
Declaration
public static RSAParameters ToPublicRsaParameters(this RSAParameters privateKey)
Returns
System.Security.Cryptography.RSAParameters
Parameters
Type | Name |
---|---|
System.Security.Cryptography.RSAParameters | privateKey |
ToPrivateKeyXml(RSAParameters)
View Source
Declaration
public static string ToPrivateKeyXml(this RSAParameters privateKey)
Returns
System.String
Parameters
Type | Name |
---|---|
System.Security.Cryptography.RSAParameters | privateKey |
Encrypt(String)
View Source
Declaration
public static string Encrypt(this string text)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | text |
Decrypt(String)
View Source
Declaration
public static string Decrypt(this string text)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | text |
Encrypt(String, String, RsaKeyLengths)
View Source
Declaration
public static string Encrypt(string text, string publicKeyXml, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | text |
System.String | publicKeyXml |
ServiceStack.RsaKeyLengths | rsaKeyLength |
Encrypt(String, RSAParameters, RsaKeyLengths)
View Source
Declaration
public static string Encrypt(string text, RSAParameters publicKey, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | text |
System.Security.Cryptography.RSAParameters | publicKey |
ServiceStack.RsaKeyLengths | rsaKeyLength |
Encrypt(Byte[], String, RsaKeyLengths)
View Source
Declaration
public static byte[] Encrypt(byte[] bytes, string publicKeyXml, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns
System.Byte[]
Parameters
Type | Name |
---|---|
System.Byte[] | bytes |
System.String | publicKeyXml |
ServiceStack.RsaKeyLengths | rsaKeyLength |
Encrypt(Byte[], RSAParameters, RsaKeyLengths)
View Source
Declaration
public static byte[] Encrypt(byte[] bytes, RSAParameters publicKey, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns
System.Byte[]
Parameters
Type | Name |
---|---|
System.Byte[] | bytes |
System.Security.Cryptography.RSAParameters | publicKey |
ServiceStack.RsaKeyLengths | rsaKeyLength |
Decrypt(String, String, RsaKeyLengths)
View Source
Declaration
public static string Decrypt(string encryptedText, string privateKeyXml, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | encryptedText |
System.String | privateKeyXml |
ServiceStack.RsaKeyLengths | rsaKeyLength |
Decrypt(String, RSAParameters, RsaKeyLengths)
View Source
Declaration
public static string Decrypt(string encryptedText, RSAParameters privateKey, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | encryptedText |
System.Security.Cryptography.RSAParameters | privateKey |
ServiceStack.RsaKeyLengths | rsaKeyLength |
Decrypt(Byte[], String, RsaKeyLengths)
View Source
Declaration
public static byte[] Decrypt(byte[] encryptedBytes, string privateKeyXml, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns
System.Byte[]
Parameters
Type | Name |
---|---|
System.Byte[] | encryptedBytes |
System.String | privateKeyXml |
ServiceStack.RsaKeyLengths | rsaKeyLength |
Decrypt(Byte[], RSAParameters, RsaKeyLengths)
View Source
Declaration
public static byte[] Decrypt(byte[] encryptedBytes, RSAParameters privateKey, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns
System.Byte[]
Parameters
Type | Name |
---|---|
System.Byte[] | encryptedBytes |
System.Security.Cryptography.RSAParameters | privateKey |
ServiceStack.RsaKeyLengths | rsaKeyLength |
Authenticate(Byte[], RSAParameters, String, RsaKeyLengths)
View Source
Declaration
public static byte[] Authenticate(byte[] dataToSign, RSAParameters privateKey, string hashAlgorithm = "SHA512", RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns
System.Byte[]
Parameters
Type | Name |
---|---|
System.Byte[] | dataToSign |
System.Security.Cryptography.RSAParameters | privateKey |
System.String | hashAlgorithm |
ServiceStack.RsaKeyLengths | rsaKeyLength |
Verify(Byte[], Byte[], RSAParameters, String, RsaKeyLengths)
View Source
Declaration
public static bool Verify(byte[] dataToVerify, byte[] signature, RSAParameters publicKey, string hashAlgorithm = "SHA512", RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns
System.Boolean
Parameters
Type | Name |
---|---|
System.Byte[] | dataToVerify |
System.Byte[] | signature |
System.Security.Cryptography.RSAParameters | publicKey |
System.String | hashAlgorithm |
ServiceStack.RsaKeyLengths | rsaKeyLength |