Array space being reused in Java?

Ninaw

New Member
I have following loop (part of a program that does decryption):\[code\]for(int i=0; i < inputd.length; i++){ byte[] blockd = this.fromHex(inputd); byte[] pt = cipher.doFinal(blockd); // Problem? if(plainText == null) plainText = new String(pt); else plainText+=new String(pt);}\[/code\]In the marked statement, \[code\]cipher.doFinal(blockd)\[/code\] returns arrays of different sizes. The problem is if in an iteration array of size say 30 is returned and in next iteration say its 25 (smaller) then assignment replaces first 25 characters and last 5 chars of previous iteration are still in the array.This is \[code\]fromHex()\[/code\] function:\[code\] private byte[] fromHex(String b){ byte[] bt = (new BigInteger(b, 16)).toByteArray(); if(bt.length > 64){ bt = Arrays.copyOfRange(bt, 1, 65); } return bt; }\[/code\]How should I solve this? Assigning null to both before loop end doesn't help.Thank you.
 
Back
Top