• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error when encrypting data using Cipher  RSS feed

John Paul Hoey
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have a problem that I'm hoping someone may be able to help me with.

I want to load a public key (.cer file) into a keystore and then use this key to encrypt some data.

The key appears to be loaded into the keystore correctly because I can view its contents using the keystore.getCertificate(alias) method.

However, when I then attempt to use this key to encrypt a piece of data, I get the following error displayed:

Exception in thread "main" java.security.InvalidKeyException: Unsupported key type: null
at sun.security.mscapi.RSACipher.engineGetKeySize(RSACipher.java:404)

Here is my code:

I am not sure why I am getting this error therefore if someone could provide some input or guidance with this matter then that would be greatly appreciated.

Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!