use of com.google.api.services.cloudkms.v1.model.EncryptResponse in project tink by google.
the class GcpKmsAead method encrypt.
@Override
public byte[] encrypt(final byte[] plaintext, final byte[] aad) throws GeneralSecurityException {
try {
EncryptRequest request = new EncryptRequest().encodePlaintext(plaintext).encodeAdditionalAuthenticatedData(aad);
EncryptResponse response = this.kmsClient.projects().locations().keyRings().cryptoKeys().encrypt(this.kmsKeyUri, request).execute();
return response.decodeCiphertext();
} catch (IOException e) {
throw new GeneralSecurityException("encryption failed", e);
}
}
use of com.google.api.services.cloudkms.v1.model.EncryptResponse in project java-docs-samples by GoogleCloudPlatform.
the class CryptFile method encrypt.
// [START kms_encrypt]
/**
* Encrypts the given plaintext using the specified crypto key.
*/
public static byte[] encrypt(String projectId, String locationId, String keyRingId, String cryptoKeyId, byte[] plaintext) throws IOException {
// The resource name of the cryptoKey
String resourceName = String.format("projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s", projectId, locationId, keyRingId, cryptoKeyId);
// Create the Cloud KMS client.
CloudKMS kms = createAuthorizedClient();
EncryptRequest request = new EncryptRequest().encodePlaintext(plaintext);
EncryptResponse response = kms.projects().locations().keyRings().cryptoKeys().encrypt(resourceName, request).execute();
return response.decodeCiphertext();
}
Aggregations