title: Two different Private Keys
body: <p>I am trying to digitally sign and then validate an AuthnRequest.
  I've generated the private key and public key certificate using the following commands:</p>
  
  <pre><code>openssl genrsa -out privatekey.pem 2048
  openssl req -new -x509 -key privatekey.pem -out publickey.cer -days 365
  openssl pkcs12 -export -out public_privatekey.pfx -inkey privatekey.pem -in publickey.cer
  </code></pre>
  
  <p>Converted the PFX to JKS by following command:</p>
  
  <pre><code>keytool -importkeystore -srckeystore public_privatekey.pfx -srcstoretype pkcs12 
  -destkeystore clientcert.jks -deststoretype JKS
  </code></pre>
  
  <p>and I am accessing that private key entry and public key certificate using the following java code:</p>
  
  <pre><code>KeyStore ks = KeyStore.getInstance("JKS");
  ks.load(new FileInputStream(keystoreFile), "dps123!@#".toCharArray());
  
  KeyStore.PrivateKeyEntry keyEntry = (KeyStore.PrivateKeyEntry) ks.getEntry("1", new KeyStore.PasswordProtection("dps123!@#".toCharArray()));
  java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate) keyEntry.getCertificate();
  </code></pre>
  
  <p>I got to print the private key value to the console by following:</p>
  
  <pre><code>String key = Base64.encode(keyEntry.getPrivateKey().getEncoded());
  System.out.println(key);
  </code></pre>
  
  <p>When I compare the contents of String "key" and the contents in "privatekey.pem" file, both are different. Is it something that I am not understanding correctly or there is a problem getting the private key value in the code?</p>