解决方法:
1.下载bcprov-jdk16-140.jar包,参考:http://www.yayihouse.com/yayishuwu/chapter/1537
2.java代码
KeyPairGenerator keyPairGenerator = KeyPairGenerator
.getInstance("RSA");
keyPairGenerator.initialize(2048);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
System.out.println("公钥:"+new BASE64Encoder().encodeBuffer(publicKey.getEncoded()));
System.out.println("私钥:"+new BASE64Encoder().encodeBuffer(privateKey.getEncoded()));