/// <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 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 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> /// <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))); }