开发者

NullPointerException when generating RSA keys with BouncyCastle

开发者 https://www.devze.com 2022-12-31 06:07 出处:网络
public static void main(String[] args) throws Exception { RSAKeyPairGenerator rsaKeyPairGen = new RSAKeyPairGenerator();
public static void main(String[] args) throws Exception {
    RSAKeyPairGenerator rsaKeyPairGen = new RSAKeyPairGenerator();
    AsymmetricCipherKeyPair keyPair = rsaKeyPairGen.generateKeyPair();
}

the rsaKeyPairGen is not null, but the generateKeyPair() method is throwing NullPointerException. What may be wrong?

Err开发者_运维技巧or message:

java.lang.NullPointerException
at org.bouncycastle.crypto.generators.RSAKeyPairGenerator.generateKeyPair(Unknown Source)
at pkg.main(Main.java:154)


You have to specify the bit length and the random number generator you want to use for the key (see the javadoc):

For generating a 2048 bit RSA key:

rsaKeyPairGen.init( new KeyGenerationParameters( new SecureRandom(), 2048 ) );
0

精彩评论

暂无评论...
验证码 换一张
取 消