Class KmsClient
java.lang.Object
com.salesforce.multicloudj.kms.client.KmsClient
- All Implemented Interfaces:
AutoCloseable
Entry point for client code to manage keys in a cloud key management service in a
substrate-agnostic way.
Usage example:
KmsClient client = KmsClient.builder(providerId)
.withRegion(region)
.withKeyContainer(keyContainer)
.build();
CreateKeyResponse created = client.createKey(CreateKeyRequest.builder()
.keyName("orders-root-key")
.description("Root key for order data")
.build());
client.tagKey(created.getKeyRef(), Map.of("team", "orders"));
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for KmsClient. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic KmsClient.KmsClientBuilderCreates a new KmsClientBuilder for the specified provider.voidclose()createKey(CreateKeyRequest request) Creates a symmetric key.decrypt(DecryptRequest request) Decrypts a ciphertext produced byencrypt(com.salesforce.multicloudj.kms.model.EncryptRequest).voiddisableKey(KeyRef keyRef) Disables a key.voidEnables a key.encrypt(EncryptRequest request) Encrypts a small payload directly with a key.Starts an import session for a key created with external origin.getKeyPolicy(KeyRef keyRef) Reads the access policy attached to a key.Describes the subset of theKeyPolicymodel the provider enforces.Imports wrapped key material into a key created with external origin.voidsetKeyPolicy(KeyRef keyRef, KeyPolicy policy) Replaces the access policy attached to a key.booleanWhether this client can create keys withCreateKeyRequest.multiRegionset.voidAdds or overwrites tags on a key.
-
Field Details
-
kms
-
-
Constructor Details
-
KmsClient
-
-
Method Details
-
builder
Creates a new KmsClientBuilder for the specified provider.- Parameters:
providerId- the ID of the provider such as "aws", "gcp", or "ali"- Returns:
- a new KmsClientBuilder instance
-
createKey
Creates a symmetric key.- Parameters:
request- the key's configuration- Returns:
- a reference to the new key and its initial state
- Throws:
SubstrateSdkException- if the operation fails
-
enableKey
Enables a key. WhenKeyRef.getVersionId()is set, providers that keep state per version enable only that version; the others enable the whole key.- Parameters:
keyRef- the key to enable- Throws:
SubstrateSdkException- if the operation fails
-
disableKey
Disables a key. WhenKeyRef.getVersionId()is set, providers that keep state per version disable only that version; the others disable the whole key.- Parameters:
keyRef- the key to disable- Throws:
SubstrateSdkException- if the operation fails
-
getImportParameters
Starts an import session for a key created with external origin.- Parameters:
request- the key and the wrapping configuration- Returns:
- the public key and token to use with
importKeyMaterial(com.salesforce.multicloudj.kms.model.ImportKeyMaterialRequest) - Throws:
SubstrateSdkException- if the operation fails
-
importKeyMaterial
Imports wrapped key material into a key created with external origin.- Parameters:
request- the key, import token and wrapped material- Returns:
- a reference to the key, including the version created for the material where the provider versions keys
- Throws:
SubstrateSdkException- if the operation fails
-
setKeyPolicy
Replaces the access policy attached to a key.- Parameters:
keyRef- the key whose policy is replacedpolicy- the new policy- Throws:
SubstrateSdkException- if the operation fails, includingUnSupportedOperationExceptionwhen the policy uses anything outsidegetPolicyCapabilities()
-
getKeyPolicy
Reads the access policy attached to a key. Native policy entries that theKeyPolicymodel cannot express are omitted.- Parameters:
keyRef- the key whose policy is read- Returns:
- the key's policy
- Throws:
SubstrateSdkException- if the operation fails
-
tagKey
Adds or overwrites tags on a key. Existing tags with other names are kept.- Parameters:
keyRef- the key to tagtags- tag names and values- Throws:
SubstrateSdkException- if the operation fails
-
encrypt
Encrypts a small payload directly with a key.- Parameters:
request- the key, plaintext and encryption context- Returns:
- the ciphertext
- Throws:
SubstrateSdkException- if the operation fails
-
decrypt
Decrypts a ciphertext produced byencrypt(com.salesforce.multicloudj.kms.model.EncryptRequest).- Parameters:
request- the ciphertext and encryption context- Returns:
- the plaintext
- Throws:
SubstrateSdkException- if the operation fails
-
getPolicyCapabilities
Describes the subset of theKeyPolicymodel the provider enforces.- Returns:
- the provider's policy capabilities
-
supportsMultiRegionKeys
public boolean supportsMultiRegionKeys()Whether this client can create keys withCreateKeyRequest.multiRegionset.- Returns:
- true if multi-region keys can be created
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-