public static bool VerifyData(
            this ECDsaCng ecdsaCng,
            byte[] data,
            int offset,
            int count,
            byte[] signature)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (offset < 0 || offset > data.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (count < 0 || count > data.Length - offset)
            {
                throw new ArgumentOutOfRangeException("count");
            }
            if (signature == null)
            {
                throw new ArgumentNullException("signature");
            }

            using (BCryptHashAlgorithm hashAlgorithm = new BCryptHashAlgorithm(CngAlgorithm.Sha256, BCryptNative.ProviderName.MicrosoftPrimitiveProvider))
            {
                hashAlgorithm.HashCore(data, offset, count);
                byte[] hashValue = hashAlgorithm.HashFinal();

                return(ecdsaCng.VerifyHash(hashValue, signature));
            }
        }
        public static byte[] SignData(
            this ECDsaCng ecdsaCng,
            byte[] data,
            int offset,
            int count)
        {
            Contract.Ensures(Contract.Result <byte[]>() != null);

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (offset < 0 || offset > data.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (count < 0 || count > data.Length - offset)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            using (var hashAlgorithm = new BCryptHashAlgorithm(CngAlgorithm.Sha256, BCryptNative.ProviderName.MicrosoftPrimitiveProvider))
            {
                hashAlgorithm.HashCore(data, offset, count);
                byte[] hashValue = hashAlgorithm.HashFinal();
                return(ecdsaCng.SignHash(hashValue));
            }
        }