I call API that returns 2 public keys (as string), each consist of 512bits:
588506d0c604d8270ac4de9fdc520abe4779128ff5b7940d38fcd13d5e5fd07f
455c2c7b4e4a873c40f46b8e2bdfd90214591c3110b3c7ab7458818af3c59649
What i need to do, is to create PublicKey
object from them in order to sign data with. ( Each key for different data )
However, what i am trying to do throws error:
KeyFactory kf = KeyFactory.getInstance("RSA");
X509EncodedKeySpec keySpecX509 = new X509EncodedKeySpec(Base64.getDecoder().decode(publicKeyContent));
RSAPublicKey pubKey = (RSAPublicKey) kf.generatePublic(keySpecX509);
The error is:
java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: DerInputStream.getLength(): lengthTag=79, too big.
(Each key has different "lengthTag" in eror )
This publicKeys should be correct ( i was assured the API returns correct keys )
Am i misunderstanding something? Did i do any mistake? I am unable to figure it out, searching depths of google shows same method i used.
I appreciate all help or hints!