System.Security.Cryptography.RSACryptoServiceProvider.SignData C# (CSharp) Method

SignData() public method

Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
public SignData ( Stream inputStream, Object halg ) : byte[]
inputStream System.IO.Stream The input data for which to compute the hash
halg Object The hash algorithm to use to create the hash value.
return byte[]
        public byte[] SignData(Stream inputStream, Object halg)
        {
            int calgHash = CapiHelper.ObjToHashAlgId(halg);
            HashAlgorithm hash = CapiHelper.ObjToHashAlgorithm(halg);
            byte[] hashVal = hash.ComputeHash(inputStream);
            return SignHash(hashVal, calgHash);
        }

Same methods

RSACryptoServiceProvider::SignData ( byte buffer, Object halg ) : byte[]
RSACryptoServiceProvider::SignData ( byte buffer, int offset, int count, object halg ) : byte[]

Usage Example

Example #1
0
        public string SignAuthCookieV1(string cookie)
        {
            byte[] privateKey = this.GetPrivateKey(KeyType.AuthCookieV1);

            //// The array to store the signed message in bytes
            byte[] signedBytes;
            using (var rsa = new RSACryptoServiceProvider())
            {
                // Write the message to a byte array using UTF8 as the encoding.

                byte[] originalData = System.Text.Encoding.UTF8.GetBytes(cookie);

                try
                {
                    // Import the private key used for signing the message
                    rsa.ImportParameters(SecureSigningService.FromBinaryToRSAParameters(privateKey));

                    signedBytes = rsa.SignData(originalData, CryptoConfig.MapNameToOID("SHA512"));
                }
                catch (CryptographicException e)
                {
                    Console.WriteLine(e.Message);
                    return null;
                }
                finally
                {
                    //// Set the keycontainer to be cleared when rsa is garbage collected.
                    rsa.PersistKeyInCsp = false;
                }
            }

            // Convert the a base64 string before returning
            return Convert.ToBase64String(signedBytes);
        }
All Usage Examples Of System.Security.Cryptography.RSACryptoServiceProvider::SignData