• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

invalidkeyspecexception - PKCS8EncodedKeySpec

Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am new to encryption and decryption methologies. I dont know who different algorithms works in any way. I am using Java Secuirty package to get the work done. This is want I am doing.

1. My Key Resource is picture "*.gif" image is used for Key generation.
2. This is how I am generating the Public Key to encrypt the data. It works really fine, giving me 128 bytes of data.

2. I am using the following code for privateKey generation

I am using the following parameters in cipher ->"RSA/ECB/PKCS1Padding". (bothe Encryption and Decryption) in the Cipher.

When I trying the decrypt the encoded values, I am facing the following error . I have wasted all my day on this error.

java.security.InvalidKeyException: Unsupported key type: null at sun.security.mscapi.RSACipher.engineGetKeySize(RSACipher.java:341) at javax.crypto.Cipher.b(DashoA13*..) at

Can someone help me with the issue .I tried to google the error, but could not get any solution.

I would really appreciate any other method or procedure to acomplish this task. I am encrypting emailID and Password. I could have used MD5, but my team needs 2 way process.

Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code does not attempt to generate any keys at all, it attempts to read in keys that have already been generated somewhere else and stored in a file. These keys are expected to be in a certain precise formats. If they aren't, you receive the errors you have received.

There's no way an image file is going to simultaneously be parseable as an image, an RSA public key, and an RSA private key by chance.

In any event, since you are using low-level crypto you must become educated about cryptography on your own. The low-level APIs you are using are not foolproof black boxes that you can just mercilessly and randomly hack to death until you get something that runs without errors. You also cannot get this education by asking on forums why said hacking produced an error.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic