Example usage for org.apache.hadoop.crypto CryptoInputStream CryptoInputStream

List of usage examples for org.apache.hadoop.crypto CryptoInputStream CryptoInputStream

Introduction

In this page you can find the example usage for org.apache.hadoop.crypto CryptoInputStream CryptoInputStream.

Prototype

public CryptoInputStream(InputStream in, CryptoCodec codec, byte[] key, byte[] iv) throws IOException 

Source Link

Usage

From source file:com.mellanox.r4h.DFSClient.java

License:Apache License

/**
 * Wraps the stream in a CryptoInputStream if the underlying file is
 * encrypted./*from  www.j  a  va 2  s .  co  m*/
 */
public HdfsDataInputStream createWrappedInputStream(DFSInputStream dfsis) throws IOException {
    final FileEncryptionInfo feInfo = dfsis.getFileEncryptionInfo();
    if (feInfo != null) {
        // File is encrypted, wrap the stream in a crypto stream.
        // Currently only one version, so no special logic based on the version #
        getCryptoProtocolVersion(feInfo);
        final CryptoCodec codec = getCryptoCodec(conf, feInfo);
        final KeyVersion decrypted = decryptEncryptedDataEncryptionKey(feInfo);
        final CryptoInputStream cryptoIn = new CryptoInputStream(dfsis, codec, decrypted.getMaterial(),
                feInfo.getIV());
        return new HdfsDataInputStream(cryptoIn);
    } else {
        // No FileEncryptionInfo so no encryption.
        return new HdfsDataInputStream(dfsis);
    }
}