BogaNet 1.4.0
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
BogaNet.Helper.RSAHelper Class Referenceabstract

Helper for RSA cryptography and X509 certificates. More...

Static Public Member Functions

static X509Certificate2 GenerateSelfSignedCertificate (string certName, RSAKeyLength keyLength=RSAKeyLength._2048, string oid="1.2.840.10045.3.1.7")
 Generates a self-signed X509-certificate.
 
static X509Certificate2 GetCertificateFromStore (string certName, StoreLocation storeLocation=StoreLocation.LocalMachine)
 Gets a X509-certificate from the key store.
 
static void AddCertificateToStore (X509Certificate2 cert, StoreName storeName=StoreName.TrustedPublisher, StoreLocation storeLocation=StoreLocation.LocalMachine)
 Adds a X509-certificate to the key store.
 
static X509Certificate2 GetPublicCertificate (X509Certificate2 cert, string? password=null)
 Gets the public key from a X509-certificate.
 
static X509Certificate2 GetPrivateCertificate (X509Certificate2 cert, string? password=null)
 Gets the private and public key from a X509-certificate. NOTE: never share this data with people outside of your organisation!
 
static X509Certificate2 GetCertificate (byte[] data, string? password=null)
 Gets a X509-certificate from a byte-array.
 
static bool WritePublicCertificateToFile (string filename, X509Certificate2 cert, string? password=null)
 Writes the public key as X509-certificate to a file.
 
static async Task< bool > WritePublicCertificateToFileAsync (string filename, X509Certificate2 cert, string? password=null)
 Writes the public key as X509-certificate to a file asynchronously.
 
static bool WritePrivateCertificateToFile (string filename, X509Certificate2 cert, string password)
 Writes the private and public key as X509-certificate to a file. NOTE: never share this file with people outside of your organisation!
 
static async Task< bool > WritePrivateCertificateToFileAsync (string filename, X509Certificate2 cert, string password)
 Writes the private and public key as X509-certificate to a file asynchronously. NOTE: never share this file with people outside of your organisation!
 
static X509Certificate2 ReadCertificateFromFile (string filename, string? password=null)
 Reads a X509-certificate from a file.
 
static async Task< X509Certificate2 > ReadCertificateFromFileAsync (string filename, string? password=null)
 Reads a X509-certificate from a file asynchronously.
 
static byte[] Encrypt (byte[] dataToEncrypt, X509Certificate2 cert, RSAEncryptionPadding? padding=null)
 Encrypts a byte-array with a X509-certificate.
 
static byte[] Encrypt (string? textToEncrypt, X509Certificate2 cert, RSAEncryptionPadding? padding=null, Encoding? encoding=null)
 Encrypts a string with a X509-certificate.
 
static byte[] Decrypt (byte[] dataToDecrypt, X509Certificate2 cert, RSAEncryptionPadding? padding=null)
 Decrypts a byte-array with a X509-certificate.
 

Detailed Description

Helper for RSA cryptography and X509 certificates.

Member Function Documentation

◆ AddCertificateToStore()

static void BogaNet.Helper.RSAHelper.AddCertificateToStore ( X509Certificate2 cert,
StoreName storeName = StoreName::TrustedPublisher,
StoreLocation storeLocation = StoreLocation::LocalMachine )
static

Adds a X509-certificate to the key store.

Parameters
certX509-certificate
storeNameName of the key store (optional, default: TrustedPublisher)
storeLocationLocation in the key store (optional, default: LocalMachine)

◆ Decrypt()

static byte[] BogaNet.Helper.RSAHelper.Decrypt ( byte[] dataToDecrypt,
X509Certificate2 cert,
RSAEncryptionPadding? padding = null )
static

Decrypts a byte-array with a X509-certificate.

Parameters
dataToDecryptbyte-array to decrypt
certX509-certificate
paddingPadding for the asymmetric encryption (optional, default: OaepSHA256)
Returns
Decrypted byte-array
Exceptions
ArgumentNullException

◆ Encrypt() [1/2]

static byte[] BogaNet.Helper.RSAHelper.Encrypt ( byte[] dataToEncrypt,
X509Certificate2 cert,
RSAEncryptionPadding? padding = null )
static

Encrypts a byte-array with a X509-certificate.

Parameters
dataToEncryptbyte-array to encrypt
certX509-certificate
paddingPadding for the asymmetric encryption (optional, default: OaepSHA256)
Returns
Encrypted data as byte-array
Exceptions
ArgumentNullException

◆ Encrypt() [2/2]

static byte[] BogaNet.Helper.RSAHelper.Encrypt ( string? textToEncrypt,
X509Certificate2 cert,
RSAEncryptionPadding? padding = null,
Encoding? encoding = null )
static

Encrypts a string with a X509-certificate.

