62,612
社区成员
发帖
与我相关
我的任务
分享
public byte[] privateKeyDecrypt(byte[] aBytes) throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.DECRYPT_MODE, getPrivateKey());
ByteBuffer tempBuffer = ByteBuffer.allocate(aBytes.length);
byte[] result;
int iOffset = 0;
int iLength = 0;
while (iOffset < aBytes.length) {
iLength = aBytes.length - iOffset;
if(iLength > 128){
iLength = 128;
}
result = cipher.doFinal(aBytes, iOffset, iLength);
tempBuffer.put(result);
iOffset += 128;
}
tempBuffer.flip();
byte[] finalBytes = new byte[tempBuffer.remaining()];
tempBuffer.get(finalBytes);
return finalBytes;
}