Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.lang.java.security > #278

keyfactory does not accept RSAPrivateKey for private key encryption

From "Marco A. Cruz Quevedo" <macruzq@myway.com>
Newsgroups comp.lang.java.programmer, comp.lang.java.security
Subject keyfactory does not accept RSAPrivateKey for private key encryption
Date 2011-01-29 07:10 -0800
Organization http://groups.google.com
Message-ID <46b61080-7f0a-4c3d-8180-0a3d7301eebf@k21g2000prb.googlegroups.com> (permalink)

Cross-posted to 2 groups.

Show all headers | View raw


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.
---

Back to comp.lang.java.security | Previous | Next | Find similar


Thread

keyfactory does not accept RSAPrivateKey for private key encryption "Marco A. Cruz Quevedo" <macruzq@myway.com> - 2011-01-29 07:10 -0800

csiph-web