Search in sources :

Example 1 with DecryptRequest

use of com.google.api.services.cloudkms.v1.model.DecryptRequest in project data-transfer-project by google.

the class GoogleAppSecretDecrypter method decryptAppSecret.

public byte[] decryptAppSecret(byte[] ciphertext) throws IOException {
    DecryptRequest request = new DecryptRequest().encodeCiphertext(ciphertext);
    DecryptResponse response = cloudKMS.projects().locations().keyRings().cryptoKeys().decrypt(secretsCryptoKey, request).execute();
    return response.decodePlaintext();
}
Also used : DecryptResponse(com.google.api.services.cloudkms.v1.model.DecryptResponse) DecryptRequest(com.google.api.services.cloudkms.v1.model.DecryptRequest)

Example 2 with DecryptRequest

use of com.google.api.services.cloudkms.v1.model.DecryptRequest in project tink by google.

the class GcpKmsAead method decrypt.

@Override
public byte[] decrypt(final byte[] ciphertext, final byte[] aad) throws GeneralSecurityException {
    try {
        DecryptRequest request = new DecryptRequest().encodeCiphertext(ciphertext).encodeAdditionalAuthenticatedData(aad);
        DecryptResponse response = this.kmsClient.projects().locations().keyRings().cryptoKeys().decrypt(this.kmsKeyUri, request).execute();
        return response.decodePlaintext();
    } catch (IOException e) {
        throw new GeneralSecurityException("decryption failed", e);
    }
}
Also used : DecryptResponse(com.google.api.services.cloudkms.v1.model.DecryptResponse) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) DecryptRequest(com.google.api.services.cloudkms.v1.model.DecryptRequest)

Example 3 with DecryptRequest

use of com.google.api.services.cloudkms.v1.model.DecryptRequest in project java-docs-samples by GoogleCloudPlatform.

the class CryptFile method decrypt.

// [END kms_encrypt]
// [START kms_decrypt]
/**
 * Decrypts the provided ciphertext with the specified crypto key.
 */
public static byte[] decrypt(String projectId, String locationId, String keyRingId, String cryptoKeyId, byte[] ciphertext) throws IOException {
    // Create the Cloud KMS client.
    CloudKMS kms = createAuthorizedClient();
    // The resource name of the cryptoKey
    String cryptoKeyName = String.format("projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s", projectId, locationId, keyRingId, cryptoKeyId);
    DecryptRequest request = new DecryptRequest().encodeCiphertext(ciphertext);
    DecryptResponse response = kms.projects().locations().keyRings().cryptoKeys().decrypt(cryptoKeyName, request).execute();
    return response.decodePlaintext();
}
Also used : DecryptResponse(com.google.api.services.cloudkms.v1.model.DecryptResponse) CloudKMS(com.google.api.services.cloudkms.v1.CloudKMS) DecryptRequest(com.google.api.services.cloudkms.v1.model.DecryptRequest)

Example 4 with DecryptRequest

use of com.google.api.services.cloudkms.v1.model.DecryptRequest in project data-transfer-project by google.

the class GoogleCryptoKeyManagementSystem method decryptAppSecret.

public byte[] decryptAppSecret(byte[] ciphertext) throws IOException {
    DecryptRequest request = new DecryptRequest().encodeCiphertext(ciphertext);
    DecryptResponse response = cloudKMS.projects().locations().keyRings().cryptoKeys().decrypt(secretsCryptoKey, request).execute();
    return response.decodePlaintext();
}
Also used : DecryptResponse(com.google.api.services.cloudkms.v1.model.DecryptResponse) DecryptRequest(com.google.api.services.cloudkms.v1.model.DecryptRequest)

Aggregations

DecryptRequest (com.google.api.services.cloudkms.v1.model.DecryptRequest)4 DecryptResponse (com.google.api.services.cloudkms.v1.model.DecryptResponse)4 CloudKMS (com.google.api.services.cloudkms.v1.CloudKMS)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1