/// <summary> /// Computes the signature for the specified hash value by encrypting it with the private key that has a pin. /// </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> /// <param name="pin">The private key pin</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. -or- wrong pin has been inputed.</exception> public static byte[] SignHashByteArray(byte[] hash, X509Certificate2 privateKey, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, string pin) { return(CertificateCrypto.SignHash(hash, privateKey, hashAlgorithm, padding, pin)); }
/// <summary> /// Computes the signature for the specified hash value by encrypting it with the private key that has a pin. /// </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> /// <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 SignHash(byte[] hash, X509Certificate2 privateKey, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, string pin) { return(Convert.ToBase64String(CertificateCrypto.SignHash(hash, privateKey, hashAlgorithm, padding, pin))); }