Originally posted by greg stark:
Use the getEncoded() method to get the byte[] from the keys. To go the other way, getting an RSAPublicKey or RSAPrivateKey from a byte[], use the appropriate KeyFactory methods and encoded key specs, e.g. for RSAPrivateKey
and for RSAPublicKey
Hi,
I applied your code to my example:
rsaKeyFac = KeyFactory.getInstance("RSA");
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(client_privatekey.getEncoded());
RSAPublicKey pubKey = (RSAPublicKey )rsaKeyFac.generatePublic(keySpec);
However I get the following error when executing the last line:
Exception in
thread "main" java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: algid parse error, not a sequence
Any expeience from this?
Best regards
Lasse