Encryption
The Encryption class provides mechanisms for RSA encryption/decryption, along with the generation of self-signed certificates.
Properties
PublicKey: Retrieves the public key for the current RSA provider instance.
Methods
Encrypt
- Purpose: Encrypts a string using the specified public RSA key.
- Parameters:
string publicKey: The RSA public key in XML format.string data: The plaintext string to be encrypted.
- Returns:
string: The encrypted data in base64 format. - Usage Example:
var encryptedData = Encryption.Encrypt(publicKey, "Hello World");Decrypt
- Purpose: Decrypts a base64-encoded string using the private RSA key.
- Parameters:
string data: The base64-encoded encrypted data.
- Returns:
string: The decrypted plaintext. - Usage Example:
var decryptedData = Encryption.Decrypt(encryptedData);GenerateSelfSignedCertificate
- Purpose: Generates a self-signed X509 certificate with RSA encryption.
- Parameters:
string subjectName: The subject name for the certificate (common name).
- Returns:
(X509Certificate2 certificate, string password): A tuple containing the generated certificate and its password. - Usage Example:
var (certificate, password) = Encryption.GenerateSelfSignedCertificate("CN=example.com");