diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java index da7e27a72851..965f15e89aed 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java @@ -119,6 +119,8 @@ private Storage.BlobGetOption toGetOption(BlobInfo blobInfo) { return Storage.BlobGetOption.metagenerationNotMatch(blobInfo.getMetageneration()); case USER_PROJECT: return Storage.BlobGetOption.userProject((String) getValue()); + case CUSTOMER_SUPPLIED_KEY: + return Storage.BlobGetOption.decryptionKey((String) getValue()); default: throw new AssertionError("Unexpected enum value"); } diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java index 82dc0775ad32..e55bdde0607f 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java @@ -748,6 +748,25 @@ public static BlobGetOption fields(BlobField... fields) { public static BlobGetOption userProject(String userProject) { return new BlobGetOption(StorageRpc.Option.USER_PROJECT, userProject); } + + /** + * Returns an option to set a customer-supplied AES256 key for server-side decryption of the + * blob. + */ + public static BlobGetOption decryptionKey(Key key) { + String base64Key = BaseEncoding.base64().encode(key.getEncoded()); + return new BlobGetOption(StorageRpc.Option.CUSTOMER_SUPPLIED_KEY, base64Key); + } + + /** + * Returns an option to set a customer-supplied AES256 key for server-side decryption of the + * blob. + * + * @param key the AES256 encoded in base64 + */ + public static BlobGetOption decryptionKey(String key) { + return new BlobGetOption(StorageRpc.Option.CUSTOMER_SUPPLIED_KEY, key); + } } /** Class for specifying bucket list options. */ @@ -1612,6 +1631,21 @@ Blob create( * Blob blob = storage.get(blobId, BlobGetOption.metagenerationMatch(blobMetageneration)); * } * + *
Example of getting information on a blob encrypted using Customer Supplied Encryption Keys, + * only if supplied Decrpytion Key decrypts the blob successfully, otherwise a {@link + * StorageException} is thrown. For more information review + * + * @see Encrypted + * Elements + *
{@code
+ * String bucketName = "my_unique_bucket";
+ * String blobName = "my_blob_name";
+ * String blobEncryptionKey = "";
+ * BlobId blobId = BlobId.of(bucketName, blobName);
+ * Blob blob = storage.get(blobId, BlobGetOption.decryptionKey(blobEncryptionKey));
+ * }
+ *
* @throws StorageException upon failure
*/
Blob get(BlobId blob, BlobGetOption... options);
diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java
index d162b33c5c7f..40a2c44d6d3e 100644
--- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java
+++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java
@@ -414,10 +414,9 @@ public Bucket get(Bucket bucket, Map