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 ( byte buffer, int offset, int count, object halg ) : byte[]
buffer byte The input data for which to compute the hash
offset int The offset into the array from which to begin using data
count int The number of bytes in the array to use as data.
halg object The hash algorithm to use to create the hash value.
return byte[]
        public byte[] SignData(byte[] buffer, int offset, int count, object halg)
        {
            int calgHash = CapiHelper.ObjToHashAlgId(halg);
            HashAlgorithm hash = CapiHelper.ObjToHashAlgorithm(halg);
            byte[] hashVal = hash.ComputeHash(buffer, offset, count);
            return SignHash(hashVal, calgHash);
        }

Same methods

RSACryptoServiceProvider::SignData ( Stream inputStream, Object halg ) : byte[]
RSACryptoServiceProvider::SignData ( byte buffer, Object halg ) : byte[]

Usage 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