/// <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="inputStream">The input data for which to compute the hash</param> /// <param name="halg">The hash algorithm to use to create the hash value. </param> /// <returns>The RSA signature for the specified data.</returns> public byte[] SignData(Stream inputStream, object halg) { int calgHash = CapiHelper.ObjToHashAlgId(halg); HashAlgorithmName hashAlgorithmName = CapiHelper.AlgIdToHashAlgorithmName(calgHash); byte[] hashVal = HashOneShotHelpers.HashData(hashAlgorithmName, inputStream); return(SignHash(hashVal, calgHash)); }
/// <summary> /// Verifies the signature of a hash value. /// </summary> public bool VerifyData(byte[] buffer, object halg, byte[] signature) { int calgHash = CapiHelper.ObjToHashAlgId(halg); HashAlgorithmName hashAlgorithmName = CapiHelper.AlgIdToHashAlgorithmName(calgHash); byte[] hashVal = HashOneShotHelpers.HashData(hashAlgorithmName, buffer); return(VerifyHash(hashVal, calgHash, signature)); }
/// <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="buffer">The input data for which to compute the hash</param> /// <param name="offset">The offset into the array from which to begin using data</param> /// <param name="count">The number of bytes in the array to use as data. </param> /// <param name="halg">The hash algorithm to use to create the hash value. </param> /// <returns>The RSA signature for the specified data.</returns> public byte[] SignData(byte[] buffer, int offset, int count, object halg) { int calgHash = CapiHelper.ObjToHashAlgId(halg); HashAlgorithmName hashAlgorithmName = CapiHelper.AlgIdToHashAlgorithmName(calgHash); byte[] hashVal = HashOneShotHelpers.HashData(hashAlgorithmName, new ReadOnlySpan <byte>(buffer, offset, count)); return(SignHash(hashVal, calgHash)); }
protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm) { if (hashAlgorithm != HashAlgorithmName.SHA1) { throw new CryptographicException(SR.Cryptography_UnknownHashAlgorithm, hashAlgorithm.Name); } return(HashOneShotHelpers.HashData(hashAlgorithm, data)); }
protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm) { if (hashAlgorithm != HashAlgorithmName.SHA1) { throw new CryptographicException(SR.Cryptography_UnknownHashAlgorithm, hashAlgorithm.Name); } return(HashOneShotHelpers.HashData(hashAlgorithm, new ReadOnlySpan <byte>(data, offset, count))); }
protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm) { // we're sealed and the base should have checked this already Debug.Assert(data != null); Debug.Assert(offset >= 0 && offset <= data.Length); Debug.Assert(count >= 0 && count <= data.Length); Debug.Assert(!string.IsNullOrEmpty(hashAlgorithm.Name)); return(HashOneShotHelpers.HashData(hashAlgorithm, new ReadOnlySpan <byte>(data, offset, count))); }
protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm) { if (hashAlgorithm != HashAlgorithmName.SHA1) { // Matching DSACryptoServiceProvider's "I only understand SHA-1/FIPS 186-2" exception throw new CryptographicException(SR.Cryptography_UnknownHashAlgorithm, hashAlgorithm.Name); } return(HashOneShotHelpers.HashData(hashAlgorithm, new ReadOnlySpan <byte>(data, offset, count))); }
protected virtual byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm) => HashOneShotHelpers.HashData(hashAlgorithm, data);
protected virtual byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm) => HashOneShotHelpers.HashData(hashAlgorithm, new ReadOnlySpan <byte>(data, offset, count));