I know, but I want to specifically set a public key that coincides with the private key the server generates.
I can't figure out how to set a key...
Joined: Mar 22, 2005
Once you have the bytes that make up a key, you can create a Key object from it like this:
Joined: Jan 16, 2010
Well Ulf, I tried fiddling with it for a bit, and googling the error, and I can't seem to get it...
Here is what I have atm:
And here is the error:
Exception in thread "main" java.security.InvalidKeyException: Neither a public nor a private key
Ulf Dittmer wrote:Once you have the bytes that make up a key, you can create a Key object from it like this:
That is for a secret (symmetric) key. For a public key, you create an X509EncodedKeySpec from the result of PublicKey.getEncoded(). You supply the X509EncodedKeySpec instance to a KeyFactory instance. Using the getInstance() method to get an RSA instance. Then use the generatePublic() method and supply the X509EncodedKeySpec to it to get the public key.