@Test(expected = IllegalArgumentException.class) public void testPaddingException() throws Exception { CbcBlockCipher.checkPadding(1, payloadData, payloadLength - 256); }
public static boolean checkPadding(int padding, byte[] data, int offset) { if (data.length < offset + 257) { throw new IllegalArgumentException("data must contain 257 bytes from offset on!"); } byte result1 = 0; byte result2 = 0; byte pad = (byte) padding; for (int index = 0; index <= padding; ++index) { result1 |= pad ^ data[offset + index]; } for (int index = padding + 1; index < 256; ++index) { result2 |= pad ^ data[offset + index]; } data[data.length - 1] ^= result2; return result1 == 0; }
CbcBlockCipher { public static boolean checkPadding(int padding, byte[] data, int offset) { if (data.length < offset + 257) { throw new IllegalArgumentException("data must contain 257 bytes from offset on!"); } byte result1 = 0; byte result2 = 0; byte pad = (byte) padding; for (int index = 0; index <= padding; ++index) { result1 |= pad ^ data[offset + index]; } for (int index = padding + 1; index < 256; ++index) { result2 |= pad ^ data[offset + index]; } data[data.length - 1] ^= result2; return result1 == 0; } }
CbcBlockCipher { public static boolean checkPadding(int padding, byte[] data, int offset) { if (data.length < offset + 257) { throw new IllegalArgumentException("data must contain 257 bytes from offset on!"); } byte result1 = 0; byte result2 = 0; byte pad = (byte) padding; for (int index = 0; index <= padding; ++index) { result1 |= pad ^ data[offset + index]; } for (int index = padding + 1; index < 256; ++index) { result2 |= pad ^ data[offset + index]; } data[data.length - 1] ^= result2; return result1 == 0; }  }
CbcBlockCipher { public static boolean checkPadding(int padding, byte[] data, int offset) { if (data.length < offset + 257) { throw new IllegalArgumentException("data must contain 257 bytes from offset on!"); } byte result1 = 0; byte result2 = 0; byte pad = (byte) padding; for (int index = 0; index <= padding; ++index) { result1 |= pad ^ data[offset + index]; } for (int index = padding + 1; index < 256; ++index) { result2 |= pad ^ data[offset + index]; } data[data.length - 1] ^= result2; return result1 == 0; }  static byte[] decrypt(CipherSuite suite, SecretKey key, SecretKey macKey, byte[] additionalData,
			byte[] ciphertext); static byte[] encrypt(CipherSuite suite, SecretKey key, SecretKey macKey, byte[] additionalData,
			byte[] payload); static byte[] getBlockCipherMac(Mac hmac, SecretKey macKey, byte[] additionalData, byte[] content,
			int length); static boolean checkPadding(int padding, byte[] data, int offset); }
CbcBlockCipher { public static boolean checkPadding(int padding, byte[] data, int offset) { if (data.length < offset + 257) { throw new IllegalArgumentException("data must contain 257 bytes from offset on!"); } byte result1 = 0; byte result2 = 0; byte pad = (byte) padding; for (int index = 0; index <= padding; ++index) { result1 |= pad ^ data[offset + index]; } for (int index = padding + 1; index < 256; ++index) { result2 |= pad ^ data[offset + index]; } data[data.length - 1] ^= result2; return result1 == 0; }  static byte[] decrypt(CipherSuite suite, SecretKey key, SecretKey macKey, byte[] additionalData,
			byte[] ciphertext); static byte[] encrypt(CipherSuite suite, SecretKey key, SecretKey macKey, byte[] additionalData,
			byte[] payload); static byte[] getBlockCipherMac(Mac hmac, SecretKey macKey, byte[] additionalData, byte[] content,
			int length); static boolean checkPadding(int padding, byte[] data, int offset);  }