您可以使用
BouncyCastle轻量级API执行此操作.
例如:
InputStream in = new FileInputStream("path/to/private/key");
AsymmetricKeyParameter privateKey = PrivateKeyFactory.createKey(in);
RSAPrivateCrtKeyParameters rsaPrivateKey = (RSAPrivateCrtKeyParameters)privateKey;
BigInteger modulus = rsaPrivateKey.getModulus();
BigInteger publicExponent = rsaPrivateKey.getPublicExponent();
RSAKeyParameters publicKeyParams = new RSAKeyParameters(false, modulus, publicExponent);
RSAKeyParameters类表示实际的键.
希望有所帮助!