how do I create a license acquisition URL endpoint using springboot from an aws elastic-transcoder data key?

278 Views Asked by At

I chose "no store" when transcoding my audio file using aws elastic transcoder. now I have Encryption Key - xxxxxxxxxxxxxxxxxx Encryption Key MD5- xxxxxxxxxxxxx Encryption Initialization Vector-xxxxxxxxxx

so I used awskms to decrypt the encryption key using this code

public ByteBuffer decryptAes(String aes) {

    Map<String, String> enccontext = new HashMap<>();
    enccontext.put("service", "elastictranscoder.amazonaws.com");
    ByteBuffer encrypted = getBytebuffer(Base64.getDecoder().decode(aes));

    DecryptRequest reqq = new DecryptRequest().withCiphertextBlob(encrypted).withEncryptionContext(enccontext);

    ByteBuffer buf = awskms.decrypt(reqq).withKeyId(keyId).getPlaintext();

    return buf;
}

and i have a the m3u8 file with a key of #EXT-X-KEY:METHOD=AES-128,URI="https://[mysite]/api/public/amazoncode",IV=0xdbe2882930b143e62b3e6e587a2269f8

so my confusion is how do I send the decrypting key to the m3u8?, I've this so far but it doesn't seem to work

// this is the endpoint for https://[mysite]/api/public/amazoncode
@GetMapping(value = "amazoncode")
public ByteBuffer getAmazonCode(){

   return amazonClient.decryptAes([the encryption code that i got from amazon]);
}

so what is the appropriate responsebody to send the decryted bytebuffer so that my m3u8 can start playing by getting the decrypting data key from my endpoint?

1

There are 1 best solutions below

0
On BEST ANSWER

For anyone going through the same problems that I was,I have figured it out after a while, all I had to do was after getting the byteBuffer, convert it to an input stream and create a key file from it. and make it downloadable through the Licence acquisition URL. here is the code:

         @GetMapping(value = "amazoncode",produces = MediaType.APPLICATION_OCTET_STREAM)
public void getAmazonCode( HttpServletResponse response){
    response.setHeader("Content-Disposition", "attachment; filename=\"mmm.key\"");
    response.setContentType("application/key");
       //this will return the decrypted data key 
       ByteBuffer b =amazonClient.decryptAes([the encryption key]);
    InputStream targetStream = new ByteArrayInputStream(b.array());
    try {
        IOUtils.copy(targetStream, response.getOutputStream());
    }catch (Exception e){
        System.out.println(e);
    }

and now it works like a charm.