Package org.forgerock.secrets.vault
Class VaultCipher
- java.lang.Object
-
- javax.crypto.CipherSpi
-
- org.forgerock.secrets.vault.VaultCipher
-
public class VaultCipher extends CipherSpi
Cipher implementation for the Hashicorp Vault transit backend. Supports AES-GCM and ChaCha20-Poly1305 authenticated encryption ciphers and RSA encryption with OAEP padding. While the RSA encryption is compatible with JOSERSA-OAEP-256
encryption, the symmetric encryption algorithms are not compatible with JOSE as they lack support for additional authenticated data. Instead the primary use-case for symmetric encryption with Vault would be to decrypt other secrets that are then used locally, such as keystore passwords read from the filesystem.
-
-
Field Summary
Fields Modifier and Type Field Description static OAEPParameterSpec
RSA_OAEP_PARAMETERS
Vault only supports RSA encryption using OAEP and these specific parameters.
-
Constructor Summary
Constructors Constructor Description VaultCipher()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected byte[]
engineDoFinal(byte[] input, int inputOffset, int inputLen)
protected int
engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
protected int
engineGetBlockSize()
protected byte[]
engineGetIV()
protected int
engineGetKeySize(Key key)
protected int
engineGetOutputSize(int inputLen)
protected AlgorithmParameters
engineGetParameters()
protected void
engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random)
protected void
engineInit(int opmode, Key key, SecureRandom random)
protected void
engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random)
protected void
engineSetMode(String mode)
protected void
engineSetPadding(String padding)
protected Key
engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType)
protected byte[]
engineUpdate(byte[] input, int inputOffset, int inputLen)
protected int
engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
protected byte[]
engineWrap(Key key)
-
Methods inherited from class javax.crypto.CipherSpi
engineDoFinal, engineUpdate, engineUpdateAAD, engineUpdateAAD
-
-
-
-
Field Detail
-
RSA_OAEP_PARAMETERS
public static final OAEPParameterSpec RSA_OAEP_PARAMETERS
Vault only supports RSA encryption using OAEP and these specific parameters. These are the same parameters used for JOSERSA-OAEP-256
encryption. When encrypting data using Java's built-in encryption capabilities, you should pass these parameters explicitly to ensure compatibility with Vault.
-
-
Method Detail
-
engineSetMode
protected void engineSetMode(String mode)
- Specified by:
engineSetMode
in classCipherSpi
-
engineSetPadding
protected void engineSetPadding(String padding)
- Specified by:
engineSetPadding
in classCipherSpi
-
engineGetBlockSize
protected int engineGetBlockSize()
- Specified by:
engineGetBlockSize
in classCipherSpi
-
engineGetOutputSize
protected int engineGetOutputSize(int inputLen)
- Specified by:
engineGetOutputSize
in classCipherSpi
-
engineGetIV
protected byte[] engineGetIV()
- Specified by:
engineGetIV
in classCipherSpi
-
engineGetParameters
protected AlgorithmParameters engineGetParameters()
- Specified by:
engineGetParameters
in classCipherSpi
-
engineInit
protected void engineInit(int opmode, Key key, SecureRandom random) throws InvalidKeyException
- Specified by:
engineInit
in classCipherSpi
- Throws:
InvalidKeyException
-
engineInit
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException
- Specified by:
engineInit
in classCipherSpi
- Throws:
InvalidKeyException
InvalidAlgorithmParameterException
-
engineInit
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException
- Specified by:
engineInit
in classCipherSpi
- Throws:
InvalidKeyException
InvalidAlgorithmParameterException
-
engineUpdate
protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen)
- Specified by:
engineUpdate
in classCipherSpi
-
engineUpdate
protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
- Specified by:
engineUpdate
in classCipherSpi
-
engineDoFinal
protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) throws BadPaddingException
- Specified by:
engineDoFinal
in classCipherSpi
- Throws:
BadPaddingException
-
engineDoFinal
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException, BadPaddingException
- Specified by:
engineDoFinal
in classCipherSpi
- Throws:
ShortBufferException
BadPaddingException
-
engineWrap
protected byte[] engineWrap(Key key) throws IllegalBlockSizeException
- Overrides:
engineWrap
in classCipherSpi
- Throws:
IllegalBlockSizeException
-
engineUnwrap
protected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException
- Overrides:
engineUnwrap
in classCipherSpi
- Throws:
InvalidKeyException
-
engineGetKeySize
protected int engineGetKeySize(Key key) throws InvalidKeyException
- Overrides:
engineGetKeySize
in classCipherSpi
- Throws:
InvalidKeyException
-
-