Search in sources :

Example 6 with KmsException

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);
    }
}
Also used : AliasListEntry(software.amazon.awssdk.services.kms.model.AliasListEntry) KmsException(software.amazon.awssdk.services.kms.model.KmsException) ListAliasesRequest(software.amazon.awssdk.services.kms.model.ListAliasesRequest) ListAliasesResponse(software.amazon.awssdk.services.kms.model.ListAliasesResponse)

Example 7 with KmsException

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);
    }
}
Also used : KeyListEntry(software.amazon.awssdk.services.kms.model.KeyListEntry) KmsException(software.amazon.awssdk.services.kms.model.KmsException) ListKeysRequest(software.amazon.awssdk.services.kms.model.ListKeysRequest) ListKeysResponse(software.amazon.awssdk.services.kms.model.ListKeysResponse)

Example 8 with KmsException

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);
    }
}
Also used : DisableKeyRequest(software.amazon.awssdk.services.kms.model.DisableKeyRequest) KmsException(software.amazon.awssdk.services.kms.model.KmsException)

Example 9 with KmsException

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;
}
Also used : SdkBytes(software.amazon.awssdk.core.SdkBytes) EncryptResponse(software.amazon.awssdk.services.kms.model.EncryptResponse) KmsException(software.amazon.awssdk.services.kms.model.KmsException) EncryptRequest(software.amazon.awssdk.services.kms.model.EncryptRequest)

Example 10 with KmsException

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);
    }
}
Also used : RevokeGrantRequest(software.amazon.awssdk.services.kms.model.RevokeGrantRequest) KmsException(software.amazon.awssdk.services.kms.model.KmsException)

Aggregations

KmsException (software.amazon.awssdk.services.kms.model.KmsException)16 SdkBytes (software.amazon.awssdk.core.SdkBytes)3 KmsClient (software.amazon.awssdk.services.kms.KmsClient)2 DecryptRequest (software.amazon.awssdk.services.kms.model.DecryptRequest)2 DecryptResponse (software.amazon.awssdk.services.kms.model.DecryptResponse)2 EncryptRequest (software.amazon.awssdk.services.kms.model.EncryptRequest)2 EncryptResponse (software.amazon.awssdk.services.kms.model.EncryptResponse)2 AliasListEntry (software.amazon.awssdk.services.kms.model.AliasListEntry)1 CreateAliasRequest (software.amazon.awssdk.services.kms.model.CreateAliasRequest)1 CreateGrantRequest (software.amazon.awssdk.services.kms.model.CreateGrantRequest)1 CreateGrantResponse (software.amazon.awssdk.services.kms.model.CreateGrantResponse)1 CreateKeyRequest (software.amazon.awssdk.services.kms.model.CreateKeyRequest)1 CreateKeyResponse (software.amazon.awssdk.services.kms.model.CreateKeyResponse)1 DeleteAliasRequest (software.amazon.awssdk.services.kms.model.DeleteAliasRequest)1 DescribeKeyRequest (software.amazon.awssdk.services.kms.model.DescribeKeyRequest)1 DescribeKeyResponse (software.amazon.awssdk.services.kms.model.DescribeKeyResponse)1 DisableKeyRequest (software.amazon.awssdk.services.kms.model.DisableKeyRequest)1 EnableKeyRequest (software.amazon.awssdk.services.kms.model.EnableKeyRequest)1 GrantListEntry (software.amazon.awssdk.services.kms.model.GrantListEntry)1 KeyListEntry (software.amazon.awssdk.services.kms.model.KeyListEntry)1