【发布时间】:2019-11-15 13:25:14
【问题描述】:
我正在尝试开发用于 AES 解密的 Bigquery Javascript UDF。 用于 AES 加密的密钥被加密并存储在 GCS 中。 我开发了一个 Javascript 代码,它将执行以下步骤:
- 从 GCS 读取具有 AES 密钥加密值的文件
- 使用 kms 密钥环和 kms 密钥解密 AES 密钥值
- 使用此密钥进行 AES 解密。
我正在使用以下语句获取存储和 kms 库:
const Storage = require('@google-cloud/storage'); const kms = require('@google-cloud/kms');
当我必须从 Bigquery UDF 调用相同的功能时,我将如何进行 确定这些库可用吗? (我不想在 Bigquery UDF 中硬编码 AES 密钥)
我在 Bigquery UDF 定义中看到了 [OPTIONS (library = library_array)] 的选项,但我 不确定存储和 kms 集成需要哪些特定的 .js 文件?
代码 sn-p
const Storage = require('@google-cloud/storage');
const storage = new Storage.Storage();
const kms = require('@google-cloud/kms');
const client = new kms.KeyManagementServiceClient();
bucketName ="gs://testbucket"
const keyFile = storage.bucket(bucketName).file("key.enc");
'use strict';
async function decrypt(ciphertext){
const name=<replace with crypto-key-path>;
const [result] = await client.decrypt({name, ciphertext});
return Buffer.from(result.plaintext, 'base64').toString();
}
var key=saltFile.download(function(err, contents) {
key=decrypt(contents);
key.then(function (value) {
key = value.trim();
console.log(value);
});
return key;
})
谢谢你, 阿努
【问题讨论】:
标签: node.js encryption google-cloud-platform google-bigquery