title: Validate if RSA key matches X.509 certificate in Java
body: <p>I have a RSA Key and a X.509 Certificate which I use for SSL connections. </p>
  
  <p>The key and certificate are stored in files in PEM format (generated by OpenSSL) and used in an Apache HTTP server environment.</p>
  
  <p>Is there an easy way to validate if the key matches the certificate using only Java code (without executing the openssl binary and parsing the output), for example by using Java security and/or Bouncycastle library methods?</p>