Class VaultTransitSecretEngine

java.lang.Object
io.quarkus.vault.VaultTransitSecretEngine

@ApplicationScoped public class VaultTransitSecretEngine extends Object
A service that interacts with Hashicorp's Vault Transit secret engine to encrypt, decrypt and sign arbitrary data.
See Also:
  • Constructor Details

  • Method Details

    • encrypt

      public String encrypt(String keyName, String clearData)
      Encrypt a regular string with a Vault key configured in the transit secret engine. Equivalent to: encrypt(keyName, ClearData.from(clearData), null);

      This method is usually used in conjunction with decrypt(String, String)

      Parameters:
      keyName - the key to encrypt the data with
      clearData - the string to encrypt
      Returns:
      cipher text
      See Also:
    • encrypt

      public String encrypt(String keyName, ClearData clearData, TransitContext transitContext)
      Encrypt a regular string with a Vault key configured in the transit secret engine. If the key does not exist, and the policy specifies a create capability the key will be lazily created (i.e. upsert). The key can be further customized by specifying transit encryption-key configuration properties.
      Parameters:
      keyName - the key to encrypt the data with
      clearData - the data to encrypt
      transitContext - optional transit context used for key derivation
      Returns:
      cipher text
      See Also:
    • encrypt

      public Map<EncryptionRequest,String> encrypt(String keyName, List<EncryptionRequest> requests)
      Encrypt a list of elements. This will return a list of cipher texts. Each element shall specify the data to encrypt, an optional key version and an optional transit context, used for key derivation if applicable. If any error occurs, the service will throw a VaultEncryptionBatchException
      Parameters:
      keyName - the key to encrypt the data with
      requests - the list of elements to encrypt
      Returns:
      a map of each request and its corresponding cipher text
      See Also:
    • decrypt

      public ClearData decrypt(String keyName, String ciphertext)
      Decrypt the encrypted data with the specified key, and return unencrypted data.
      Parameters:
      keyName - the key that was used to encrypt the original data
      ciphertext - the encrypted data
      Returns:
      the unencrypted data
      See Also:
    • decrypt

      public ClearData decrypt(String keyName, String ciphertext, TransitContext transitContext)
      Decrypt the encrypted data with the specified key and a transit context used for key derivation.
      Parameters:
      keyName - the key that was used to encrypt the original data
      ciphertext - data to decrypt
      transitContext - optional transit context used for key derivation
      Returns:
      the unencrypted data
      See Also:
    • decrypt

      public Map<DecryptionRequest,ClearData> decrypt(String keyName, List<DecryptionRequest> requests)
      Decrypt a list of encrypted data items. Each item shall specify the encrypted data plus an optional transit context used for key derivation (if applicable). If any error occurs, the service will throw a VaultDecryptionBatchException
      Parameters:
      keyName - the key that was used to encrypt the original data
      requests - the list of encrypted data items
      Returns:
      a map of each request with its corresponding decrypted data item
      See Also:
    • rewrap

      public String rewrap(String keyName, String ciphertext)
      Reencrypt into a new cipher text a cipher text that was obtained from encryption using an old key version with the last key version
      Parameters:
      keyName - the encryption key that was used for the previous encryption
      ciphertext - the old cipher text that needs rewrapping
      Returns:
      the reencrypted cipher text with last key version as a new cipher text
      See Also:
    • rewrap

      public String rewrap(String keyName, String ciphertext, TransitContext transitContext)
      Reencrypt into a new cipher text a cipher text that was obtained from encryption using an old key version with the last key version and an optional transit context used for key derivation
      Parameters:
      keyName - the encryption key that was used for the previous encryption
      ciphertext - the old cipher text that needs rewrapping
      transitContext - optional transit context used for key derivation
      Returns:
      the reencrypted cipher text with last key version as a new cipher text
      See Also:
    • rewrap

      public Map<RewrappingRequest,String> rewrap(String keyName, List<RewrappingRequest> requests)
      Reencrypt a list of encrypted data items with the last version of the specified key. Each item shall specify a cipher text to reencrypt, an optional key version, and an optional transit context used for key derivation, if applicable. If any error occurs, the service will throw a VaultRewrappingBatchException
      Parameters:
      keyName - the encryption key that was used for the previous encryptions
      requests - the list of items to reencrypt
      Returns:
      a map of each request with its corresponding reencrypted data item
      See Also:
    • sign

      public String sign(String keyName, String input)
      Sign an input string with the specified key.
      Parameters:
      keyName - the signing key to use
      input - String to sign
      Returns:
      the signature
      See Also:
    • sign

      public String sign(String keyName, SigningInput input, TransitContext transitContext)
      Sign the input with the specified key and an optional transit context used for key derivation, if applicable.
      Parameters:
      keyName - the signing key to use
      input - data to sign
      transitContext - optional transit context used for key derivation
      Returns:
      the signature
      See Also:
    • sign

      public String sign(String keyName, SigningInput input, SignVerifyOptions options, TransitContext transitContext)
      Sign the input with the specified key and an optional explicit sign/verify options and an optional transit context used for key derivation, if applicable.
      Parameters:
      keyName - the signing key to use
      input - data to sign
      options - optional explicit sign/verify options
      transitContext - optional transit context used for key derivation
      Returns:
      the signature
      See Also:
    • sign

      public Map<SigningRequest,String> sign(String keyName, List<SigningRequest> requests)
      Sign a list of inputs items. Each item shall specify the input to sign, an optional key version, and an optional transit context used for key derivation, if applicable. If any error occurs, the service will throw a VaultSigningBatchException
      Parameters:
      keyName - the signing key to use
      requests - the list of inputs to sign
      Returns:
      a map of each request with its corresponding signature item
      See Also:
    • sign

      public Map<SigningRequest,String> sign(String keyName, List<SigningRequest> requests, SignVerifyOptions options)
      Sign a list of inputs items and an optional explicit sign/verify options. Each item shall specify the input to sign, an optional key version, and an optional transit context used for key derivation, if applicable. If any error occurs, the service will throw a VaultSigningBatchException
      Parameters:
      keyName - the signing key to use
      requests - the list of inputs to sign
      options - optional explicit sign/verify options
      Returns:
      a map of each request with its corresponding signature item
      See Also:
    • verifySignature

      public void verifySignature(String keyName, String signature, String input)
      Checks that the signature was obtained from signing the input with the specified key. The service will throw a VaultException if this is not the case.
      Parameters:
      keyName - the key that was used to sign the input
      signature - the signature obtained from one of the sign methods
      input - the original input data
      See Also:
    • verifySignature

      public void verifySignature(String keyName, String signature, SigningInput input, TransitContext transitContext)
      Checks that the signature was obtained from signing the input with the specified key. The service will throw a VaultException if this is not the case.
      Parameters:
      keyName - the key that was used to sign the input
      signature - the signature obtained from one of the sign methods
      input - the original input data
      transitContext - optional transit context used for key derivation
      See Also:
    • verifySignature

      public void verifySignature(String keyName, String signature, SigningInput input, SignVerifyOptions options, TransitContext transitContext)
      Checks that the signature was obtained from signing the input with the specified key an an optional explicit sign/verify options. The service will throw a VaultException if this is not the case.
      Parameters:
      keyName - the key that was used to sign the input
      signature - the signature obtained from one of the sign methods
      input - the original input data
      options - optional explicit sign/verify options
      transitContext - optional transit context used for key derivation
      See Also:
    • verifySignature

      public void verifySignature(String keyName, List<VerificationRequest> requests)
      Checks a list of verification requests. Each request shall specify an input and the signature we want to match against, and an optional transit context used for key derivation, if applicable. If the signature does not match, or if any other error occurs, the service will throw a VaultVerificationBatchException
      Parameters:
      keyName - the key that was used to sign the input
      requests - a list of items specifying an input and a signature to match against
      See Also:
    • verifySignature

      public void verifySignature(String keyName, List<VerificationRequest> requests, SignVerifyOptions options)
      Checks a list of verification requests. Each request shall specify an input and the signature we want to match against, and an optional explicit sign/verify options and an optionals transit context used for key derivation, if applicable. If the signature does not match, or if any other error occurs, the service will throw a VaultVerificationBatchException
      Parameters:
      keyName - the key that was used to sign the input
      requests - a list of items specifying an input and a signature to match against
      options - optional explicit sign/verify options
      See Also:
    • createKey

      public void createKey(String keyName, KeyCreationRequestDetail detail)
      Create a new Transit key.
      Parameters:
      keyName - key name
      detail - key creation detail or null
      See Also:
    • updateKeyConfiguration

      public void updateKeyConfiguration(String keyName, KeyConfigRequestDetail detail)
      Update the configuration of a Transit key. The key must exist.
      Parameters:
      keyName - key name
      detail - key configuration detail
      See Also:
    • rotateKey

      public void rotateKey(String keyName)
      This endpoint rotates the version of the named key. After rotation, new plaintext requests will be encrypted with the new version of the key.
      Parameters:
      keyName - the key name
      See Also:
    • deleteKey

      public void deleteKey(String keyName)
      Delete a Transit key. Key must have been configured with deletion allowed. The key must exist.
      Parameters:
      keyName - key name
      See Also:
    • exportKey

      public VaultTransitKeyExportDetail exportKey(String keyName, VaultTransitExportKeyType keyType, String keyVersion)
      Export a Transit Key. Key must have made exportable through creation or configuration update. The key must exist.
      Parameters:
      keyName - name of the key
      keyType - key type
      keyVersion - null, "latest" or a valid version number as a String. If null all versions will be returned
      Returns:
      All specified key versions
      See Also:
    • readKey

      public Optional<VaultTransitKeyDetail<?>> readKey(String keyName)
      Read the configuration of a Transit key.
      Parameters:
      keyName - key name
      Returns:
      key detail, or null if the key does not exist
      See Also:
    • listKeys

      public List<String> listKeys()
      List all Transit keys.
      Returns:
      key names
      See Also:
    • generateDataKey

      public VaultTransitDataKey generateDataKey(VaultTransitDataKeyType type, String keyName, VaultTransitDataKeyRequestDetail detail)
      Create a data key
      Parameters:
      type - plaintext or wrapped
      keyName - the key name
      detail - optional context, nonce and bits
      Returns:
      the generated data key
      See Also: