Show / Hide Table of Contents

Interface IAsymmetricCryptographyRSA

Service interface for encrypting and decrypting strings and byte[] arrays.

Make sure that everything you encrypt with these methods will also be decrypted again using the same code.

DO NOT MIX crypto libraries under any circumstances! IAsymmetricKeygenRSA

Namespace: GlitchedPolygons.Services.Cryptography.Asymmetric
Assembly: GlitchedPolygons.Services.Cryptography.Asymmetric.dll
Syntax
public interface IAsymmetricCryptographyRSA

Methods

| Improve this Doc View Source

Decrypt(Byte[], String)

Decrypts the specified bytes using the provided private RSA key (the key needs to be a PEM-formatted string).

Declaration
byte[] Decrypt(byte[] encryptedData, string privateKeyPem)
Parameters
Type Name Description
System.Byte[] encryptedData

The encrypted data bytes (byte[]).

System.String privateKeyPem

The private RSA key to use for decryption (PEM-formatted string).

Returns
Type Description
System.Byte[]

Decrypted bytes (System.Byte[]) if successful; an empty byte[] array if the passed data or key argument was null or empty; null if decryption failed.

| Improve this Doc View Source

Decrypt(String, String)

Decrypts the specified text using the provided RSA private key.

Declaration
string Decrypt(string encryptedText, string privateKeyPem)
Parameters
Type Name Description
System.String encryptedText

The encrypted text to decrypt.

System.String privateKeyPem

The private RSA key needed for decryption (PEM-formatted string).

Returns
Type Description
System.String

Decrypted string; null if the passed key or encrypted text argument was null or empty; null if decryption failed.

| Improve this Doc View Source

Encrypt(Byte[], String)

Encrypts the specified bytes using the provided RSA public key, which needs to be a PEM-formatted string.

Declaration
byte[] Encrypt(byte[] data, string publicKeyPem)
Parameters
Type Name Description
System.Byte[] data

The data (byte[] array) to encrypt.

System.String publicKeyPem

The public key (PEM-formatted string) to use for encryption.

Returns
Type Description
System.Byte[]

The encrypted bytes (System.Byte[]) if successful; Array.Empty<byte>() if the passed data or key argument was null or empty; null if encryption failed.

| Improve this Doc View Source

Encrypt(String, String)

Encrypts the specified text using the provided RSA public key.

Declaration
string Encrypt(string text, string publicKeyPem)
Parameters
Type Name Description
System.String text

The plain text to encrypt.

System.String publicKeyPem

The public RSA key for encryption. Needs to be a PEM-formatted string.

Returns
Type Description
System.String

The encrypted string; string.Empty if the passed key or plain text argument was null or empty; null if encryption failed.

| Improve this Doc View Source

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
byte[] Sign(byte[] data, string privateKeyPem)
Parameters
Type Name Description
System.Byte[] data

The data to sign.

System.String privateKeyPem

The private RSA key to use for generating the signature (PEM-formatted string)

Returns
Type Description
System.Byte[]

The signature (byte[]), string.Empty if the provided data and/or privateKeyPem parameters were null or empty. Returns null if signing failed entirely.

See Also
Org.BouncyCastle.Security.SignerUtilities
| Improve this Doc View Source

Sign(String, String)

Signs the specified string using the provided private RSA key.

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
string Sign(string data, string privateKeyPem)
Parameters
Type Name Description
System.String data

The data to sign.

System.String privateKeyPem

The private RSA key to use for generating the signature (PEM-formatted string)

Returns
Type Description
System.String

The signature (base-64 encoded string) if successful. string.Empty is returned if the provided data and/or privateKeyPem parameters were null or empty. Returns null if signing failed entirely.

| Improve this Doc View Source

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
bool Verify(byte[] data, byte[] signature, string publicKeyPem)
Parameters
Type Name Description
System.Byte[] data

The data whose signature you want to verify.

System.Byte[] signature

The passed data's signature (return value of Sign(Byte[], String)).

System.String publicKeyPem

The public RSA key (PEM-formatted) to use for signature verification.

Returns
Type Description
System.Boolean

Whether the data's signature verification succeeded or not.

| Improve this Doc View Source

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
bool Verify(string data, string signature, string publicKeyPem)
Parameters
Type Name Description
System.String data

The data whose signature you want to verify.

System.String signature

The passed data's signature (return value of Sign(String, String)).

System.String publicKeyPem

The public RSA key (PEM-formatted string) to use for signature verification.

Returns
Type Description
System.Boolean

Whether the data's signature verification succeeded or not.

  • Improve this Doc
  • View Source
Back to top Generated by DocFX