AWS Lambda弹性转码器密钥使用播放列表加密HLS

时间:2018-02-09 10:21:14

标签: aws-lambda amazon-elastic-transcoder

我想设置一个视频自动转码为带有播放列表的加密hls。 我的lambda代码在下面,但是当它运行时,我得到以下错误

{ ValidationException: The MD5 hash of the base64-decoded value for 
''Encryption:Key'' must equal the base64-decoded value for ''Encryption:KeyMd5''.

lambda中的代码是

var srcKey =  decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " ")); 
 var newKey = key.split('.')[0];
 var plainEncryptionKey='t6w9z$C&F)J@NcQf';
 var KeyBase64 = new Buffer(plainEncryptionKey).toString('base64');
 console.log("plain_base64: " + KeyBase64);

 var crypto = require('crypto');
 var MD5= crypto.createHash('md5').update(plainEncryptionKey).digest("hex");
 var MD5Base64 = new Buffer(MD5).toString('base64');
 console.log("md5_base64: " + MD5Base64);


 var params = {
  PipelineId: pipelineId,
  OutputKeyPrefix: newKey + '/',
  Input: {
   Key: srcKey,
   FrameRate: 'auto',
   Resolution: 'auto',
   AspectRatio: 'auto',
   Interlaced: 'auto',
   Container: 'auto'
  },
  Outputs: [{
   Key: newKey + '-hls' + '.ts',
   ThumbnailPattern: '',
   PresetId: '1351620000001-200010', //HLS v3 2mb/s
   SegmentDuration: '10',
  }],
    Playlists: [
    {
      Name: 'index',
      Format: 'HLSv3',
      OutputKeys: [ newKey + '-hls' + '.ts',  ],
      HlsContentProtection: {
        InitializationVector: 'VQMKGVjivkBUJLf4BY4uQQ==',
        Key: KeyBase64,
        KeyMd5: MD5Base64,
        KeyStoragePolicy: 'NoStore',
        LicenseAcquisitionUrl: 'https://example.com/ekey.php',
        Method: 'aes-128'
      },
    },

我在俯瞰什么? 我唯一想到的就是我缺少的是我首先需要加密普通钥匙....但是有什么建议怎么做?

1 个答案:

答案 0 :(得分:0)

似乎MD5代错了,我需要这样做:

var MD5Base64= crypto.createHash('md5').update(encKey).digest("base64");

这将创建MD5并使用base64

对其进行编码