int size = ((plaintext[data.length] & 0xff) << 8) + (plaintext[data.length + 1] & 0xff);
if((size > 32768) || (size < 0)) {
throw new CHKDecodeException("Invalid size: "+size);
}
// Check the hash.
Mac hmac = Mac.getInstance("HmacSHA256", hmacProvider);
hmac.init(new SecretKeySpec(cryptoKey, "HmacSHA256"));
hmac.update(plaintext); // plaintext includes lengthBytes
byte[] hashCheck = hmac.doFinal();
if(!Arrays.equals(hash, hashCheck)) {
throw new CHKDecodeException("HMAC is wrong, wrong decryption key?");
}
return Key.decompress(dontCompress ? false : key.isCompressed(), plaintext, size, bf,
Math.min(maxLength, CHKBlock.MAX_LENGTH_BEFORE_COMPRESSION), key.compressionAlgorithm, false);