HLS data encryption
Updated at:
This topic describes the scenarios and limits for HLS data encryption using the Node.js software development kit (SDK). It also provides a complete code sample.
Scenarios
- Standard HLS data encryption protects videos from unauthorized downloads and distribution.
- If you have high security requirements, you can enable data encryption in your workflow. For more information, see Alibaba Cloud proprietary cryptography.
Limits
- Standard HLS data encryption requires the Submit transcoding jobs API operation.
- Standard HLS data encryption cannot be used in workflows.
Sample code
const base64url = require('base64-url');
var RPCClient = require('@alicloud/pop-core').RPCClient;
var REGION = "cn-shanghai"; // Configure as needed.
var ID = "<your ID>"; // Obtain it from the AccessKey console and configure as needed.
var KEY = "<your key>"; // Obtain it from the AccessKey console and configure as needed.
var LOCATION = "<oss-cn-shanghai>"; // Configure as needed. The MPS service, OSS service, and PipelineId must be in the same region.
var INPUT_BUCKET = "<your input_bucket>"; // Configure as needed.
var OUTPUT_BUCKET = "<your output_bucket>"; // Configure as needed.
var PIPELINE_ID = "<your pipelineid>"; // Obtain it from the MPS console and configure as needed.
function initMtsClient(accessKeyId, accessKeySecret, regionId) {
var client = new RPCClient({
accessKeyId: accessKeyId,
accessKeySecret: accessKeySecret,
endpoint: 'http://mts.' + regionId + '.aliyuncs.com',
apiVersion: '2014-06-18'
});
return client;
}
function DataEncryptionDemo() {
return initMtsClient(ID, KEY, REGION);
}
function getInputFile() {
var inputFile = {};
inputFile.Location = LOCATION;
inputFile.Bucket = INPUT_BUCKET;
inputFile.Object = 'result.mp4';
return inputFile;
}
function getOutputs() {
var left = '[';
var right = ']';
var output = getOutput();
var outputs = left.concat(JSON.stringify(output), right);
return outputs;
}
function getOutput() {
var output = {};
output.OutputObject = "BaseTest/hls-encryption****.m3u8";
output.TemplateId = "S00000001-100020";
output.Encryption = JSON.stringify(getEncryptionConfigs());
return output;
}
function getEncryptionConfigs() {
var encryption = {};
encryption.Type = "hls-aes-128";
encryption.Key = base64url.encode("encryptionkey123");
encryption.KeyUri = base64url.encode("http://example.aliyundoc.com/document/hls128****.key");
encryption.KeyType = "Base64";
return encryption;
}
function submitJobs() {
inputFile = getInputFile();
outputs = getOutputs();
client = DataEncryptionDemo();
client.request('SubmitJobs', {
Input: JSON.stringify(inputFile),
OutputLocation: LOCATION,
OutputBucket: OUTPUT_BUCKET,
Outputs: outputs,
PipelineId: PIPELINE_ID,
OutputLocation: LOCATION
}).then(function (response) {
console.log(JSON.stringify(response.JobResultList));
console.log(response.JobResultList.JobResult[0].Job.JobId);
}).catch(function (response) {
console.log(JSON.stringify(response));
})
}
submitJobs();Is this page helpful?