For the task I am making, I must generate a public key using only modulus and exponent and then save the key to the Keystore.
I am able to generate a public key using modulus and exponent, but when it comes to saving it to Keystore I am unable to save it without a certificate. Here is the code for generating the public key based on modulus and exponent:
KeyFactory factory = KeyFactory.getInstance("RSA");
RSAPublicKeySpec rsaPublicKeySpec = new RSAPublicKeySpec(publicKeyData.getModulusInteger(), publicKeyData.getPublicExponentInteger());
PublicKey publicKey = factory.generatePublic(rsaPublicKeySpec);
I have tried setting key entry like this:
keyStore.setKeyEntry(alias, publicKey , "".toCharArray(), null);
Then I try accecing it:
(PublicKey) keyStore.getKey(alias, "".toCharArray());
Which gives an exception: java.security.UnrecoverableKeyException: Rejected by the jceks.key.serialFilter or jdk.serialFilter property
Is there a way to generate a certificate knowing only a public key, or is there another way to save a public key as an entry in the Keystore?