Tworzenie podpisanych adresów URL dla Google Cloud Storage za pomocą NodeJS

Próbuję utworzyć podpis dla prywatnego pliku przechowywanego w Google Cloud Storage; tak, że mogę rozpowszechniać link ograniczony czasowo.

Obecnie robię to i sprawia, że ​​podpis jest zbyt krótki ... gdzie się mylę?

var crypto = require("crypto");

var ttl = new Date().getTime() + 3600;
var id = 'the_target_file.txt';
var bucketName = 'bucket_name';
var POLICY_JSON = "GET\n" + "\n" + "\n" + ttl + "\n" + '/' + bucketName + '/' + id;

// stringify and encode the policy
var stringPolicy = JSON.stringify(POLICY_JSON);
var base64Policy = Buffer(stringPolicy, "utf-8").toString("base64");

// sign the base64 encoded policy
var privateKey = "MY_PRIVATE_KEY";
var sha256 = crypto.createHmac("sha256", privateKey);
var signature = sha256.update(new Buffer(base64Policy, "utf-8")).digest("base64");

console.log ( signature );

questionAnswers(2)

yourAnswerToTheQuestion