@@ -45,18 +45,19 @@ class CustomerSuppliedEncryptionKeysSamples {
45
45
* @param storage A Storage object, ready for use
46
46
* @param bucketName The name of the destination bucket
47
47
* @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.
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.
51
50
*
52
51
* @return An InputStream that contains the decrypted contents of the object.
52
+ *
53
+ * @throws IOException if there was some error download from GCS.
53
54
*/
54
55
public static InputStream downloadObject (
55
56
Storage storage ,
56
57
String bucketName ,
57
58
String objectName ,
58
- String base64CSEKey ,
59
- String base64CSEKeyHash )
59
+ String base64CseKey ,
60
+ String base64CseKeyHash )
60
61
throws Exception {
61
62
Storage .Objects .Get getObject = storage .objects ().get (bucketName , objectName );
62
63
@@ -66,8 +67,8 @@ public static InputStream downloadObject(
66
67
// Now set the CSEK headers
67
68
final HttpHeaders httpHeaders = new HttpHeaders ();
68
69
httpHeaders .set ("x-goog-encryption-algorithm" , "AES256" );
69
- httpHeaders .set ("x-goog-encryption-key" , base64CSEKey );
70
- httpHeaders .set ("x-goog-encryption-key-sha256" , base64CSEKeyHash );
70
+ httpHeaders .set ("x-goog-encryption-key" , base64CseKey );
71
+ httpHeaders .set ("x-goog-encryption-key-sha256" , base64CseKeyHash );
71
72
72
73
getObject .setRequestHeaders (httpHeaders );
73
74
@@ -89,17 +90,17 @@ public static InputStream downloadObject(
89
90
* @param bucketName The name of the destination bucket
90
91
* @param objectName The name of the destination object
91
92
* @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.
93
+ * @param base64CseKey An AES256 key, encoded as a base64 string.
94
+ * @param base64CseKeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
94
95
* @throws IOException if there was some error uploading to GCS.
95
96
*/
96
97
public static void uploadObject (
97
98
Storage storage ,
98
99
String bucketName ,
99
100
String objectName ,
100
101
InputStream data ,
101
- String base64CSEKey ,
102
- String base64CSEKeyHash )
102
+ String base64CseKey ,
103
+ String base64CseKeyHash )
103
104
throws IOException {
104
105
InputStreamContent mediaContent = new InputStreamContent ("text/plain" , data );
105
106
Storage .Objects .Insert insertObject =
@@ -112,8 +113,8 @@ public static void uploadObject(
112
113
// Now set the CSEK headers
113
114
final HttpHeaders httpHeaders = new HttpHeaders ();
114
115
httpHeaders .set ("x-goog-encryption-algorithm" , "AES256" );
115
- httpHeaders .set ("x-goog-encryption-key" , base64CSEKey );
116
- httpHeaders .set ("x-goog-encryption-key-sha256" , base64CSEKeyHash );
116
+ httpHeaders .set ("x-goog-encryption-key" , base64CseKey );
117
+ httpHeaders .set ("x-goog-encryption-key-sha256" , base64CseKeyHash );
117
118
118
119
insertObject .setRequestHeaders (httpHeaders );
119
120
@@ -192,18 +193,18 @@ public static void main(String[] args) throws Exception {
192
193
System .exit (1 );
193
194
}
194
195
String bucketName = args [0 ];
195
-
196
+
196
197
Storage storage = StorageFactory .getService ();
197
198
InputStream dataToUpload = new StorageUtils .ArbitrarilyLargeInputStream (10000000 );
198
199
199
200
System .out .format ("Uploading object gs://%s/%s using CSEK.\n " , bucketName , OBJECT_NAME );
200
201
uploadObject (storage , bucketName , OBJECT_NAME , dataToUpload , CSEK_KEY , CSEK_KEY_HASH );
201
-
202
+
202
203
System .out .format ("Downloading object gs://%s/%s using CSEK.\n " , bucketName , OBJECT_NAME );
203
204
InputStream objectData =
204
205
downloadObject (storage , bucketName , OBJECT_NAME , CSEK_KEY , CSEK_KEY_HASH );
205
206
StorageUtils .readStream (objectData );
206
-
207
+
207
208
System .out .println ("Rotating object to use a different CSEK." );
208
209
rotateKey (storage , bucketName , OBJECT_NAME , CSEK_KEY , CSEK_KEY_HASH ,
209
210
ANOTHER_CESK_KEY , ANOTHER_CSEK_KEY_HASH );
0 commit comments