System.Security.Cryptography.RSACryptoServiceProvider.SignHash C# (CSharp) Метод

SignHash() публичный Метод

Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
public SignHash ( byte rgbHash, string str ) : byte[]
rgbHash byte The input data for which to compute the hash
str string The hash algorithm to use to create the hash value.
Результат byte[]
        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);

            return SignHash(rgbHash, calgHash);
        }

Same methods

RSACryptoServiceProvider::SignHash ( byte hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding ) : byte[]
RSACryptoServiceProvider::SignHash ( byte rgbHash, int calgHash ) : byte[]

Usage Example

        /// <summary>
        /// Creates a base64 encoded signature for the SHA-256 hash of the specified data.
        /// </summary>
        /// <param name="data">The data to hash and sign. Must not be null.</param>
        /// <returns>The base-64 encoded signature.</returns>
        public string CreateSignature(byte[] data)
        {
            data.ThrowIfNull(nameof(data));

            using (var hashAlg = SHA256.Create())
            {
                byte[] assertionHash = hashAlg.ComputeHash(data);
#if NETSTANDARD
                var sigBytes = key.SignHash(assertionHash, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
#else
                var sigBytes = key.SignHash(assertionHash, Sha256Oid);
#endif
                return(Convert.ToBase64String(sigBytes));
            }
        }
All Usage Examples Of System.Security.Cryptography.RSACryptoServiceProvider::SignHash