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();
}
}
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);
}
}
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;
}
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();
}
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);
}
Aggregations