Package org.apache.orc
Class InMemoryKeystore
java.lang.Object
org.apache.orc.InMemoryKeystore
- All Implemented Interfaces:
KeyProvider
This is an in-memory implementation of
KeyProvider
.
The primary use of this class is for when the user doesn't have a Hadoop KMS running and wishes to use encryption. It is also useful for testing.
The local keys for this class are encrypted/decrypted using the cipher in CBC/NoPadding mode and a constant IV. Since the key is random, the constant IV is not a problem.
This class is not thread safe.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.orc.impl.KeyProvider
KeyProvider.Factory
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreate a new InMemoryKeystore.InMemoryKeystore
(Random random) Create an InMemoryKeystore with the given random generator. -
Method Summary
Modifier and TypeMethodDescriptionaddKey
(String keyName, int version, EncryptionAlgorithm algorithm, byte[] masterKey) Function that takes care of adding a new key.
A new key can be added only if: This is a new key and no prior key version exist. If the key exists (has versions), then the new version to be added should be greater than the version that already exists.addKey
(String keyName, EncryptionAlgorithm algorithm, byte[] masterKey) Function that takes care of adding a new key.
A new key can be added only if: This is a new key and no prior key version exist. If the key exists (has versions), then the new version to be added should be greater than the version that already exists.Create a local key for the given key version.decryptLocalKey
(HadoopShims.KeyMetadata key, byte[] encryptedKey) Create a local key for the given key version and initialization vector.getCurrentKeyVersion
(String keyName) Get the current metadata for a given key.Get the list of key names from the key provider.getKind()
-
Field Details
-
SUPPORTS_AES_256
public static final boolean SUPPORTS_AES_256Support AES 256 ?
-
-
Constructor Details
-
InMemoryKeystore
public InMemoryKeystore()Create a new InMemoryKeystore. -
InMemoryKeystore
Create an InMemoryKeystore with the given random generator. Except for testing, this must be a SecureRandom.
-
-
Method Details
-
getKeyNames
Get the list of key names from the key provider.- Specified by:
getKeyNames
in interfaceKeyProvider
- Returns:
- a list of key names
-
getCurrentKeyVersion
Get the current metadata for a given key. This is used when encrypting new data.- Specified by:
getCurrentKeyVersion
in interfaceKeyProvider
- Parameters:
keyName
- the name of a key- Returns:
- metadata for the current version of the key
-
createLocalKey
Create a local key for the given key version.- Specified by:
createLocalKey
in interfaceKeyProvider
- Parameters:
key
- the master key version- Returns:
- the local key's material
-
decryptLocalKey
Create a local key for the given key version and initialization vector. Given a probabilistically unique iv, it will generate a unique key with the master key at the specified version. This allows the encryption to use this local key for the encryption and decryption without ever having access to the master key.This uses KeyProviderCryptoExtension.decryptEncryptedKey with a fixed key of the appropriate length.
- Specified by:
decryptLocalKey
in interfaceKeyProvider
- Parameters:
key
- the master key versionencryptedKey
- the unique initialization vector- Returns:
- the local key's material
-
getKind
- Specified by:
getKind
in interfaceKeyProvider
-
addKey
public InMemoryKeystore addKey(String keyName, EncryptionAlgorithm algorithm, byte[] masterKey) throws IOException Function that takes care of adding a new key.
A new key can be added only if:- This is a new key and no prior key version exist.
- If the key exists (has versions), then the new version to be added should be greater than the version that already exists.
- Parameters:
keyName
- Name of the key to be addedalgorithm
- Algorithm usedmasterKey
- Master key- Returns:
- this
- Throws:
IOException
-
addKey
public InMemoryKeystore addKey(String keyName, int version, EncryptionAlgorithm algorithm, byte[] masterKey) throws IOException Function that takes care of adding a new key.
A new key can be added only if:- This is a new key and no prior key version exist.
- If the key exists (has versions), then the new version to be added should be greater than the version that already exists.
- Parameters:
keyName
- Name of the key to be addedversion
- Key Versionalgorithm
- Algorithm usedmasterKey
- Master key- Returns:
- this
- Throws:
IOException
-