كتبت مشروع يعمل فك التشفير لملف باستخدام AES - 128
ولكن عندي مشكلة في الكود ولي يومين احاول احلها بش مش قادرة
وهي ظهور هذه الرسالة عن عمل run
"Input length must be multiple of 16 when decrypting with padded cipher"
بالرغم اني جربت اكثر من كود واكثر من طريقة لحل المشكلة لكن دون فائدة
الرجاء مساعدتي وشكرا
وهذا الكود
public byte[] decrypt (byte[] cipherText)
throws NoSuchAlgorithmException,GeneralSecurityException {
cipher.init(Cipher.DECRYPT_MODE, key);
// Remove cipher text length
int blocksize = 16;
int ciphertextLength = 0;
int remainder = cipherText.length % blocksize;
if (remainder == 0) {
ciphertextLength = cipherText.length;
}else{
ciphertextLength = cipherText.length - remainder + blocksize;
}
// how should i know the exact byte size require ?
byte [] decrypted = new byte[ciphertextLength];
int outLength = cipherText.length;
int ptLength = cipher.update( cipherText , 0 , outLength , decrypted , 0 );
ptLength+= cipher.doFinal( decrypted, ptLength );
return decrypted;
}