Parameters
textToEncryptstring to encrypt
certX509-certificate
paddingPadding for the asymmetric encryption (optional, default: OaepSHA256)
encodingEncoding of the string (optional, default: UTF8)
Returns
Encrypted string as byte-array
Exceptions
ArgumentNullException

◆ GenerateSelfSignedCertificate()

static X509Certificate2 BogaNet.Helper.RSAHelper.GenerateSelfSignedCertificate ( string certName,
RSAKeyLength keyLength = RSAKeyLength::_2048,
string oid = "1.2.840.10045.3.1.7" )
static

Generates a self-signed X509-certificate.

Parameters
certNameName of the certificate
keyLengthKey length of the certificate (optional, default: 2048)
oidOID for the certificate (optional, default: "1.2.840.10045.3.1.7"
Returns
X509-certificate

◆ GetCertificate()

static X509Certificate2 BogaNet.Helper.RSAHelper.GetCertificate ( byte[] data,
string? password = null )
static

Gets a X509-certificate from a byte-array.

Parameters
dataX509-certificate as byte-array
passwordPassword for the certificate
Returns
X509-certificate
Exceptions
ArgumentNullException

◆ GetCertificateFromStore()

static X509Certificate2 BogaNet.Helper.RSAHelper.GetCertificateFromStore ( string certName,
StoreLocation storeLocation = StoreLocation::LocalMachine )
static

Gets a X509-certificate from the key store.

Parameters
certNameName of the certificate
storeLocationLocation in the key store (optional, default: LocalMachine)
Returns
X509-certificate

◆ GetPrivateCertificate()

static X509Certificate2 BogaNet.Helper.RSAHelper.GetPrivateCertificate ( X509Certificate2 cert,
string? password = null )
static

Gets the private and public key from a X509-certificate. NOTE: never share this data with people outside of your organisation!

Parameters
certX509-certificate
passwordPassword for the file (optional, default: none)
Returns
X509-certificate

◆ GetPublicCertificate()

static X509Certificate2 BogaNet.Helper.RSAHelper.GetPublicCertificate ( X509Certificate2 cert,
string? password = null )
static

Gets the public key from a X509-certificate.

Parameters
certX509-certificate
passwordPassword for the file (optional, default: none)
Returns
X509-certificate as byte-array

◆ ReadCertificateFromFile()

static X509Certificate2 BogaNet.Helper.RSAHelper.ReadCertificateFromFile ( string filename,
string? password = null )
static

Reads a X509-certificate from a file.

Parameters
filenameName of the file with the certificate
passwordPassword for the file
Returns
X509-certificate
Exceptions
Exception

◆ ReadCertificateFromFileAsync()

static async Task< X509Certificate2 > BogaNet.Helper.RSAHelper.ReadCertificateFromFileAsync ( string filename,
string? password = null )
static

Reads a X509-certificate from a file asynchronously.

Parameters
filenameName of the file with the certificate
passwordPassword for the file
Returns
X509-certificate
Exceptions
Exception

◆ WritePrivateCertificateToFile()

static bool BogaNet.Helper.RSAHelper.WritePrivateCertificateToFile ( string filename,
X509Certificate2 cert,
string password )
static

Writes the private and public key as X509-certificate to a file. NOTE: never share this file with people outside of your organisation!

Parameters
filenameName of the file for the certificate
certX509-certificate
passwordPassword for the file
Returns
True if the operation was successful
Exceptions
Exception

◆ WritePrivateCertificateToFileAsync()

static async Task< bool > BogaNet.Helper.RSAHelper.WritePrivateCertificateToFileAsync ( string filename,
X509Certificate2 cert,
string password )
static

Writes the private and public key as X509-certificate to a file asynchronously. NOTE: never share this file with people outside of your organisation!

Parameters
filenameName of the file for the certificate
certX509-certificate
passwordPassword for the file
Returns
True if the operation was successful
Exceptions
Exception

◆ WritePublicCertificateToFile()

static bool BogaNet.Helper.RSAHelper.WritePublicCertificateToFile ( string filename,
X509Certificate2 cert,
string? password = null )
static

Writes the public key as X509-certificate to a file.

Parameters
filenameName of the file
certX509-certificate
passwordPassword for the file (optional, default: none)
Returns
True if the operation was successful
Exceptions
Exception

◆ WritePublicCertificateToFileAsync()

static async Task< bool > BogaNet.Helper.RSAHelper.WritePublicCertificateToFileAsync ( string filename,
X509Certificate2 cert,
string? password = null )
static

Writes the public key as X509-certificate to a file asynchronously.

Parameters
filenameName of the file
certX509-certificate
passwordPassword for the file (optional, default: none)
Returns
True if the operation was successful
Exceptions
Exception

The documentation for this class was generated from the following file: