use of software.amazon.awssdk.services.kms.model.KmsException in project aws-doc-sdk-examples by awsdocs.
the class ListAliases method listAllAliases.
// snippet-start:[kms.java2_list_aliases.main]
public static void listAllAliases(KmsClient kmsClient) {
try {
ListAliasesRequest aliasesRequest = ListAliasesRequest.builder().limit(15).build();
ListAliasesResponse aliasesResponse = kmsClient.listAliases(aliasesRequest);
List<AliasListEntry> aliases = aliasesResponse.aliases();
for (AliasListEntry alias : aliases) {
System.out.println("The alias name is: " + alias.aliasName());
}
} catch (KmsException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.kms.model.KmsException in project aws-doc-sdk-examples by awsdocs.
the class ListKeys method listAllKeys.
// snippet-start:[kms.java2_list_keys.main]
public static void listAllKeys(KmsClient kmsClient) {
try {
ListKeysRequest listKeysRequest = ListKeysRequest.builder().limit(15).build();
ListKeysResponse keysResponse = kmsClient.listKeys(listKeysRequest);
List<KeyListEntry> keyListEntries = keysResponse.keys();
for (KeyListEntry key : keyListEntries) {
System.out.println("The key ARN is: " + key.keyArn());
System.out.println("The key Id is: " + key.keyId());
}
} catch (KmsException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.kms.model.KmsException in project aws-doc-sdk-examples by awsdocs.
the class DisableCustomerKey method disableKey.
// snippet-start:[kms.java2_disable_key.main]
public static void disableKey(KmsClient kmsClient, String keyId) {
try {
DisableKeyRequest keyRequest = DisableKeyRequest.builder().keyId(keyId).build();
kmsClient.disableKey(keyRequest);
} catch (KmsException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.kms.model.KmsException in project aws-doc-sdk-examples by awsdocs.
the class EncryptDataKey method encryptData.
// snippet-start:[kms.java2_encrypt_data.main]
public static SdkBytes encryptData(KmsClient kmsClient, String keyId) {
try {
SdkBytes myBytes = SdkBytes.fromByteArray(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
EncryptRequest encryptRequest = EncryptRequest.builder().keyId(keyId).plaintext(myBytes).build();
EncryptResponse response = kmsClient.encrypt(encryptRequest);
String algorithm = response.encryptionAlgorithm().toString();
System.out.println("The encryption algorithm is " + algorithm);
// Get the encrypted data.
SdkBytes encryptedData = response.ciphertextBlob();
return encryptedData;
} catch (KmsException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return null;
}
use of software.amazon.awssdk.services.kms.model.KmsException in project aws-doc-sdk-examples by awsdocs.
the class RevokeGrant method revokeKeyGrant.
// snippet-start:[kms.java2_revoke_grant.main]
public static void revokeKeyGrant(KmsClient kmsClient, String keyId, String grantId) {
try {
RevokeGrantRequest grantRequest = RevokeGrantRequest.builder().keyId(keyId).grantId(grantId).build();
kmsClient.revokeGrant(grantRequest);
} catch (KmsException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
Aggregations