This page describes how to use your own encryption key, referred to as a customer-supplied encryption key , with Cloud Storage. For other encryption options in Cloud Storage, see Data Encryption Options .
Generate your own encryption key
There are many ways to generate a Base64-encoded AES-256 encryption key. Here are several examples:
C++
For more information, see the Cloud Storage C++ API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
C#
For more information, see the Cloud Storage C# API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Go
For more information, see the Cloud Storage Go API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Java
For more information, see the Cloud Storage Java API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Node.js
For more information, see the Cloud Storage Node.js API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
PHP
For more information, see the Cloud Storage PHP API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Python
For more information, see the Cloud Storage Python API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Ruby
For more information, see the Cloud Storage Ruby API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Upload with your encryption key
To use customer-supplied encryption keys to upload an object:
Console
The Google Cloud console cannot be used to upload an object with a customer-supplied encryption key. Use the Google Cloud CLI or the client libraries instead.
Command line
Use the  gcloud storage cp 
 
command with the --encryption-key 
flag:
gcloud storage cp SOURCE_DATA gs:// BUCKET_NAME / OBJECT_NAME --encryption-key= YOUR_ENCRYPTION_KEY
Where:
-  SOURCE_DATAis the source location of the data you're encrypting. This can be any source location supported by thecpcommand. For example, a local file such asDesktop/dogs.pngor another Cloud Storage object such asgs://my-bucket/pets/old-dog.png.
-  BUCKET_NAMEis the name of the destination bucket for this copy command. For example,my-bucket.
-  OBJECT_NAMEis the name of the final, encrypted object. For example,pets/new-dog.png.
-  YOUR_ENCRYPTION_KEYis the AES-256 key that you want to use for encrypting the uploaded object.
Client libraries
C++
For more information, see the Cloud Storage C++ API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
C#
For more information, see the Cloud Storage C# API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Go
For more information, see the Cloud Storage Go API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Java
For more information, see the Cloud Storage Java API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Node.js
For more information, see the Cloud Storage Node.js API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
PHP
For more information, see the Cloud Storage PHP API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Python
For more information, see the Cloud Storage Python API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Ruby
For more information, see the Cloud Storage Ruby API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .

