java.security.spec.InvalidKeySpecException: Only RSAPrivate(Crt)KeySpec and PKCS8EncodedKeySpec supported for RSA private keys

public PrivateKey getPrivateKey(String fileName) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException
{
byte[] keyFileBytes = readKeyFile(fileName);
X509EncodedKeySpec spec =
new X509EncodedKeySpec(keyFileBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
return kf.generatePrivate(spec);
}

The reason is this line, This is used to read public key spec and not private key. The private key is read via

PKCS8EncodedKeySpec spec =
      new PKCS8EncodedKeySpec(keyBytes);
So as the error says it needs to be in PKCS8 spec format for java to understand.

Comments

  1. Java.Security.Spec.Invalidkeyspecexception: Only Rsaprivate(Crt)Keyspec And Pkcs8Encodedkeyspec Supported For Rsa Private Keys >>>>> Download Now

    >>>>> Download Full

    Java.Security.Spec.Invalidkeyspecexception: Only Rsaprivate(Crt)Keyspec And Pkcs8Encodedkeyspec Supported For Rsa Private Keys >>>>> Download LINK

    >>>>> Download Now

    Java.Security.Spec.Invalidkeyspecexception: Only Rsaprivate(Crt)Keyspec And Pkcs8Encodedkeyspec Supported For Rsa Private Keys >>>>> Download Full

    >>>>> Download LINK 7S

    ReplyDelete

Post a Comment