0
使用下面的代码创建密钥,但是当我尝试使用KeyGeneration.getPublicKey()
返回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; }
如下错误信息:
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)
如果你想看到完整的代码,我可以张贴在这里。
你正在使用哪个java版本? –
我们不需要完整的代码,只需[SSCCE](http://www.sscce.org)=) –