public override RSAParameters ExportParameters(bool includePrivateParameters)
{
// It's entirely possible that this line will cause the key to be generated in the first place.
SafeRsaHandle key = _key.Value;
CheckInvalidKey(key);
RSAParameters rsaParameters = Interop.Crypto.ExportRsaParameters(key, includePrivateParameters);
bool hasPrivateKey = rsaParameters.D != null;
if (hasPrivateKey != includePrivateParameters || !HasConsistentPrivateKey(ref rsaParameters))
{
throw new CryptographicException(SR.Cryptography_CSP_NoPrivateKey);
}
return rsaParameters;
}