1+ /*
2+ * Copyright 2016 Google Inc. All Rights Reserved.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
117import com .google .api .client .googleapis .json .GoogleJsonResponseException ;
218import com .google .api .client .http .HttpHeaders ;
319import com .google .api .client .http .InputStreamContent ;
@@ -45,18 +61,19 @@ class CustomerSuppliedEncryptionKeysSamples {
4561 * @param storage A Storage object, ready for use
4662 * @param bucketName The name of the destination bucket
4763 * @param objectName The name of the destination object
48- * @param base64CSEKey An AES256 key, encoded as a base64 string.
49- * @param base64CSEKeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
50- * @throws IOException if there was some error download from GCS.
64+ * @param base64CseKey An AES256 key, encoded as a base64 string.
65+ * @param base64CseKeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
5166 *
5267 * @return An InputStream that contains the decrypted contents of the object.
68+ *
69+ * @throws IOException if there was some error download from GCS.
5370 */
5471 public static InputStream downloadObject (
5572 Storage storage ,
5673 String bucketName ,
5774 String objectName ,
58- String base64CSEKey ,
59- String base64CSEKeyHash )
75+ String base64CseKey ,
76+ String base64CseKeyHash )
6077 throws Exception {
6178 Storage .Objects .Get getObject = storage .objects ().get (bucketName , objectName );
6279
@@ -66,8 +83,8 @@ public static InputStream downloadObject(
6683 // Now set the CSEK headers
6784 final HttpHeaders httpHeaders = new HttpHeaders ();
6885 httpHeaders .set ("x-goog-encryption-algorithm" , "AES256" );
69- httpHeaders .set ("x-goog-encryption-key" , base64CSEKey );
70- httpHeaders .set ("x-goog-encryption-key-sha256" , base64CSEKeyHash );
86+ httpHeaders .set ("x-goog-encryption-key" , base64CseKey );
87+ httpHeaders .set ("x-goog-encryption-key-sha256" , base64CseKeyHash );
7188
7289 getObject .setRequestHeaders (httpHeaders );
7390
@@ -89,17 +106,17 @@ public static InputStream downloadObject(
89106 * @param bucketName The name of the destination bucket
90107 * @param objectName The name of the destination object
91108 * @param data An InputStream containing the contents of the object to upload
92- * @param base64CSEKey An AES256 key, encoded as a base64 string.
93- * @param base64CSEKeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
109+ * @param base64CseKey An AES256 key, encoded as a base64 string.
110+ * @param base64CseKeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
94111 * @throws IOException if there was some error uploading to GCS.
95112 */
96113 public static void uploadObject (
97114 Storage storage ,
98115 String bucketName ,
99116 String objectName ,
100117 InputStream data ,
101- String base64CSEKey ,
102- String base64CSEKeyHash )
118+ String base64CseKey ,
119+ String base64CseKeyHash )
103120 throws IOException {
104121 InputStreamContent mediaContent = new InputStreamContent ("text/plain" , data );
105122 Storage .Objects .Insert insertObject =
@@ -112,8 +129,8 @@ public static void uploadObject(
112129 // Now set the CSEK headers
113130 final HttpHeaders httpHeaders = new HttpHeaders ();
114131 httpHeaders .set ("x-goog-encryption-algorithm" , "AES256" );
115- httpHeaders .set ("x-goog-encryption-key" , base64CSEKey );
116- httpHeaders .set ("x-goog-encryption-key-sha256" , base64CSEKeyHash );
132+ httpHeaders .set ("x-goog-encryption-key" , base64CseKey );
133+ httpHeaders .set ("x-goog-encryption-key-sha256" , base64CseKeyHash );
117134
118135 insertObject .setRequestHeaders (httpHeaders );
119136
@@ -192,18 +209,18 @@ public static void main(String[] args) throws Exception {
192209 System .exit (1 );
193210 }
194211 String bucketName = args [0 ];
195-
212+
196213 Storage storage = StorageFactory .getService ();
197214 InputStream dataToUpload = new StorageUtils .ArbitrarilyLargeInputStream (10000000 );
198215
199216 System .out .format ("Uploading object gs://%s/%s using CSEK.\n " , bucketName , OBJECT_NAME );
200217 uploadObject (storage , bucketName , OBJECT_NAME , dataToUpload , CSEK_KEY , CSEK_KEY_HASH );
201-
218+
202219 System .out .format ("Downloading object gs://%s/%s using CSEK.\n " , bucketName , OBJECT_NAME );
203220 InputStream objectData =
204221 downloadObject (storage , bucketName , OBJECT_NAME , CSEK_KEY , CSEK_KEY_HASH );
205222 StorageUtils .readStream (objectData );
206-
223+
207224 System .out .println ("Rotating object to use a different CSEK." );
208225 rotateKey (storage , bucketName , OBJECT_NAME , CSEK_KEY , CSEK_KEY_HASH ,
209226 ANOTHER_CESK_KEY , ANOTHER_CSEK_KEY_HASH );
0 commit comments