Source:
private byte[] decryptBlockCipher(byte[] ciphertextFragment, DTLSConnectionState currentReadState) throws GeneralSecurityException { if (currentReadState == null) { throw new NullPointerException("Current read state must not be null"); } else if (ciphertextFragment == null) { throw new NullPointerException("Ciphertext must not be null"); } else if (ciphertextFragment.length % currentReadState.getRecordIvLength() != 0) { throw new GeneralSecurityException("Ciphertext doesn't fit block size!"); } else if (ciphertextFragment.length < currentReadState.getRecordIvLength() + currentReadState.getMacLength() + 1) { throw new GeneralSecurityException("Ciphertext too short!"); } DatagramReader reader = new DatagramReader(ciphertextFragment); byte[] iv = reader.readBytes(currentReadState.getRecordIvLength()); Cipher blockCipher = currentReadState.getCipherSuite().getCipher(); blockCipher.init(Cipher.DECRYPT_MODE, currentReadState.getEncryptionKey(), new IvParameterSpec(iv)); byte[] plaintext = blockCipher.doFinal(reader.readBytesLeft()); int paddingLength = plaintext[plaintext.length - 1] & 0xff; int fragmentLength = plaintext.length - 1 - currentReadState.getMacLength(); if (fragmentLength < paddingLength) { throw new InvalidMacException(); } fragmentLength -= paddingLength; for (int index = fragmentLength + currentReadState.getMacLength(); index < plaintext.length; ++index) { if (plaintext[index] != (byte) paddingLength) { throw new InvalidMacException(); } } byte[] content = Arrays.copyOf(plaintext, fragmentLength); byte[] macFromMessage = Arrays.copyOfRange(plaintext, fragmentLength, fragmentLength + currentReadState.getCipherSuite().getMacLength()); byte[] mac = getBlockCipherMac(currentReadState, content); if (Arrays.equals(macFromMessage, mac)) { return content; } else { throw new InvalidMacException(mac, macFromMessage); } }

Target:
private byte[] decryptBlockCipher(byte[] ciphertextFragment, DTLSConnectionState currentReadState) throws GeneralSecurityException { if (currentReadState == null) { throw new NullPointerException("Current read state must not be null"); } else if (ciphertextFragment == null) { throw new NullPointerException("Ciphertext must not be null"); } else if (ciphertextFragment.length % currentReadState.getRecordIvLength() != 0) { throw new GeneralSecurityException("Ciphertext doesn't fit block size!"); } else if (ciphertextFragment.length < currentReadState.getRecordIvLength() + currentReadState.getMacLength() + 1) { throw new GeneralSecurityException("Ciphertext too short!"); } DatagramReader reader = new DatagramReader(ciphertextFragment); byte[] iv = reader.readBytes(currentReadState.getRecordIvLength()); Cipher blockCipher = currentReadState.getCipherSuite().getCipher(); blockCipher.init(Cipher.DECRYPT_MODE, currentReadState.getEncryptionKey(), new IvParameterSpec(iv)); byte[] plaintext = blockCipher.doFinal(reader.readBytesLeft()); int paddingLength = plaintext[plaintext.length - 1] & 0xff; int fragmentLength = plaintext.length - 1 - paddingLength - currentReadState.getMacLength(); if (fragmentLength < 0) { throw new InvalidMacException(); } for (int index = fragmentLength + currentReadState.getMacLength(); index < plaintext.length; ++index) { if (plaintext[index] != (byte) paddingLength) { throw new InvalidMacException(); } } byte[] content = Arrays.copyOf(plaintext, fragmentLength); byte[] macFromMessage = Arrays.copyOfRange(plaintext, fragmentLength, fragmentLength + currentReadState.getCipherSuite().getMacLength()); byte[] mac = getBlockCipherMac(currentReadState, content); if (Arrays.equals(macFromMessage, mac)) { return content; } else { throw new InvalidMacException(mac, macFromMessage); } }