初学java,在研究软件时遇到了RSA 密钥长度2048的加密, 加密blocksize的长度是多少,解密blocksize的是长度256。求以下的解密方法对应加密方法,谢谢!
public static byte[] decode_sun(Key key, byte[] data, int blocksize) throws ErrorS{
byte[] returnStr = null;
ByteArrayOutputStream out = new ByteArrayOutputStream(data.length);
try {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(2, key);
int position = 0;
int length = data.length;
boolean more = true;
while(more) {
if (position + blocksize <= length) {
out.write(cipher.doFinal(data, position, blocksize));
position += blocksize;
} else {
more = false;
}
}
if (position < length) {
out.write(cipher.doFinal(data, position, length - position));
}
byte[] returnStr = out.toByteArray();
return returnStr;
} catch (Exception ) {
throw new ErrorS(ErrorCode.error_105231.getError());
}
}