Im using the following code to create keys, but when i try to use KeyGeneration.getPublicKey() returns null.
public KeyGeneration() throws Exception,(more but cleared to make easier to read) { KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); kpg.initialize(1024); KeyPair kp = kpg.genKeyPair(); PublicKey publicKey = kp.getPublic(); PrivateKey privateKey = kp.getPrivate(); } public static PublicKey getPublicKey() { return publicKey; } Error message as below:
java.security.InvalidKeyException: No installed provider supports this key: (null) at javax.crypto.Cipher.chooseProvider(Cipher.java:878) at javax.crypto.Cipher.init(Cipher.java:1213) at javax.crypto.Cipher.init(Cipher.java:1153) at RSAHashEncryption.RSAHashCipher(RSAHashEncryption.java:41) at RSAHashEncryption.exportEHash(RSAHashEncryption.java:21) at Main.main(Main.java:28) If you would like to see the full code, i can post here.