/** * Encode a splitfile block. * @param data The data to encode. Must be exactly DATA_LENGTH bytes. * @param cryptoKey The encryption key. Can be null in which case this is equivalent to a normal block * encode. */ static public ClientCHKBlock encodeSplitfileBlock(byte[] data, byte[] cryptoKey, byte cryptoAlgorithm) throws CHKEncodeException { if(data.length != CHKBlock.DATA_LENGTH) throw new IllegalArgumentException(); if(cryptoKey != null && cryptoKey.length != 32) throw new IllegalArgumentException(); MessageDigest md256 = SHA256.getMessageDigest(); // No need to pad if(cryptoKey == null) { cryptoKey = md256.digest(data); } if(cryptoAlgorithm == Key.ALGO_AES_PCFB_256_SHA256) return innerEncode(data, CHKBlock.DATA_LENGTH, md256, cryptoKey, false, (short)-1, cryptoAlgorithm); else if(cryptoAlgorithm != Key.ALGO_AES_CTR_256_SHA256) throw new IllegalArgumentException("Unknown crypto algorithm: "+cryptoAlgorithm); if(Rijndael.AesCtrProvider == null) { return encodeNewNoJCA(data, CHKBlock.DATA_LENGTH, md256, cryptoKey, false, (short)-1, cryptoAlgorithm, KeyBlock.HASH_SHA256); } else { return encodeNew(data, CHKBlock.DATA_LENGTH, md256, cryptoKey, false, (short)-1, cryptoAlgorithm, KeyBlock.HASH_SHA256); } }
else { if(Rijndael.AesCtrProvider == null || forceNoJCA) return encodeNewNoJCA(data, dataLength, md256, encKey, asMetadata, compressionAlgorithm, cryptoAlgorithm, KeyBlock.HASH_SHA256); else return encodeNew(data, dataLength, md256, encKey, asMetadata, compressionAlgorithm, cryptoAlgorithm, KeyBlock.HASH_SHA256);