问题
I am trying to decrypt a string with RSA. It was encrypted in C# on the iPhone and I have the private key. This seems like a silly problem, but all of the examples I have seen show generating the private key. I have the private key (it is a byte[] of hex). It using PKCS#1 padding. The part I cannot figure out how to do is create a java.security.Key object with the private key I already have.
Do I need to have them give me the private key in 2 parts...modulus and exponent?
Thanks in advance.
回答1:
You need to go through a RSAPrivateKeySpec. Here's an example (based on this):
BigInteger n = new BigInteger(nBytes);
BigInteger p = new BigInteger(pBytes);
RSAPrivateKeySpec privateSpec = new RSAPrivateKeySpec(n, p);
KeyFactory kf = KeyFactory.getInstance("RSA");
Key privateKey = kf.generatePrivate(privateSpec);
来源:https://stackoverflow.com/questions/1236481/rsa-decrypt-with-java