客户提供的带有dart / gcloud的加密密钥

时间:2017-03-28 21:27:03

标签: encryption dart google-cloud-storage

使用dart-lang/gcloud向Google云端存储读取和写入文件,是否可以提供客户提供的加密密钥?

Dart gcloud库基于dart-lang/googleapis构建,它本身与云存储REST API接口,但它使用的HTTP客户端是如此抽象,以至于很难说如何设置自定义加密所需的头。

1 个答案:

答案 0 :(得分:1)

目前,package:gcloud中不支持自定义加密密钥。

虽然Storage constructor接受 http.Client 。所以你可以提供你自己的客户端,它添加标题,类似于:

import 'package:http/http.dart' as http;
import 'package:gcloud/storage.dart' as storage;

class ClientWithKeys extends http.client {
  final String encryptionAlgorithm;
  final String encryptionKey;
  final String encryptionSHA256;

  ClientWithKeys(this.encriptionAlgorithm,
                 this.encriptionKey,
                 this.encryptionSHA256);

  Future<StreamedResponse> send(request) {
    request.headers['x-goog-encryption-algorithm'] = encryptionAlgorithm;
    request.headers['x-goog-encryption-key'] = encryptionKey;
    request.headers['x-goog-encryption-key-sha256'] = encryptionSHA256;
    return super.send(request);
  }
}

code() {
  final client = new ClientWithKeys('<algo>', '<key>', '<sha256>');
  final api = new storage.Storage(client, '<project-id>');
  ...
  client.close();
}