【问题标题】:Customer-supplied encryption keys with dart/gcloud客户提供的 dart/gcloud 加密密钥
【发布时间】:2017-03-28 21:27:03
【问题描述】:

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

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

【问题讨论】:

    标签: encryption dart google-cloud-storage


    【解决方案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();
    }
    

    【讨论】:

      猜你喜欢
      • 2017-12-14
      • 1970-01-01
      • 2022-01-27
      • 2018-02-10
      • 2019-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多