我的Android项目(RSA加密/解密)出现错误。 加密通过确定,但是当我尝试解密加密文本时,有错误:“RSA块的数据太多”。Java Android错误“RSA数据块太多”
如何解决这个问题?
代码:
public String Decrypt(String text) throws Exception
{
try{
Log.i("Crypto.java:Decrypt", text);
RSAPrivateKey privateKey = (RSAPrivateKey)kp.getPrivate();
Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] cipherData = cipher.doFinal(text.getBytes());// <----ERROR: too much data for RSA block
byte[] decryptedBytes = cipher.doFinal(cipherData);
String decrypted = new String(decryptedBytes);
Log.i("Decrypted", decrypted);
return decrypted;
}catch(Exception e){
System.out.println(e.getMessage());
}
return null;
}
我对这个图书馆一无所知,但我的猜测是“文字”字符太多;太长。你可以尝试缩短它只是为了测试一小部分? – Sababado 2013-02-22 12:55:35
@Perception除了它不是一个确切的重复,这个问题很难理解,并且很难从刚刚开始非对称加密/解密的人那里提取答案。 – 2013-02-22 13:16:50
不,“太多的RSA数据块失败的数据。什么是PKCS#7”不能帮助我:( – user2095816 2013-02-22 13:28:01