} catch (UnsupportedCipherException e) {
// Impossible.
throw new Error(e);
}
aes.initialize(cryptoKey);
CTRBlockCipher cipher = new CTRBlockCipher(aes);
cipher.init(hash, 0, 16);
byte[] plaintext = new byte[data.length];
cipher.processBytes(data, 0, data.length, plaintext, 0);
byte[] lengthBytes = new byte[2];
cipher.processBytes(headers, hash.length+2, 2, lengthBytes, 0);
int size = ((lengthBytes[0] & 0xff) << 8) + (lengthBytes[1] & 0xff);
if((size > 32768) || (size < 0)) {
throw new CHKDecodeException("Invalid size: "+size);
}
try {