def rotate_encryption_key(bucket_name, blob_name, base64_encryption_key, base64_new_encryption_key):
 storage_client = storage.Client()
 bucket = storage_client.get_bucket(bucket_name)
 current_encryption_key = base64.b64decode(base64_encryption_key)
 new_encryption_key = base64.b64decode(base64_new_encryption_key)
 source_blob = Blob(blob_name, bucket, encryption_key=current_encryption_key)
 destination_blob = Blob(blob_name, bucket, encryption_key=new_encryption_key)
 token = None
 while True:
  (token, bytes_rewritten, total_bytes) = destination_blob.rewrite(source_blob, token=token)
  if (token is None):
   break
 print 'Key rotation complete for Blob {}'.format(blob_name)

def rotate_encryption_key ( bucket_name , blob_name , base64_encryption_key , base64_new_encryption_key ) : storage_client = storage . Client ( ) bucket = storage_client . get_bucket ( bucket_name ) current_encryption_key = base64 . b64decode ( base64_encryption_key ) new_encryption_key = base64 . b64decode ( base64_new_encryption_key ) source_blob = Blob ( blob_name , bucket , encryption_key = current_encryption_key ) destination_blob = Blob ( blob_name , bucket , encryption_key = new_encryption_key ) token = None while True : ( token , bytes_rewritten , total_bytes ) = destination_blob . rewrite ( source_blob , token = token ) if ( token is None ) : break print 'Key rotation complete for Blob {}' . format ( blob_name )
performs a key rotation by re-writing an encrypted blob with a new encryption key .