0

I generated a public using java keygenerator:

Sun RSA public key, 1024 bits modulus: 106394877608018766537720801416655991345106535990850729605963854419450103716730599362154190537257597233014065015311499176359112816419965961469419756050290964343366687334245741905264407605904082573446954295309549250335299907317631410981650257400135070254491184426528002396792285738067623733919575203674519111607 public exponent: 65537

I sent this key from client side(via copy,paste) and received exactly exactly the same as a string. Then I tried to reconstruct it:

byte [] bytes = publicKey.getBytes("UTF-8");
Key key = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(bytes));

Then I am returning from the function. I am getting Invalid Key Exception from line 2 where I form Key.

Any ideas?

0

1 Answer 1

3

You need to Use RSAPublicKeySpec

String modulus="106394877608018766537720801416655991345106535990850729605963854419450103716730599362154190537257597233014065015311499176359112816419965961469419756050290964343366687334245741905264407605904082573446954295309549250335299907317631410981650257400135070254491184426528002396792285738067623733919575203674519111607";
    RSAPublicKeySpec spec = new RSAPublicKeySpec(new BigInteger(modulus),BigInteger.valueOf(65537));

    Key key = KeyFactory.getInstance("RSA").generatePublic(spec);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.