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

Popular posts from this blog

'jasypt.encryptor.password' or one of ['jasypt.encryptor.privateKeyString', 'jasypt.encryptor.privateKeyLocation'] must be provided for Password-based or Asymmetric encryption

Field or property 'jobParameters' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - Spring Batch

Couldn't store job: Unable to serialize JobDataMap for insertion into database because the value of property 'jobLauncher' is not serializable