Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Provides AWS Key Management Service (KMS) patterns using AWS SDK for Java 2.x. Use when creating/managing encryption keys, encrypting/decrypting data, generating data keys, digital signing, key rotation, or integrating encryption into Spring Boot applications.
.claude/skills/giuseppe-trisciuoglio-aws-sdk-java-v2-kms/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 67% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 138% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 99% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 282% | 0% |
| case-05 | ✓→✓ | = Same ✓ | 207% | 0% |
Provides AWS KMS patterns using AWS SDK for Java 2.x. Covers key management, encryption/decryption, envelope encryption, digital signatures, and Spring Boot integration.
xml<dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>kms</artifactId> </dependency>
groovyimplementation 'software.amazon.awssdk:kms:2.x.x'
javaimport software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.kms.KmsClient; KmsClient kmsClient = KmsClient.builder() .region(Region.US_EAST_1) .build();
javaimport software.amazon.awssdk.services.kms.KmsAsyncClient; KmsAsyncClient kmsAsyncClient = KmsAsyncClient.builder() .region(Region.US_EAST_1) .build();
javaKmsClient kmsClient = KmsClient.builder() .region(Region.of(System.getenv("AWS_REGION"))) .credentialsProvider(DefaultCredentialsProvider.create()) .overrideConfiguration(c -> c.retryPolicy(RetryPolicy.builder() .numRetries(3) .build())) .build();
javapublic String createEncryptionKey(KmsClient kmsClient, String description) { CreateKeyRequest request = CreateKeyRequest.builder() .description(description) .keyUsage(KeyUsageType.ENCRYPT_DECRYPT) .build(); CreateKeyResponse response = kmsClient.createKey(request); return response.keyMetadata().keyId(); }
javapublic KeyMetadata getKeyMetadata(KmsClient kmsClient, String keyId) { DescribeKeyRequest request = DescribeKeyRequest.builder() .keyId(keyId) .build(); return kmsClient.describeKey(request).keyMetadata(); }
javapublic void toggleKeyState(KmsClient kmsClient, String keyId, boolean enable) { if (enable) { kmsClient.enableKey(EnableKeyRequest.builder().keyId(keyId).build()); } else { kmsClient.disableKey(DisableKeyRequest.builder().keyId(keyId).build()); } }
javapublic String encryptData(KmsClient kmsClient, String keyId, String plaintext) { SdkBytes plaintextBytes = SdkBytes.fromString(plaintext, StandardCharsets.UTF_8); EncryptRequest request = EncryptRequest.builder() .keyId(keyId) .plaintext(plaintextBytes) .build(); EncryptResponse response = kmsClient.encrypt(request); return Base64.getEncoder().encodeToString( response.ciphertextBlob().asByteArray()); }
javapublic String decryptData(KmsClient kmsClient, String ciphertextBase64) { byte[] ciphertext = Base64.getDecoder().decode(ciphertextBase64); SdkBytes ciphertextBytes = SdkBytes.fromByteArray(ciphertext); DecryptRequest request = DecryptRequest.builder() .ciphertextBlob(ciphertextBytes) .build(); DecryptResponse response = kmsClient.decrypt(request); return response.plaintext().asString(StandardCharsets.UTF_8); }
javapublic DataKeyResult encryptWithEnvelope(KmsClient kmsClient, String masterKeyId, byte[] data) { try { GenerateDataKeyRequest keyRequest = GenerateDataKeyRequest.builder() .keyId(masterKeyId) .keySpec(DataKeySpec.AES_256) .build(); GenerateDataKeyResponse keyResponse = kmsClient.generateDataKey(keyRequest); // Validate response if (keyResponse.plaintext() == null || keyResponse.ciphertextBlob() == null) { throw new IllegalStateException("Data key generation returned null"); } byte[] encryptedData = encryptWithAES(data, keyResponse.plaintext().asByteArray()); // Clear plaintext key from memory Arrays.fill(keyResponse.plaintext().asByteArray(), (byte) 0); return new DataKeyResult(encryptedData, keyResponse.ciphertextBlob().asByteArray()); } catch (KmsException e) { throw new RuntimeException("Envelope encryption failed: " + e.awsErrorDetails().errorCode(), e); } } public byte[] decryptWithEnvelope(KmsClient kmsClient, DataKeyResult encryptedEnvelope) { try { DecryptRequest keyDecryptRequest = DecryptRequest.builder() .ciphertextBlob(SdkBytes.fromByteArray(encryptedEnvelope.encryptedKey())) .build(); DecryptResponse keyDecryptResponse = kmsClient.decrypt(keyDecryptRequest); // Validate response if (keyDecryptResponse.plaintext() == null) { throw new IllegalStateException("Key decryption returned null"); } byte[] decryptedData = decryptWithAES( encryptedEnvelope.encryptedData(), keyDecryptResponse.plaintext().asByteArray()); // Clear plaintext key from memory Arrays.fill(keyDecryptResponse.plaintext().asByteArray(), (byte) 0); return decryptedData; } catch (KmsException e) { throw new RuntimeException("Envelope decryption failed: " + e.awsErrorDetails().errorCode(), e); } }
javapublic String createAndSignData(KmsClient kmsClient, String description, String message) { // Create signing key CreateKeyRequest keyRequest = CreateKeyRequest.builder() .description(description) .keySpec(KeySpec.RSA_2048) .keyUsage(KeyUsageType.SIGN_VERIFY) .build(); CreateKeyResponse keyResponse = kmsClient.createKey(keyRequest); String keyId = keyResponse.keyMetadata().keyId(); // Sign data SignRequest signRequest = SignRequest.builder() .keyId(keyId) .message(SdkBytes.fromString(message, StandardCharsets.UTF_8)) .signingAlgorithm(SigningAlgorithmSpec.RSASSA_PSS_SHA_256) .build(); SignResponse signResponse = kmsClient.sign(signRequest); return Base64.getEncoder().encodeToString( signResponse.signature().asByteArray()); }
javapublic boolean verifySignature(KmsClient kmsClient, String keyId, String message, String signatureBase64) { byte[] signature = Base64.getDecoder().decode(signatureBase64); VerifyRequest verifyRequest = VerifyRequest.builder() .keyId(keyId) .message(SdkBytes.fromString(message, StandardCharsets.UTF_8)) .signature(SdkBytes.fromByteArray(signature)) .signingAlgorithm(SigningAlgorithmSpec.RSASSA_PSS_SHA_256) .build(); VerifyResponse verifyResponse = kmsClient.verify(verifyRequest); return verifyResponse.signatureValid(); }
java@Configuration public class KmsConfiguration { @Bean public KmsClient kmsClient() { return KmsClient.builder() .region(Region.US_EAST_1) .build(); } @Bean public KmsAsyncClient kmsAsyncClient() { return KmsAsyncClient.builder() .region(Region.US_EAST_1) .build(); } }
java@Service @RequiredArgsConstructor public class KmsEncryptionService { private final KmsClient kmsClient; @Value("${kms.encryption-key-id}") private String keyId; public String encrypt(String plaintext) { try { EncryptRequest request = EncryptRequest.builder() .keyId(keyId) .plaintext(SdkBytes.fromString(plaintext, StandardCharsets.UTF_8)) .build(); EncryptResponse response = kmsClient.encrypt(request); return Base64.getEncoder().encodeToString( response.ciphertextBlob().asByteArray()); } catch (KmsException e) { throw new RuntimeException("Encryption failed", e); } } public String decrypt(String ciphertextBase64) { try { byte[] ciphertext = Base64.getDecoder().decode(ciphertextBase64); DecryptRequest request = DecryptRequest.builder() .ciphertextBlob(SdkBytes.fromByteArray(ciphertext)) .build(); DecryptResponse response = kmsClient.decrypt(request); return response.plaintext().asString(StandardCharsets.UTF_8); } catch (KmsException e) { throw new RuntimeException("Decryption failed", e); } } }
javapublic class BasicEncryptionExample { public static void main(String[] args) { KmsClient kmsClient = KmsClient.builder() .region(Region.US_EAST_1) .build(); // Create key String keyId = createEncryptionKey(kmsClient, "Example encryption key"); System.out.println("Created key: " + keyId); // Encrypt and decrypt String plaintext = "Hello, World!"; String encrypted = encryptData(kmsClient, keyId, plaintext); String decrypted = decryptData(kmsClient, encrypted); System.out.println("Original: " + plaintext); System.out.println("Decrypted: " + decrypted); } }
javapublic class EnvelopeEncryptionExample { public static void main(String[] args) { KmsClient kmsClient = KmsClient.builder() .region(Region.US_EAST_1) .build(); String masterKeyId = "alias/your-master-key"; String largeData = "This is a large amount of data that needs encryption..."; byte[] data = largeData.getBytes(StandardCharsets.UTF_8); // Encrypt using envelope pattern DataKeyResult encryptedEnvelope = encryptWithEnvelope( kmsClient, masterKeyId, data); // Decrypt byte[] decryptedData = decryptWithEnvelope( kmsClient, encryptedEnvelope); String result = new String(decryptedData, StandardCharsets.UTF_8); System.out.println("Decrypted: " + result); } }
For detailed implementation patterns, advanced techniques, and comprehensive examples:
@aws-sdk-java-v2-core - Core AWS SDK patterns and configuration@aws-sdk-java-v2-dynamodb - DynamoDB integration patterns@aws-sdk-java-v2-secrets-manager - Secrets management patterns@spring-boot-dependency-injection - Spring dependency injection patterns| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 20,659 | 18,190 | -12% | 1 | 1 | 0% | 4,342 | 7,234 | +67% | 0 | 0 | — |
case-02 | fail→fail | 17,994 | 14,578 | -19% | 1 | 1 | 0% | 3,770 | 6,564 | +74% | 0 | 0 | — |
case-03 | pass→pass | 15,392 | 11,504 | -25% | 1 | 1 | 0% | 2,758 | 5,485 | +99% | 0 | 0 | — |
case-04 | pass→pass | 7,478 | 7,426 | -1% | 1 | 1 | 0% | 1,210 | 4,617 | +282% | 0 | 0 | — |
case-05 | pass→pass | 7,399 | 5,380 | -27% | 1 | 1 | 0% | 1,471 | 4,519 | +207% | 0 | 0 | — |
case-06 | pass→pass | 12,804 | 15,250 | +19% | 1 | 1 | 0% | 2,725 | 5,533 | +103% | 0 | 0 | — |
case-07 | pass→pass | 8,888 | 6,936 | -22% | 1 | 1 | 0% | 1,741 | 4,872 | +180% | 0 | 0 | — |
case-08 | fail→pass | 10,449 | 8,977 | -14% | 1 | 1 | 0% | 2,100 | 4,994 | +138% | 0 | 0 | — |
case-09 | pass→pass | 10,396 | 7,713 | -26% | 1 | 1 | 0% | 2,049 | 4,944 | +141% | 0 | 0 | — |
case-10 | pass→pass | 4,723 | 3,673 | -22% | 1 | 1 | 0% | 789 | 4,043 | +412% | 0 | 0 | — |
case-11 | pass→pass | 5,908 | 4,652 | -21% | 1 | 1 | 0% | 1,229 | 4,375 | +256% | 0 | 0 | — |
case-12 | pass→pass | 6,926 | 6,511 | -6% | 1 | 1 | 0% | 1,383 | 4,791 | +246% | 0 | 0 | — |
case-13 | pass→pass | 12,392 | 7,528 | -39% | 1 | 1 | 0% | 2,371 | 4,875 | +106% | 0 | 0 | — |
case-14 | pass→pass | 11,790 | 19,363 | +64% | 1 | 1 | 0% | 1,304 | 5,676 | +335% | 0 | 0 | — |
case-15 | pass→pass | 5,431 | 4,969 | -9% | 1 | 1 | 0% | 827 | 4,265 | +416% | 0 | 0 | — |
case-16 | pass→pass | 8,481 | 8,379 | -1% | 1 | 1 | 0% | 1,462 | 4,829 | +230% | 0 | 0 | — |
case-17 | pass→pass | 2,957 | 2,114 | -29% | 1 | 1 | 0% | 481 | 3,782 | +686% | 0 | 0 | — |
case-18 | pass→pass | 5,102 | 3,072 | -40% | 1 | 1 | 0% | 891 | 3,922 | +340% | 0 | 0 | — |
case-19 | pass→pass | 8,483 | 5,890 | -31% | 1 | 1 | 0% | 1,765 | 4,508 | +155% | 0 | 0 | — |
case-20 | pass→pass | 12,369 | 12,524 | +1% | 1 | 1 | 0% | 2,193 | 5,959 | +172% | 0 | 0 | — |
case-21 | pass→pass | 10,849 | 13,461 | +24% | 1 | 1 | 0% | 2,207 | 5,607 | +154% | 0 | 0 | — |
case-22 | pass→pass | 19,519 | 13,591 | -30% | 1 | 1 | 0% | 3,788 | 5,913 | +56% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +9 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.