title: java - need to import private key from jks(java keystore)
body: <p>I have a stored my certificate in Java KeyStore which is required for accessing Restful API. To access this API I need to create JWT (Json Web Token) which I am implementing in Java. For generating JWT I need to sign the payload with given private key.
  So, what I am doing is, importing private key from .jks file into my code </p>
  
  <pre><code>FileInputStream is = new FileInputStream("src/main/resources/file.jks");
              KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
              keystore.load(is, "password".toCharArray());  
  PrivateKey privateKey = (PrivateKey) keystore.getKey("key", "".toCharArray());
  JWTClaimsSet claimsSetOne = new JWTClaimsSet.Builder()
                  .subject("alias")
                  .issueTime(new Date(123000L))
                  .issuer("https://issuer")
                  .audience("https://audience")
                  .build();
  
  JWSSigner signer = new RSASSASigner(privateKey);
  SignedJWT signedJWT = new SignedJWT (new JWSHeader(JWSAlgorithm.RS256), claimsSetOne);
  signedJWT.sign(signer);
  String orderOne = signedJWT.serialize();
  </code></pre>
  
  <p>Now, with this piece of code, It returns private key as "null" value. which results into failure of my code.
  So, what could be my code so that I can read private key to sign the payload to generate JWT.
  Or any other alternative to achieve same.
  Thanks in advance.<br>
  Edit :
  Then I tried this command,</p>
  
  <pre><code>File file = new File("src/main/resources/sho1.jks");
  InputStream   is = new FileInputStream(file);
  KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
  String password = "sho123";
  keystore.load(is, password.toCharArray());
  
  KeyStore.PrivateKeyEntry keyEnt = 
     (KeyStore.PrivateKeyEntry) keystore.getEntry("sho",new KeyStore.PasswordProtection(password.toCharArray()));
  PrivateKey privateKey = keyEnt.getPrivateKey();
  </code></pre>
  
  <p>It gives me error as Invalid_Signature.</p>