/// <summary> /// Computes the signature for the specified hash value by encrypting it with the private key. /// </summary> /// <param name="rgbHash">The hash value of the data to be signed.</param> /// <param name="str">The name of the hash algorithm used to create the hash value of the data.</param> /// <returns>The DSA signature for the specified hash value.</returns> public byte[] SignHash(byte[] rgbHash, string str) { if (rgbHash == null) { throw new ArgumentNullException(nameof(rgbHash)); } if (PublicOnly) { throw new CryptographicException(SR.Cryptography_CSP_NoPrivateKey); } int calgHash = CapiHelper.NameOrOidToHashAlgId(str, OidGroup.HashAlgorithm); if (rgbHash.Length != _sha1.HashSize / 8) { throw new CryptographicException(string.Format(SR.Cryptography_InvalidHashSize, "SHA1", _sha1.HashSize / 8)); } return(CapiHelper.SignValue( SafeProvHandle, SafeKeyHandle, _parameters.KeyNumber, CapiHelper.CALG_DSS_SIGN, calgHash, rgbHash)); }
public override byte[] SignHash(byte[] rgbHash) { if (rgbHash == null) { throw new ArgumentNullException(nameof(rgbHash)); } if (PublicOnly) { throw new CryptographicException(SR.Cryptography_CSP_NoPrivateKey); } if (rgbHash.Length != (GostConstants.GOST3411_2012_256_SIZE / 8)) { throw new CryptographicException( string.Format( SR.Cryptography_InvalidHashSize, "GOST3411_2012_256", GostConstants.GOST3411_2012_256_SIZE / 8)); } GetKeyPair(); return(CapiHelper.SignValue( SafeProvHandle, SafeKeyHandle, _keySpec, //2 CapiHelper.CALG_RSA_SIGN, //переворачиваем подпись, раньше (Sharpei) переворачивали только в форматтерах GostConstants.CALG_GR3411_2012_256, rgbHash)); }
/// <summary> /// Computes the hash value of a subset of the specified byte array using the /// specified hash algorithm, and signs the resulting hash value. /// </summary> /// <param name="rgbHash">The input data for which to compute the hash</param> /// <param name="calgHash">The hash algorithm to use to create the hash value. </param> /// <returns>The RSA signature for the specified data.</returns> private byte[] SignHash(byte[] rgbHash, int calgHash) { Debug.Assert(rgbHash != null); return(CapiHelper.SignValue( SafeProvHandle, SafeKeyHandle, _parameters.KeyNumber, CapiHelper.CALG_RSA_SIGN, calgHash, rgbHash)); }