/// <summary>
 /// Verifies that the base64 encoded signature is valid by hashing the data and then comparing it by decrypting the signature.
 /// </summary>
 /// <param name="data">Data (not hash) to be verified</param>
 /// <param name="encodedsiged">The encoded hashed and signed data</param>
 /// <param name="publicKey">Public key that is the RSA pair of the private key that signed the message</param>
 /// <param name="hashAlgorithm">The algorithm used for signing</param>
 /// <returns>Return true if data is Verified</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields.</exception>
 public static bool VerifyData(byte[] data, string encodedSigned, X509Certificate2 publicKey, HashAlgorithmName hashAlgorithm)
 {
     byte[] signedData = Convert.FromBase64String(encodedSigned);
     return(CertificateCrypto.VerifyData(data, signedData, publicKey, hashAlgorithm));
 }
 /// <summary>
 /// Verifies that the base64 encoded signature is valid by hashing the data and then comparing it by decrypting the signature.
 /// </summary>
 /// <param name="data">Data (not hash) to be verified</param>
 /// <param name="signedData">The signed data as byte array</param>
 /// <param name="publicKey">Public key that is the RSA pair of the private key that signed the message</param>
 /// <param name="hashAlgorithm">The algorithm used for signing</param>
 /// <returns>Return true if data is Verified</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields.</exception>
 public static bool VerifyData(byte[] data, byte[] signedData, X509Certificate2 publicKey, HashAlgorithmName hashAlgorithm)
 {
     return(CertificateCrypto.VerifyData(data, signedData, publicKey, hashAlgorithm));
 }
 /// <summary>
 /// Verifies that the base64 encoded signature is valid by comparing the hashed data with the decrypted signature.
 /// </summary>
 /// <param name="hashedData">Hashed data to be verified</param>
 /// <param name="encodedsiged">The encoded hashed and signed data</param>
 /// <param name="publicKey">Public key that is the RSA pair of the private key that signed the message</param>
 /// <param name="hashAlgorithm">The algorithm used for signing</param>
 /// <param name="padding">The padding that was used in the signature</param>
 /// <returns>Return true if data is Verified</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields.</exception>
 public static bool VerifyHash(byte[] data, string encodedSigned, X509Certificate2 publicKey, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
 {
     byte[] signedHash = Convert.FromBase64String(encodedSigned);
     return(CertificateCrypto.VerifyHash(data, signedHash, publicKey, hashAlgorithm, padding));
 }
 /// <summary>
 /// Verifies that the base64 encoded signature is valid by comparing the hashed data with the decrypted signature.
 /// </summary>
 /// <param name="hashedData">Hashed data to be verified</param>
 /// <param name="signedHash">Signed hash as byte array</param>
 /// <param name="publicKey">Public key that is the RSA pair of the private key that signed the message</param>
 /// <param name="hashAlgorithm">The algorithm used for signing</param>
 /// <param name="padding">The padding that was used in the signature</param>
 /// <returns>Return true if data is Verified</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields.</exception>
 public static bool VerifyHash(byte[] data, byte[] signedHash, X509Certificate2 publicKey, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
 {
     return(CertificateCrypto.VerifyHash(data, signedHash, publicKey, hashAlgorithm, padding));
 }
 /// <summary>
 /// Computes the hash value of the specified byte array using the specified hash algorithm,
 /// and signs the resulting hash value.
 /// </summary>
 /// <param name="data">Data (not hash) to be signed</param>
 /// <param name="privateKey">The private key used for signing</param>
 /// <param name="hashAlgorithm">The hash algorithm used in hashing the data before signing</param>
 /// <returns>Return signed data as byte array, or null if fails</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields. -or- The padding mode is not supported. -or- The certificate context is invalid.</exception>
 public static byte[] SignDataByteArray(byte[] data, X509Certificate2 privateKey, HashAlgorithmName hashAlgorithm)
 {
     return(CertificateCrypto.SignData(data, privateKey, hashAlgorithm));
 }
 /// <summary>
 /// Computes the hash value of the specified byte array using the specified hash algorithm,
 /// and signs the resulting hash value.
 /// </summary>
 /// <param name="data">Data (not hash) to be signed</param>
 /// <param name="privateKey">The private key used for signing</param>
 /// <param name="hashAlgorithm">The hash algorithm used in hashing the data before signing</param>
 /// <param name="padding">The padding that will be used in the signature</param>
 /// <param name="pin">The private key pin</param>
 /// <returns>Return signed data as byte array, or null if fails</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields. -or- The padding mode is not supported. -or- The certificate context is invalid. -or- wrong pin has been inputed.</exception>
 public static byte[] SignDataByteArray(byte[] data, X509Certificate2 privateKey, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, string pin)
 {
     return(CertificateCrypto.SignData(data, privateKey, hashAlgorithm, padding, pin));
 }
 /// <summary>
 /// Computes the hash value of the specified byte array using the specified hash algorithm,
 /// and signs the resulting hash value.
 /// </summary>
 /// <param name="data">Data (not hash) to be signed</param>
 /// <param name="privateKey">The private key used for signing</param>
 /// <param name="hashAlgorithm">The hash algorithm used in hashing the data before signing</param>
 /// <returns>Return Base64 encoded sign string, or null if fails</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields. -or- The padding mode is not supported. -or- The certificate context is invalid.</exception>
 public static string SignData(byte[] data, X509Certificate2 privateKey, HashAlgorithmName hashAlgorithm)
 {
     return(Convert.ToBase64String(CertificateCrypto.SignData(data, privateKey, hashAlgorithm)));
 }
 /// <summary>
 /// Computes the hash value of the specified byte array using the specified hash algorithm,
 /// and signs the resulting hash value using a private key that uses pin.
 /// </summary>
 /// <param name="data">Data (not hash) to be signed</param>
 /// <param name="privateKey">The private key used for signing</param>
 /// <param name="hashAlgorithm">The hash algorithm used in hashing the data before signing</param>
 /// <param name="padding">The padding that will be used in the signature</param>
 /// <param name="pin">The private key pin</param>
 /// <returns>Return Base64 encoded sign string, or null if fails</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields. -or- The padding mode is not supported. -or- The certificate context is invalid. -or- wrong pin has been inputed.</exception>
 public static string SignData(byte[] data, X509Certificate2 privateKey, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, string pin)
 {
     return(Convert.ToBase64String(CertificateCrypto.SignData(data, privateKey, hashAlgorithm, padding, pin)));
 }
 /// <summary>
 /// Computes the signature for the specified hash value by encrypting it with the private key.
 /// </summary>
 /// <param name="hash">Hashed data to be signed</param>
 /// <param name="privateKey">The private key used for signing</param>
 /// <param name="hashAlgorithm">The algorithm that will be used for signing</param>
 /// <param name="padding">The padding that will be used in the signature</param>
 /// <returns>Return signed hash as byte array, or null if fails</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields. -or- The padding mode is not supported. -or- The certificate context is invalid.</exception>
 public static byte[] SignHashByteArray(byte[] hash, X509Certificate2 privateKey, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
 {
     return(CertificateCrypto.SignHash(hash, privateKey, hashAlgorithm, padding));
 }
 /// <summary>
 /// Computes the signature for the specified hash value by encrypting it with the private key.
 /// </summary>
 /// <param name="hash">Hashed data to be signed</param>
 /// <param name="privateKey">The private key used for signing</param>
 /// <param name="hashAlgorithm">The algorithm that will be used for signing</param>
 /// <param name="padding">The padding that will be used in the signature</param>
 /// <returns>Return Base64 encoded sign string, or null if fails</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields. -or- The padding mode is not supported. -or- The certificate context is invalid.</exception>
 public static string SignHash(byte[] hash, X509Certificate2 privateKey, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
 {
     return(Convert.ToBase64String(CertificateCrypto.SignHash(hash, privateKey, hashAlgorithm, padding)));
 }
 /// <summary>
 /// Decrypts the message using an exchange private key that has a pin.
 /// </summary>
 /// <param name="encryptedMessage">Encrypted message as byte array</param>
 /// <param name="privateKey">Private exchange key to decrypt the message</param>
 /// <param name="padding">Padding mode to be used with the decryption</param>
 /// <param name="pin">The private key pin</param>
 /// <returns>Decrypted message as byte array</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields. -or- The padding mode is not supported. -or- The certificate context is invalid. -or- wrong pin has been inputed.</exception>
 public static byte[] Decrypt(byte[] encryptedMessage, X509Certificate2 privateKey, RSAEncryptionPadding padding, string pin)
 {
     return(CertificateCrypto.Decrypt(encryptedMessage, privateKey, padding, pin));
 }
 /// <summary>
 /// Encrypts the message using an exchange public key
 /// </summary>
 /// <param name="message">Message to be encrypted</param>
 /// <param name="publicKey">Public exchange key to encrypt the message</param>
 /// <param name="padding">Padding mode to be used with the encryption</param>
 /// <returns>Encrypted message as byte array</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields. -or- The padding mode is not supported. -or- The certificate context is invalid.</exception>
 public static byte[] EncryptToByteArray(byte[] message, X509Certificate2 publicKey, RSAEncryptionPadding padding)
 {
     return(CertificateCrypto.Encrypt(message, publicKey, padding));
 }
 /// <summary>
 /// Encrypts the message using an exchange public key
 /// </summary>
 /// <param name="message">Message to be encrypted</param>
 /// <param name="publicKey">Public exchange key to encrypt the message</param>
 /// <param name="padding">Padding mode to be used with the encryption</param>
 /// <returns>Encrypted message as base64 string</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields. -or- The padding mode is not supported. -or- The certificate context is invalid.</exception>
 public static string Encrypt(byte[] message, X509Certificate2 publicKey, RSAEncryptionPadding padding)
 {
     return(Convert.ToBase64String(CertificateCrypto.Encrypt(message, publicKey, padding)));
 }