private byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithmName)
{
int algorithmNid = GetAlgorithmNid(hashAlgorithmName);
SafeRsaHandle rsa = _key.Value;
byte[] signature = new byte[Interop.Crypto.RsaSize(rsa)];
int signatureSize;
bool success = Interop.Crypto.RsaSign(
algorithmNid,
hash,
hash.Length,
signature,
out signatureSize,
rsa);
if (!success)
{
throw Interop.Crypto.CreateOpenSslCryptographicException();
}
Debug.Assert(
signatureSize == signature.Length,
"RSA_sign reported an unexpected signature size",
"RSA_sign reported signatureSize was {0}, when {1} was expected",
signatureSize,
signature.Length);
return signature;
}