use of com.aliyuncs.kms.model.v20160120.EncryptResponse in project java-kms by googleapis.
the class EncryptSymmetric method encryptSymmetric.
// Encrypt data with a given key.
public void encryptSymmetric(String projectId, String locationId, String keyRingId, String keyId, String plaintext) throws IOException {
// safely clean up any remaining background resources.
try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
// Build the key version name from the project, location, key ring, key,
// and key version.
CryptoKeyName keyVersionName = CryptoKeyName.of(projectId, locationId, keyRingId, keyId);
// Encrypt the plaintext.
EncryptResponse response = client.encrypt(keyVersionName, ByteString.copyFromUtf8(plaintext));
System.out.printf("Ciphertext: %s%n", response.getCiphertext().toStringUtf8());
}
}
use of com.aliyuncs.kms.model.v20160120.EncryptResponse in project spring-cloud-gcp by GoogleCloudPlatform.
the class KmsTemplate method encryptBytes.
@Override
public byte[] encryptBytes(String cryptoKey, byte[] bytes) {
CryptoKeyName cryptoKeyName = KmsPropertyUtils.getCryptoKeyName(cryptoKey, projectIdProvider);
long crc32c = longCrc32c(bytes);
EncryptRequest request = EncryptRequest.newBuilder().setName(cryptoKeyName.toString()).setPlaintext(ByteString.copyFrom(bytes)).setPlaintextCrc32C(Int64Value.newBuilder().setValue(crc32c).build()).build();
EncryptResponse response = client.encrypt(request);
assertCrcMatch(response);
return response.getCiphertext().toByteArray();
}
use of com.aliyuncs.kms.model.v20160120.EncryptResponse in project gapic-generator-java by googleapis.
the class AsyncEncrypt method asyncEncrypt.
public static void asyncEncrypt() throws Exception {
// It may require modifications to work in your environment.
try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
EncryptRequest request = EncryptRequest.newBuilder().setName(CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString()).setPlaintext(ByteString.EMPTY).setAdditionalAuthenticatedData(ByteString.EMPTY).setPlaintextCrc32C(Int64Value.newBuilder().build()).setAdditionalAuthenticatedDataCrc32C(Int64Value.newBuilder().build()).build();
ApiFuture<EncryptResponse> future = keyManagementServiceClient.encryptCallable().futureCall(request);
// Do something.
EncryptResponse response = future.get();
}
}
use of com.aliyuncs.kms.model.v20160120.EncryptResponse in project gapic-generator-java by googleapis.
the class SyncEncrypt method syncEncrypt.
public static void syncEncrypt() throws Exception {
// It may require modifications to work in your environment.
try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
EncryptRequest request = EncryptRequest.newBuilder().setName(CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString()).setPlaintext(ByteString.EMPTY).setAdditionalAuthenticatedData(ByteString.EMPTY).setPlaintextCrc32C(Int64Value.newBuilder().build()).setAdditionalAuthenticatedDataCrc32C(Int64Value.newBuilder().build()).build();
EncryptResponse response = keyManagementServiceClient.encrypt(request);
}
}
use of com.aliyuncs.kms.model.v20160120.EncryptResponse in project gapic-generator-java by googleapis.
the class SyncEncryptStringBytestring method syncEncryptStringBytestring.
public static void syncEncryptStringBytestring() throws Exception {
// It may require modifications to work in your environment.
try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
String name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString();
ByteString plaintext = ByteString.EMPTY;
EncryptResponse response = keyManagementServiceClient.encrypt(name, plaintext);
}
}
Aggregations