public override RSAParameters ExportParameters(bool includePrivateParameters) { if ((includePrivateParameters) && (!privateKeyExportable)) { throw new CryptographicException("cannot export private key"); } var rsaParams = rsa.ExportParameters(includePrivateParameters); if (includePrivateParameters) { // we want an ArgumentNullException is only the D is missing, but a // CryptographicException if other parameters (CRT) are missings if (rsaParams.D == null) { throw new ArgumentNullException("Missing D parameter for the private key."); } else if ((rsaParams.P == null) || (rsaParams.Q == null) || (rsaParams.DP == null) || (rsaParams.DQ == null) || (rsaParams.InverseQ == null)) { // note: we can import a private key, using FromXmlString, // without the CRT parameters but we export it using ToXmlString! throw new CryptographicException("Missing some CRT parameters for the private key."); } } return(rsaParams); }
public override RSAParameters ExportParameters(bool includePrivateParameters) { if ((includePrivateParameters) && (!privateKeyExportable)) { throw new CryptographicException("cannot export private key"); } return(rsa.ExportParameters(includePrivateParameters)); }