The private and the public key from the cert must have the same algorithm, correct?

Yes of course pub / priv are a key pair.
So this code would be legal, to be more flexible (e.g. ECDSA or DSA):

PrivateKey privkey = (PrivateKey) keystore.getKey(keyAlias, passphrase);
Certificate cert = keystore.getCertificate(keyAlias);
KeyFactory keyFactory = KeyFactory.getInstance(privkey.getAlgorithm()); //before: "RSA"
publicKey = keyFactory.generatePublic(keySpec1);`

Normally the private and public key will be generated as a keypair in which they use the algorithm to generate that keypair. so obviously the keys will be mathematically related each other, otherwise it wont.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.