Reputation: 3
I am trying to develop a Bigquery Javascript UDF for AES decryption. The key used for AES encryption is encrypted and stored in GCS. I have developed a Javascript code , which will do the following steps:
I am getting storage and kms libraries using below statements:
const Storage = require('@google-cloud/storage'); const kms = require('@google-cloud/kms');
When I have to call the same functionality from Bigquery UDF, how will I make sure these libraries are available? (I don't want to hard code the AES key in the Bigquery UDF)
I have seen an option for [OPTIONS (library = library_array)] in Bigquery UDF definition, but I am not sure which specific .js files are required for storage and kms integration?
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;
})
Thank you, Anu
Upvotes: 0
Views: 889
Reputation: 59175
But:
Upvotes: 1