title: How to check if private/public key pair match using (.NET / BouncyCastle)?
body: <p>I have AsymmetricKeyParameter object for private and public key. What is the easiest way to see if they match? </p>
  
  <p>I am trying to encrypt some text (private key) and decrypt some text (public key). 
  So far I have not been able to do that but it seems like the wrong approach.</p>
  
  <p>Update: Here is sample code:</p>
  
  <pre><code>X509Certificate2 c = new X509Certificate2(@"certificate.cer");
  byte[] privateKeyData = System.IO.File.ReadAllBytes(@"private.key");
  Org.BouncyCastle.X509.X509Certificate cert = DotNetUtilities.FromX509Certificate(c);
  
  
  RsaPrivateCrtKeyParameters privateKey = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(privateKeyData);
  RsaKeyParameters publicKey = (RsaKeyParameters)cert.GetPublicKey();
  
  if (privateKey.Modulus.Equals(publicKey.Modulus) &amp;&amp; publicKey.Exponent.Equals(privateKey.PublicExponent)) 
  {
       //they match
  }
  </code></pre>