public SignData ( byte buffer, Object halg ) : byte[] | ||
buffer | byte | The input data for which to compute the hash |
halg | Object | The hash algorithm to use to create the hash value. |
Résultat | byte[] |
public byte[] SignData(byte[] buffer, Object halg)
{
int calgHash = CapiHelper.ObjToHashAlgId(halg);
HashAlgorithm hash = CapiHelper.ObjToHashAlgorithm(halg);
byte[] hashVal = hash.ComputeHash(buffer);
return SignHash(hashVal, calgHash);
}
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); }