diff --git a/storage/json-api/src/main/java/CustomerSuppliedEncryptionKeysSamples.java b/storage/json-api/src/main/java/CustomerSuppliedEncryptionKeysSamples.java index 88cb8f3b882..387100adc95 100644 --- a/storage/json-api/src/main/java/CustomerSuppliedEncryptionKeysSamples.java +++ b/storage/json-api/src/main/java/CustomerSuppliedEncryptionKeysSamples.java @@ -45,18 +45,19 @@ class CustomerSuppliedEncryptionKeysSamples { * @param storage A Storage object, ready for use * @param bucketName The name of the destination bucket * @param objectName The name of the destination object - * @param base64CSEKey An AES256 key, encoded as a base64 string. - * @param base64CSEKeyHash The SHA-256 hash of the above key, also encoded as a base64 string. - * @throws IOException if there was some error download from GCS. + * @param base64CseKey An AES256 key, encoded as a base64 string. + * @param base64CseKeyHash The SHA-256 hash of the above key, also encoded as a base64 string. * * @return An InputStream that contains the decrypted contents of the object. + * + * @throws IOException if there was some error download from GCS. */ public static InputStream downloadObject( Storage storage, String bucketName, String objectName, - String base64CSEKey, - String base64CSEKeyHash) + String base64CseKey, + String base64CseKeyHash) throws Exception { Storage.Objects.Get getObject = storage.objects().get(bucketName, objectName); @@ -66,8 +67,8 @@ public static InputStream downloadObject( // Now set the CSEK headers final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("x-goog-encryption-algorithm", "AES256"); - httpHeaders.set("x-goog-encryption-key", base64CSEKey); - httpHeaders.set("x-goog-encryption-key-sha256", base64CSEKeyHash); + httpHeaders.set("x-goog-encryption-key", base64CseKey); + httpHeaders.set("x-goog-encryption-key-sha256", base64CseKeyHash); getObject.setRequestHeaders(httpHeaders); @@ -89,8 +90,8 @@ public static InputStream downloadObject( * @param bucketName The name of the destination bucket * @param objectName The name of the destination object * @param data An InputStream containing the contents of the object to upload - * @param base64CSEKey An AES256 key, encoded as a base64 string. - * @param base64CSEKeyHash The SHA-256 hash of the above key, also encoded as a base64 string. + * @param base64CseKey An AES256 key, encoded as a base64 string. + * @param base64CseKeyHash The SHA-256 hash of the above key, also encoded as a base64 string. * @throws IOException if there was some error uploading to GCS. */ public static void uploadObject( @@ -98,8 +99,8 @@ public static void uploadObject( String bucketName, String objectName, InputStream data, - String base64CSEKey, - String base64CSEKeyHash) + String base64CseKey, + String base64CseKeyHash) throws IOException { InputStreamContent mediaContent = new InputStreamContent("text/plain", data); Storage.Objects.Insert insertObject = @@ -112,8 +113,8 @@ public static void uploadObject( // Now set the CSEK headers final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("x-goog-encryption-algorithm", "AES256"); - httpHeaders.set("x-goog-encryption-key", base64CSEKey); - httpHeaders.set("x-goog-encryption-key-sha256", base64CSEKeyHash); + httpHeaders.set("x-goog-encryption-key", base64CseKey); + httpHeaders.set("x-goog-encryption-key-sha256", base64CseKeyHash); insertObject.setRequestHeaders(httpHeaders); @@ -192,18 +193,18 @@ public static void main(String[] args) throws Exception { System.exit(1); } String bucketName = args[0]; - + Storage storage = StorageFactory.getService(); InputStream dataToUpload = new StorageUtils.ArbitrarilyLargeInputStream(10000000); System.out.format("Uploading object gs://%s/%s using CSEK.\n", bucketName, OBJECT_NAME); uploadObject(storage, bucketName, OBJECT_NAME, dataToUpload, CSEK_KEY, CSEK_KEY_HASH); - + System.out.format("Downloading object gs://%s/%s using CSEK.\n", bucketName, OBJECT_NAME); InputStream objectData = downloadObject(storage, bucketName, OBJECT_NAME, CSEK_KEY, CSEK_KEY_HASH); StorageUtils.readStream(objectData); - + System.out.println("Rotating object to use a different CSEK."); rotateKey(storage, bucketName, OBJECT_NAME, CSEK_KEY, CSEK_KEY_HASH, ANOTHER_CESK_KEY, ANOTHER_CSEK_KEY_HASH); diff --git a/storage/json-api/src/main/java/StorageUtils.java b/storage/json-api/src/main/java/StorageUtils.java index 5e37b36f790..bcd5ce1b32d 100644 --- a/storage/json-api/src/main/java/StorageUtils.java +++ b/storage/json-api/src/main/java/StorageUtils.java @@ -2,12 +2,12 @@ import java.io.InputStream; public class StorageUtils { - + /** * Reads the contents of an InputStream and does nothing with it. */ public static void readStream(InputStream is) throws IOException { - byte inputBuffer[] = new byte[256]; + byte[] inputBuffer = new byte[256]; while (is.read(inputBuffer) != -1) {} // The caller is responsible for closing this InputStream. is.close();