Thursday 15 May 2014

java - array out of bounds adding a byte array to another -


Working on a bit of crypto and the limit ran out of an array outside the exception, I searched it on paper several times and Everyone seems right to me so I can not really determine the origin of the error, if anyone will help that would be horrible!

  static byte [] encrypt (byte [pt] pytes, javax.crypto.SecretKey key, byte [] IV) {byte [CT]; Byte [pt]; Byte [ptBlock, ctBlock; Int bytes; // The number of bytes in the last block is left / / it comes in the game / Swap and accessories / extra bytes with the last 2 blocks, in case the last block of plain text is not whole bytes = ptBytes. Length% 16; // pad the plain text array to the appropriate length pt = Arrays.copyOf (ptBytes, (ptBytes.length) / 16) + 1) * 16); Println (Arrays.toString (PT)); // ctBlock = one block of cipher text ctBlock = new byte [16]; // CT to padded PT CT = new byte length [pt.length]; // Encryption / I am for the current block of plain / cipher text, we are on (int i = 1; i & lt; = ((ptbytes.length) / 16) +1; i ++) (I == 1) Make the first segment of {// ptBlock} the whole plain text ptBlock = Arrays.copyOfRange (pt, 0, (i * 16)); // I = 1 after XOR obtains a new plain text With IV (int j = 0; j   

It says that the error is on this line

  ct [k] = ctBlock [k-16];   

Which does not make much sense, the array is CT length 48, and CTBLL is lane 16 and in case of this error where this error is in the loop, i would be 2 or 3 That's why I'm adding 16 byte array of any size to the other third part. Array whistle or third third and as I said I discovered it on paper and it seemed to be legally inactive!

Thanks in advance!

Consider the case when i = 3 .

 for  (int k = (i-1) * 16; k & lt; (i * 16) -1, k ++) {whistle} = ctblock [k - 16]; }   

here -

  • Kashmir begins with 32
  • the status goes to 32 < 47
  • The array index for ctBlock gets 32 - 16 = 16, and balm! The array index is not bound!

    Quick correction -

     for  (int k = (i - 1) * 16; k    

No comments:

Post a Comment