Example usage for org.apache.hadoop.crypto.key KeyProviderCryptoExtension decryptEncryptedKey

List of usage examples for org.apache.hadoop.crypto.key KeyProviderCryptoExtension decryptEncryptedKey

Introduction

In this page you can find the example usage for org.apache.hadoop.crypto.key KeyProviderCryptoExtension decryptEncryptedKey.

Prototype

public KeyVersion decryptEncryptedKey(EncryptedKeyVersion encryptedKey)
        throws IOException, GeneralSecurityException 

Source Link

Document

Decrypts an encrypted byte[] key material using the given a key version name and initialization vector.

Usage

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

License:Apache License

/**
 * Decrypts a EDEK by consulting the KeyProvider.
 *//*from  w  ww .j a v a  2s.c  om*/
private KeyVersion decryptEncryptedDataEncryptionKey(FileEncryptionInfo feInfo) throws IOException {
    TraceScope scope = Trace.startSpan("decryptEDEK", traceSampler);
    try {
        KeyProvider provider = getKeyProvider();
        if (provider == null) {
            throw new IOException("No KeyProvider is configured, cannot access" + " an encrypted file");
        }
        EncryptedKeyVersion ekv = EncryptedKeyVersion.createForDecryption(feInfo.getKeyName(),
                feInfo.getEzKeyVersionName(), feInfo.getIV(), feInfo.getEncryptedDataEncryptionKey());
        try {
            KeyProviderCryptoExtension cryptoProvider = KeyProviderCryptoExtension
                    .createKeyProviderCryptoExtension(provider);
            return cryptoProvider.decryptEncryptedKey(ekv);
        } catch (GeneralSecurityException e) {
            throw new IOException(e);
        }
    } finally {
        scope.close();
    }
}