Example usage for org.apache.hadoop.crypto CryptoCodec getInstance

List of usage examples for org.apache.hadoop.crypto CryptoCodec getInstance

Introduction

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

Prototype

public static CryptoCodec getInstance(Configuration conf, CipherSuite cipherSuite) 

Source Link

Document

Get crypto codec for specified algorithm/mode/padding.

Usage

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

License:Apache License

/**
 * Obtain a CryptoCodec based on the CipherSuite set in a FileEncryptionInfo
 * and the available CryptoCodecs configured in the Configuration.
 * /*  ww w.j ava2  s  .  co  m*/
 * @param conf
 *            Configuration
 * @param feInfo
 *            FileEncryptionInfo
 * @return CryptoCodec
 * @throws IOException
 *             if no suitable CryptoCodec for the CipherSuite is
 *             available.
 */
private static CryptoCodec getCryptoCodec(Configuration conf, FileEncryptionInfo feInfo) throws IOException {
    final CipherSuite suite = feInfo.getCipherSuite();
    if (suite.equals(CipherSuite.UNKNOWN)) {
        throw new IOException("NameNode specified unknown CipherSuite with ID " + suite.getUnknownValue()
                + ", cannot instantiate CryptoCodec.");
    }
    final CryptoCodec codec = CryptoCodec.getInstance(conf, suite);
    if (codec == null) {
        throw new UnknownCipherSuiteException("No configuration found for the cipher suite "
                + suite.getConfigSuffix() + " prefixed with " + HADOOP_SECURITY_CRYPTO_CODEC_CLASSES_KEY_PREFIX
                + ". Please see the example configuration "
                + "hadoop.security.crypto.codec.classes.EXAMPLECIPHERSUITE "
                + "at core-default.xml for details.");
    }
    return codec;
}