Search in sources :

Example 1 with DecryptResponse

use of com.aliyuncs.kms.model.v20160120.DecryptResponse in project gapic-generator-java by googleapis.

the class AsyncDecrypt method asyncDecrypt.

public static void asyncDecrypt() throws Exception {
    // It may require modifications to work in your environment.
    try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
        DecryptRequest request = DecryptRequest.newBuilder().setName(CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString()).setCiphertext(ByteString.EMPTY).setAdditionalAuthenticatedData(ByteString.EMPTY).setCiphertextCrc32C(Int64Value.newBuilder().build()).setAdditionalAuthenticatedDataCrc32C(Int64Value.newBuilder().build()).build();
        ApiFuture<DecryptResponse> future = keyManagementServiceClient.decryptCallable().futureCall(request);
        // Do something.
        DecryptResponse response = future.get();
    }
}
Also used : DecryptResponse(com.google.cloud.kms.v1.DecryptResponse) DecryptRequest(com.google.cloud.kms.v1.DecryptRequest) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient)

Example 2 with DecryptResponse

use of com.aliyuncs.kms.model.v20160120.DecryptResponse in project gapic-generator-java by googleapis.

the class SyncDecrypt method syncDecrypt.

public static void syncDecrypt() throws Exception {
    // It may require modifications to work in your environment.
    try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
        DecryptRequest request = DecryptRequest.newBuilder().setName(CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString()).setCiphertext(ByteString.EMPTY).setAdditionalAuthenticatedData(ByteString.EMPTY).setCiphertextCrc32C(Int64Value.newBuilder().build()).setAdditionalAuthenticatedDataCrc32C(Int64Value.newBuilder().build()).build();
        DecryptResponse response = keyManagementServiceClient.decrypt(request);
    }
}
Also used : DecryptResponse(com.google.cloud.kms.v1.DecryptResponse) DecryptRequest(com.google.cloud.kms.v1.DecryptRequest) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient)

Example 3 with DecryptResponse

use of com.aliyuncs.kms.model.v20160120.DecryptResponse in project aliyun-oss-java-sdk by aliyun.

the class KmsEncryptionMaterials method decryptCipherBlob.

/**
 * Decrypt the cipherBlob to palin text.
 */
private DecryptResponse decryptCipherBlob(KmsClientSuite kmsClientSuite, String cipherBlob) throws ClientException {
    final DefaultAcsClient kmsClient = createKmsClient(kmsClientSuite.region, kmsClientSuite.credentialsProvider);
    final DecryptRequest decReq = new DecryptRequest();
    decReq.setSysProtocol(ProtocolType.HTTPS);
    decReq.setAcceptFormat(FormatType.JSON);
    decReq.setSysMethod(MethodType.POST);
    decReq.setCiphertextBlob(cipherBlob);
    final DecryptResponse decResponse;
    try {
        decResponse = kmsClient.getAcsResponse(decReq);
    } catch (Exception e) {
        throw new ClientException("The kms client decrypt data faild." + e.getMessage(), e);
    }
    return decResponse;
}
Also used : DecryptResponse(com.aliyuncs.kms.model.v20160120.DecryptResponse) DefaultAcsClient(com.aliyuncs.DefaultAcsClient) ClientException(com.aliyun.oss.ClientException) DecryptRequest(com.aliyuncs.kms.model.v20160120.DecryptRequest) ClientException(com.aliyun.oss.ClientException)

Example 4 with DecryptResponse

use of com.aliyuncs.kms.model.v20160120.DecryptResponse in project ranger by apache.

the class RangerGoogleCloudHSMProvider method decryptZoneKey.

@Override
public byte[] decryptZoneKey(byte[] encryptedByte) throws Exception {
    CryptoKeyName keyName = CryptoKeyName.of(this.gcpProjectId, this.gcpLocationId, this.gcpKeyRingId, this.gcpMasterKeyName);
    if (logger.isDebugEnabled()) {
        logger.debug("==> GCP decryptZoneKey() : CryptoKeyName - { " + keyName + " }");
    }
    DecryptResponse response = client.decrypt(keyName, ByteString.copyFrom(encryptedByte));
    if (response == null) {
        throw new RuntimeCryptoException("Got null response for decrypt zone key operation!");
    } else if (response.getPlaintext() == null || StringUtils.isEmpty(response.getPlaintext().toString())) {
        throw new RuntimeCryptoException("Error - Received null or empty decrypted zone key : " + response.getPlaintext());
    }
    if (logger.isDebugEnabled()) {
        logger.debug("<== GCP decryptZoneKey() : DecryptResponse - { " + response + " }");
    }
    return response.getPlaintext().toByteArray();
}
Also used : RuntimeCryptoException(org.bouncycastle.crypto.RuntimeCryptoException) DecryptResponse(com.google.cloud.kms.v1.DecryptResponse) CryptoKeyName(com.google.cloud.kms.v1.CryptoKeyName)

Example 5 with DecryptResponse

use of com.aliyuncs.kms.model.v20160120.DecryptResponse in project spring-cloud-gcp by GoogleCloudPlatform.

the class KmsTemplateTests method testEncryptDecrypt.

@Test
void testEncryptDecrypt() {
    EncryptResponse encryptResponse = createEncryptResponse();
    DecryptResponse decryptResponse = createDecryptResponse();
    when(this.client.encrypt(any(EncryptRequest.class))).thenReturn(encryptResponse);
    when(this.client.decrypt(any(DecryptRequest.class))).thenReturn(decryptResponse);
    String cryptoKeyNameStr = "test-project/europe-west2/key-ring-id/key-id";
    byte[] encryptedBytes = kmsTemplate.encryptText(cryptoKeyNameStr, "1234");
    String decryptedText = kmsTemplate.decryptText(cryptoKeyNameStr, encryptedBytes);
    Assert.assertEquals("1234", decryptedText);
}
Also used : EncryptResponse(com.google.cloud.kms.v1.EncryptResponse) DecryptResponse(com.google.cloud.kms.v1.DecryptResponse) ByteString(com.google.protobuf.ByteString) DecryptRequest(com.google.cloud.kms.v1.DecryptRequest) EncryptRequest(com.google.cloud.kms.v1.EncryptRequest) Test(org.junit.jupiter.api.Test)

Aggregations

DecryptResponse (com.google.cloud.kms.v1.DecryptResponse)11 KeyManagementServiceClient (com.google.cloud.kms.v1.KeyManagementServiceClient)7 DecryptRequest (com.google.cloud.kms.v1.DecryptRequest)6 ByteString (com.google.protobuf.ByteString)6 CryptoKeyName (com.google.cloud.kms.v1.CryptoKeyName)5 ClientException (com.aliyun.oss.ClientException)2 DecryptResponse (com.aliyuncs.kms.model.v20160120.DecryptResponse)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2 DefaultAcsClient (com.aliyuncs.DefaultAcsClient)1 DecryptRequest (com.aliyuncs.kms.model.v20160120.DecryptRequest)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 EncryptRequest (com.google.cloud.kms.v1.EncryptRequest)1 EncryptResponse (com.google.cloud.kms.v1.EncryptResponse)1 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 PrivateKey (java.security.PrivateKey)1 LinkedHashMap (java.util.LinkedHashMap)1