Search in sources :

Example 1 with GenerateDataKeyRequest

use of com.amazonaws.services.kms.model.GenerateDataKeyRequest in project aws-doc-sdk-examples by awsdocs.

the class GenerateDataKey method main.

public static void main(String[] args) {
    final String USAGE = "To run this example, supply a key id or ARN and a KeySpec\n" + "Usage: GenerateDataKey <key-id> <key-spec>\n" + "Example: GenerateDataKey 1234abcd-12ab-34cd-56ef-1234567890ab" + " AES_256\n";
    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String keyId = args[0];
    String keySpec = args[1];
    AWSKMS kmsClient = AWSKMSClientBuilder.standard().build();
    // Generate a data key
    GenerateDataKeyRequest dataKeyRequest = new GenerateDataKeyRequest();
    dataKeyRequest.setKeyId(keyId);
    dataKeyRequest.setKeySpec(keySpec);
    GenerateDataKeyResult dataKeyResult = kmsClient.generateDataKey(dataKeyRequest);
    ByteBuffer plaintextKey = dataKeyResult.getPlaintext();
    ByteBuffer encryptedKey = dataKeyResult.getCiphertextBlob();
    System.out.printf("Successfully generated an encrypted data key: %s%n", Base64.getEncoder().encodeToString(encryptedKey.array()));
}
Also used : GenerateDataKeyRequest(com.amazonaws.services.kms.model.GenerateDataKeyRequest) GenerateDataKeyResult(com.amazonaws.services.kms.model.GenerateDataKeyResult) ByteBuffer(java.nio.ByteBuffer) AWSKMS(com.amazonaws.services.kms.AWSKMS)

Example 2 with GenerateDataKeyRequest

use of com.amazonaws.services.kms.model.GenerateDataKeyRequest in project checker-framework by typetools.

the class GenerateDataKeyRequestExamples method incorrect4.

void incorrect4(AWSKMS client) {
    GenerateDataKeyRequest request = new GenerateDataKeyRequest();
    request.withKeySpec(DataKeySpec.AES_256);
    request.withNumberOfBytes(32);
    // :: error: argument
    client.generateDataKey(request);
}
Also used : GenerateDataKeyRequest(com.amazonaws.services.kms.model.GenerateDataKeyRequest)

Example 3 with GenerateDataKeyRequest

use of com.amazonaws.services.kms.model.GenerateDataKeyRequest in project checker-framework by typetools.

the class GenerateDataKeyRequestExamples method correctWithNumberOfBytes.

void correctWithNumberOfBytes(AWSKMS client) {
    GenerateDataKeyRequest request = new GenerateDataKeyRequest();
    request.withNumberOfBytes(32);
    client.generateDataKey(request);
}
Also used : GenerateDataKeyRequest(com.amazonaws.services.kms.model.GenerateDataKeyRequest)

Example 4 with GenerateDataKeyRequest

use of com.amazonaws.services.kms.model.GenerateDataKeyRequest in project checker-framework by typetools.

the class GenerateDataKeyRequestExamples method setTwice4.

void setTwice4(AWSKMS client) {
    GenerateDataKeyRequest request = new GenerateDataKeyRequest();
    request.setNumberOfBytes(32);
    request.setNumberOfBytes(32);
    client.generateDataKey(request);
}
Also used : GenerateDataKeyRequest(com.amazonaws.services.kms.model.GenerateDataKeyRequest)

Example 5 with GenerateDataKeyRequest

use of com.amazonaws.services.kms.model.GenerateDataKeyRequest in project checker-framework by typetools.

the class GenerateDataKeyRequestExamples method incorrect3.

void incorrect3(AWSKMS client) {
    GenerateDataKeyRequest request = new GenerateDataKeyRequest();
    request.setKeySpec(DataKeySpec.AES_256);
    request.withNumberOfBytes(32);
    // :: error: argument
    client.generateDataKey(request);
}
Also used : GenerateDataKeyRequest(com.amazonaws.services.kms.model.GenerateDataKeyRequest)

Aggregations

GenerateDataKeyRequest (com.amazonaws.services.kms.model.GenerateDataKeyRequest)15 GenerateDataKeyResult (com.amazonaws.services.kms.model.GenerateDataKeyResult)2 ByteBuffer (java.nio.ByteBuffer)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 AWSKMS (com.amazonaws.services.kms.AWSKMS)1 AWSKMSClient (com.amazonaws.services.kms.AWSKMSClient)1 DecryptRequest (com.amazonaws.services.kms.model.DecryptRequest)1 WSPasswordCallback (org.apache.wss4j.common.ext.WSPasswordCallback)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1