gpt4 book ai didi

Java 安卓错误 "too much data for RSA block"

转载 作者:行者123 更新时间:2023-11-29 05:48:11 25 4
gpt4 key购买 nike

<分区>

A 在我的 Android 项目中出现错误(RSA 加密/解密)。加密通过 OK,但是当我尝试解密加密文本时,出现错误:“RSA block 的数据过多”

如何解决这个问题?

代码:

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;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com