public EncryptedKvDecoder(InputStream in, Decryptor decryptor) { super(in); this.decryptor = decryptor; if (decryptor != null) { this.iv = new byte[decryptor.getIvLength()]; } }
@Override public InputStream createDecryptionStream(InputStream in, Context context, byte[] iv) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkState(context.getKey() != null, "Context does not have a key"); Preconditions.checkNotNull(iv); Decryptor d = getDecryptor(); d.setKey(context.getKey()); d.setIv(iv); return d.createDecryptionStream(in); }
@Override public InputStream createDecryptionStream(InputStream in, Decryptor decryptor) throws IOException { Preconditions.checkNotNull(decryptor); return decryptor.createDecryptionStream(in); }
public SecureWALCellCodec(Configuration conf, Decryptor decryptor) { super(conf, null); this.decryptor = decryptor; }
public static WALCellCodec getCodec(Configuration conf, Decryptor decryptor) { return new SecureWALCellCodec(conf, decryptor); }
@Override public Decryptor getDecryptor() { return new AESDecryptor(getJCECipherInstance()); }
@Override public InputStream createDecryptionStream(InputStream in, Decryptor d) throws IOException { Preconditions.checkNotNull(d); return d.createDecryptionStream(in); }
public EncryptedKvDecoder(InputStream in, Decryptor decryptor) { super(in); this.decryptor = decryptor; this.iv = new byte[decryptor.getIvLength()]; }
@Override public void prepareDecoding(int onDiskSizeWithoutHeader, int uncompressedSizeWithoutHeader, ByteBuffer blockBufferWithoutHeader, byte[] onDiskBlock, int offset) throws IOException { InputStream in = new DataInputStream(new ByteArrayInputStream(onDiskBlock, offset, onDiskSizeWithoutHeader)); Encryption.Context cryptoContext = fileContext.getEncryptionContext(); if (cryptoContext != Encryption.Context.NONE) { Cipher cipher = cryptoContext.getCipher(); Decryptor decryptor = cipher.getDecryptor(); decryptor.setKey(cryptoContext.getKey()); // Encrypted block format: // +--------------------------+ // | byte iv length | // +--------------------------+ // | iv data ... | // +--------------------------+ // | encrypted block data ... | // +--------------------------+ int ivLength = in.read(); if (ivLength > 0) { byte[] iv = new byte[ivLength]; IOUtils.readFully(in, iv); decryptor.setIv(iv); // All encrypted blocks will have a nonzero IV length. If we see an IV // length of zero, this means the encoding context had 0 bytes of // plaintext to encode. decryptor.reset(); in = decryptor.createDecryptionStream(in); } onDiskSizeWithoutHeader -= Bytes.SIZEOF_BYTE + ivLength; } Compression.Algorithm compression = fileContext.getCompression(); if (compression != Compression.Algorithm.NONE) { Compression.decompress(blockBufferWithoutHeader.array(), blockBufferWithoutHeader.arrayOffset(), in, onDiskSizeWithoutHeader, uncompressedSizeWithoutHeader, compression); } else { IOUtils.readFully(in, blockBufferWithoutHeader.array(), blockBufferWithoutHeader.arrayOffset(), onDiskSizeWithoutHeader); } }
@Override public Decryptor getDecryptor() { return new CommonsCryptoAESDecryptor(cipherMode, props); }