我遇到了RSA非对称加密算法的严重问题。 使用用户A公钥加密的消息正由用户的私钥解密。在电脑上它工作正常。当我在java中运行它时效果很好,但在android中它并没有。下面是代码:
public synchronized void generate_keys()
{
SecureRandom secureRandom = new SecureRandom();
BigInteger p = new BigInteger(bitLength/2,100 ,secureRandom);
BigInteger q = new BigInteger(bitLength/2,100 ,secureRandom);
n = p.multiply(q);
BigInteger v = (p.subtract(BigInteger.ONE)).
multiply(q.subtract(BigInteger.ONE));
e = new BigInteger("3");
while (v.gcd(e).intValue() > 1 )
{
e = e.add(new BigInteger("2"));
}
d = e.modInverse(v);
}
public synchronized static String encryptKey(String key, BigInteger n,
BigInteger publicKey) {
BigInteger plaintTextBytes = new BigInteger(key.getBytes());
return plaintTextBytes.modPow(publicKey, n).toString();
}
public synchronized static String decryptKey(String CypherKey,
BigInteger privateKey, BigInteger n) {
BigInteger keyBytes = new BigInteger(CypherKey);
BigInteger key = keyBytes.modPow(privateKey, n);
return new String(key.toByteArray());
}
请仔细阅读代码并指导我找出可能导致问题的原因。