Class AsymmetricCryptographyRSA
IAsymmetricCryptographyRSA implementation for asymmetric RSA encryption/decryption and signing/verifying.
Implements
Inherited Members
Namespace: GlitchedPolygons.Services.Cryptography.Asymmetric
Assembly: GlitchedPolygons.Services.Cryptography.Asymmetric.dll
Syntax
public class AsymmetricCryptographyRSA : IAsymmetricCryptographyRSA
Constructors
AsymmetricCryptographyRSA(string)
Instantiates a new AsymmetricCryptographyRSA instance to use for encrypting/decrypting, signing and verifying data strings and bytes.
Declaration
public AsymmetricCryptographyRSA(string signatureAlgo = "SHA256withRSA")
Parameters
Type | Name | Description |
---|---|---|
string | signatureAlgo | The signature algorithm to use in the signing and verifying methods. Check out Org.BouncyCastle.Security.SignerUtilities for more information about what |
See Also
Methods
Decrypt(byte[], string)
Decrypts the specified bytes using the provided private RSA key
(the key needs to be a PEM-formatted string
).
Declaration
public byte[] Decrypt(byte[] encryptedData, string privateKeyPem)
Parameters
Type | Name | Description |
---|---|---|
byte[] | encryptedData | The encrypted data bytes ( |
string | privateKeyPem | The private RSA key to use for decryption (PEM-formatted |
Returns
Type | Description |
---|---|
byte[] | Decrypted bytes (System.Byte[]) if successful; an empty |
See Also
Decrypt(string, string)
Decrypts the specified text using the provided RSA private key.
Declaration
public string Decrypt(string encryptedText, string privateKeyPem)
Parameters
Type | Name | Description |
---|---|---|
string | encryptedText | The encrypted text to decrypt. |
string | privateKeyPem | The private RSA key needed for decryption (PEM-formatted |
Returns
Type | Description |
---|---|
string | Decrypted |
See Also
Encrypt(byte[], string)
Encrypts the specified bytes using the provided RSA public key,
which needs to be a PEM-formatted string
.
Declaration
public byte[] Encrypt(byte[] data, string publicKeyPem)
Parameters
Type | Name | Description |
---|---|---|
byte[] | data | The data ( |
string | publicKeyPem | The public key (PEM-formatted |
Returns
Type | Description |
---|---|
byte[] | The encrypted bytes ( |
See Also
Encrypt(string, string)
Encrypts the specified text using the provided RSA public key.
Declaration
public string Encrypt(string text, string publicKeyPem)
Parameters
Type | Name | Description |
---|---|---|
string | text | The plain text to encrypt. |
string | publicKeyPem | The public RSA key for encryption. Needs to be a PEM-formatted |
Returns
Type | Description |
---|---|
string | The encrypted |
See Also
Sign(byte[], string)
Signs the specified data byte[]
array using the provided private RSA key (which needs to be a PEM-formatted string
).
If the procedure succeeds, the calculated signature
byte[]
array is returned. Otherwise,
an empty byte[]
array is returned if the provided data
and/or privateKeyPem
parameters
were null
or empty. If the procedure fails entirely, null
is returned.
Declaration
public byte[] Sign(byte[] data, string privateKeyPem)
Parameters
Type | Name | Description |
---|---|---|
byte[] | data | The data to sign. |
string | privateKeyPem | The private RSA key to use for generating the signature (PEM-formatted |
Returns
Type | Description |
---|---|
byte[] | The signature ( |
See Also
Sign(string, string)
Signs the specified string
using the provided private RSA key (which needs to be a PEM-formatted string
).
Signature algo is the value of GlitchedPolygons.Services.Cryptography.Asymmetric.AsymmetricCryptographyRSA.signatureAlgo; see Org.BouncyCastle.Security.SignerUtilities for more information about what algorithms are supported and what
string
s to use here.If the procedure succeeds, the calculated signature
string
is returned (which is base-64 encoded).Otherwise, an empty
string
is returned if the provided data
and/or privateKeyPem
parameters
were null
or empty. If the procedure fails entirely, null
is returned.
Declaration
public string Sign(string data, string privateKeyPem)
Parameters
Type | Name | Description |
---|---|---|
string | data | The data to sign. |
string | privateKeyPem | The private RSA key to use for generating the signature (PEM-formatted |
Returns
Type | Description |
---|---|
string | The signature (base-64 encoded |
See Also
Verify(byte[], byte[], string)
Verifies a signature that was obtained using Sign(byte[], string) with a public RSA key (which needs to be a PEM-formatted string
).
Declaration
public bool Verify(byte[] data, byte[] signature, string publicKeyPem)
Parameters
Type | Name | Description |
---|---|---|
byte[] | data | The data whose signature you want to verify. |
byte[] | signature | The passed |
string | publicKeyPem | The public RSA key (PEM-formatted |
Returns
Type | Description |
---|---|
bool | Whether the data's signature verification succeeded or not. |
See Also
Verify(string, string, string)
Verifies a signature that was obtained using Sign(string, string) with a public RSA key (which needs to be a PEM-formatted string
).
Declaration
public bool Verify(string data, string signature, string publicKeyPem)
Parameters
Type | Name | Description |
---|---|---|
string | data | The data whose signature you want to verify. |
string | signature | The passed |
string | publicKeyPem | The public RSA key (PEM-formatted |
Returns
Type | Description |
---|---|
bool | Whether the data's signature verification succeeded or not. |