M
Marco A. Cruz Quevedo
Hi everybody:
I have the following code:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
X509EncodedKeySpec publicKeySpec = new
X509EncodedKeySpec(encodedPublicKey);
System.out.println("\tKey Factory Algorithm =
"+keyFactory.getAlgorithm());
System.out.println("\tKey Factory Provider =
"+keyFactory.getProvider());
PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
System.out.println("\t*** Public key in key factory\n\n");
PKCS8EncodedKeySpec privateKeySpec = new
PKCS8EncodedKeySpec(encodedPrivateKey);
System.out.println("\tEncoded KeySpec Format=
"+privateKeySpec.getFormat());
//-- *** error !
RSAPrivateKey mc_privkey =
keyFactory.generatePrivate(privateKeySpec);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
And when this code is run, I get the following error:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
java.security.InvalidKeyException: IOException : DER input,
Integer tag error
java.security.spec.InvalidKeySpecException:
java.security.InvalidKeyException: I
OException : DER input, Integer tag error
at
sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(Unknown Source)
at java.security.KeyFactory.generatePrivate(Unknown Source)
at encripta.main(encripta.java:99)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
It seems the keyfactory does not accept the RSAPrivateKey object, Why?
What is missing or wrong?
Thank you in advance
Marco.
---
I have the following code:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
X509EncodedKeySpec publicKeySpec = new
X509EncodedKeySpec(encodedPublicKey);
System.out.println("\tKey Factory Algorithm =
"+keyFactory.getAlgorithm());
System.out.println("\tKey Factory Provider =
"+keyFactory.getProvider());
PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
System.out.println("\t*** Public key in key factory\n\n");
PKCS8EncodedKeySpec privateKeySpec = new
PKCS8EncodedKeySpec(encodedPrivateKey);
System.out.println("\tEncoded KeySpec Format=
"+privateKeySpec.getFormat());
//-- *** error !
RSAPrivateKey mc_privkey =
keyFactory.generatePrivate(privateKeySpec);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
And when this code is run, I get the following error:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
java.security.InvalidKeyException: IOException : DER input,
Integer tag error
java.security.spec.InvalidKeySpecException:
java.security.InvalidKeyException: I
OException : DER input, Integer tag error
at
sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(Unknown Source)
at java.security.KeyFactory.generatePrivate(Unknown Source)
at encripta.main(encripta.java:99)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
It seems the keyfactory does not accept the RSAPrivateKey object, Why?
What is missing or wrong?
Thank you in advance
Marco.
---