Skip to main content

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

ServiceStack.RsaKeyPair

Parameters
TypeName
ServiceStack.RsaKeyLengthsrsaKeyLength

CreatePrivateKeyParams(RsaKeyLengths)

View Source
Declaration
public static RSAParameters CreatePrivateKeyParams(RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns

System.Security.Cryptography.RSAParameters

Parameters
TypeName
ServiceStack.RsaKeyLengthsrsaKeyLength

FromPrivateRSAParameters(RSAParameters)

View Source
Declaration
public static string FromPrivateRSAParameters(this RSAParameters privateKey)
Returns

System.String

Parameters
TypeName
System.Security.Cryptography.RSAParametersprivateKey

FromPublicRSAParameters(RSAParameters)

View Source
Declaration
public static string FromPublicRSAParameters(this RSAParameters publicKey)
Returns

System.String

Parameters
TypeName
System.Security.Cryptography.RSAParameterspublicKey

ToPrivateRSAParameters(String)

View Source
Declaration
public static RSAParameters ToPrivateRSAParameters(this string privateKeyXml)
Returns

System.Security.Cryptography.RSAParameters

Parameters
TypeName
System.StringprivateKeyXml

ToPublicRSAParameters(String)

View Source
Declaration
public static RSAParameters ToPublicRSAParameters(this string publicKeyXml)
Returns

System.Security.Cryptography.RSAParameters

Parameters
TypeName
System.StringpublicKeyXml

ToPublicKeyXml(RSAParameters)

View Source
Declaration
public static string ToPublicKeyXml(this RSAParameters publicKey)
Returns

System.String

Parameters
TypeName
System.Security.Cryptography.RSAParameterspublicKey

ToPublicRsaParameters(RSAParameters)

View Source
Declaration
public static RSAParameters ToPublicRsaParameters(this RSAParameters privateKey)
Returns

System.Security.Cryptography.RSAParameters

Parameters
TypeName
System.Security.Cryptography.RSAParametersprivateKey

ToPrivateKeyXml(RSAParameters)

View Source
Declaration
public static string ToPrivateKeyXml(this RSAParameters privateKey)
Returns

System.String

Parameters
TypeName
System.Security.Cryptography.RSAParametersprivateKey

Encrypt(String)

View Source
Declaration
public static string Encrypt(this string text)
Returns

System.String

Parameters
TypeName
System.Stringtext

Decrypt(String)

View Source
Declaration
public static string Decrypt(this string text)
Returns

System.String

Parameters
TypeName
System.Stringtext

Encrypt(String, String, RsaKeyLengths)

View Source
Declaration
public static string Encrypt(string text, string publicKeyXml, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns

System.String

Parameters
TypeName
System.Stringtext
System.StringpublicKeyXml
ServiceStack.RsaKeyLengthsrsaKeyLength

Encrypt(String, RSAParameters, RsaKeyLengths)

View Source
Declaration
public static string Encrypt(string text, RSAParameters publicKey, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns

System.String

Parameters
TypeName
System.Stringtext
System.Security.Cryptography.RSAParameterspublicKey
ServiceStack.RsaKeyLengthsrsaKeyLength

Encrypt(Byte[], String, RsaKeyLengths)

View Source
Declaration
public static byte[] Encrypt(byte[] bytes, string publicKeyXml, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns

System.Byte[]

Parameters
TypeName
System.Byte[]bytes
System.StringpublicKeyXml
ServiceStack.RsaKeyLengthsrsaKeyLength

Encrypt(Byte[], RSAParameters, RsaKeyLengths)

View Source
Declaration
public static byte[] Encrypt(byte[] bytes, RSAParameters publicKey, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns

System.Byte[]

Parameters
TypeName
System.Byte[]bytes
System.Security.Cryptography.RSAParameterspublicKey
ServiceStack.RsaKeyLengthsrsaKeyLength

Decrypt(String, String, RsaKeyLengths)

View Source
Declaration
public static string Decrypt(string encryptedText, string privateKeyXml, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns

System.String

Parameters
TypeName
System.StringencryptedText
System.StringprivateKeyXml
ServiceStack.RsaKeyLengthsrsaKeyLength

Decrypt(String, RSAParameters, RsaKeyLengths)

View Source
Declaration
public static string Decrypt(string encryptedText, RSAParameters privateKey, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns

System.String

Parameters
TypeName
System.StringencryptedText
System.Security.Cryptography.RSAParametersprivateKey
ServiceStack.RsaKeyLengthsrsaKeyLength

Decrypt(Byte[], String, RsaKeyLengths)

View Source
Declaration
public static byte[] Decrypt(byte[] encryptedBytes, string privateKeyXml, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns

System.Byte[]

Parameters
TypeName
System.Byte[]encryptedBytes
System.StringprivateKeyXml
ServiceStack.RsaKeyLengthsrsaKeyLength

Decrypt(Byte[], RSAParameters, RsaKeyLengths)

View Source
Declaration
public static byte[] Decrypt(byte[] encryptedBytes, RSAParameters privateKey, RsaKeyLengths rsaKeyLength = RsaKeyLengths.Bit2048)
Returns

System.Byte[]

Parameters
TypeName
System.Byte[]encryptedBytes
System.Security.Cryptography.RSAParametersprivateKey
ServiceStack.RsaKeyLengthsrsaKeyLength

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
TypeName
System.Byte[]dataToSign
System.Security.Cryptography.RSAParametersprivateKey
System.StringhashAlgorithm
ServiceStack.RsaKeyLengthsrsaKeyLength

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
TypeName
System.Byte[]dataToVerify
System.Byte[]signature
System.Security.Cryptography.RSAParameterspublicKey
System.StringhashAlgorithm
ServiceStack.RsaKeyLengthsrsaKeyLength