2

I want to setup a automatic transcoding of a video to encrypted hls with a playlist. My lambda code is below, but when it is run, I get the following error

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

The code in lambda is

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'
      },
    },

What am I overlooking ? The only thing I can think of that I am missing is that I first need to encrypt the plainkey.... but any suggestions how to do so ?

Daniel B.
  • 1,650
  • 1
  • 19
  • 40
robo
  • 39
  • 1
  • 5

1 Answers1

0

It seems that the MD5 generation was wrong and I needed to do it like this:

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

This creates the MD5 and encodes it with base64

robo
  • 39
  • 1
  • 5