全部产品
媒体转码

hls数据加密

更新时间:2017-09-18 20:06:57   分享:   

适应场景
  • hls标准数据加密适用于“对视频进行简单的保护”的,可以简单的防止非法下载和非法传播
  • 如果对安全有强需求,请开启工作流中的数据加密
使用限制
  • hls标准数据加密需要使用SubmitJobs接口,工作流中不可使用
示例代码依赖

1、MTS SDK 点击查看

2、其他依赖

  1. <dependency>
  2. <groupId>com.alibaba</groupId>
  3. <artifactId>fastjson</artifactId>
  4. <version>1.2.25</version
  5. </dependency>
  6. <dependency>
  7. <groupId>commons-codec</groupId>
  8. <artifactId>commons-codec</artifactId>
  9. <version>1.9</version>
  10. </dependency>
  1. package com.aliyun
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.aliyuncs.DefaultAcsClient;
  5. import com.aliyuncs.exceptions.ClientException;
  6. import com.aliyuncs.mts.model.v20140618.QueryJobListRequest;
  7. import com.aliyuncs.mts.model.v20140618.QueryJobListResponse;
  8. import com.aliyuncs.mts.model.v20140618.SubmitJobsRequest;
  9. import com.aliyuncs.mts.model.v20140618.SubmitJobsResponse;
  10. import com.aliyuncs.profile.DefaultProfile;
  11. import org.apache.commons.codec.binary.Base64;
  12. public class DataEncryptionDemo {
  13. private DefaultAcsClient client = null;
  14. private final String REGION = "cn-shanghai"; //按需配置
  15. private final String MTS_ENDPOINT = "mts.cn-shanghai.aliyuncs.com"; //按需配置
  16. private final String ID="idid"; //按需配置
  17. private final String KEY ="keykey"; //按需配置
  18. private final String LOCATION = "oss-cn-shanghai"; //按需配置
  19. private final String INPUT_BUCKET = "input-bucket"; //按需配置
  20. private final String OUTPUT_BUCKET = "output-bucket"; //按需配置
  21. private final String PIPELINE_ID = "pipelineId"; //按需配置
  22. public DataEncryptionDemo() throws ClientException {
  23. DefaultProfile.addEndpoint(REGION, REGION, "Mts", MTS_ENDPOINT);
  24. this.client = new DefaultAcsClient(DefaultProfile.getProfile(REGION, ID, KEY));
  25. }
  26. private JSONObject getInputFile() {
  27. JSONObject inputFile = new JSONObject();
  28. inputFile.put("Location", LOCATION);
  29. inputFile.put("Bucket", INPUT_BUCKET);
  30. inputFile.put("Object", "uploadvideo/test.flv");
  31. return inputFile;
  32. }
  33. private JSONArray getOutputs() {
  34. JSONArray outputs = new JSONArray();
  35. outputs.add(getOutput());
  36. return outputs;
  37. }
  38. private JSONObject getOutput() {
  39. JSONObject output = new JSONObject();
  40. output.put("OutputObject", "BaseTest/hls-encryption.m3u8");
  41. output.put("TemplateId", "S00000001-100020");
  42. output.put("Encryption", getEncryptionConfigs());
  43. return output;
  44. }
  45. private JSONObject getEncryptionConfigs() {
  46. JSONObject encryption = new JSONObject();
  47. encryption.put("Type", "hls-aes-128");
  48. encryption.put("Key", Base64.encodeBase64URLSafeString("encryptionkey123".getBytes()));
  49. encryption.put("KeyUri", Base64.encodeBase64URLSafeString("http://demo.aliyuncs.com/document/hls128.key".getBytes()));
  50. encryption.put("KeyType", "Base64");
  51. return encryption;
  52. }
  53. private String submitJobs() throws ClientException {
  54. JSONObject inputFile = getInputFile();
  55. SubmitJobsRequest request = new SubmitJobsRequest();
  56. request.setInput(inputFile.toJSONString());
  57. request.setOutputLocation(LOCATION);
  58. request.setOutputBucket(OUTPUT_BUCKET);
  59. request.setOutputs(getOutputs().toJSONString());
  60. request.setPipelineId(PIPELINE_ID);
  61. SubmitJobsResponse reponse = this.client.getAcsResponse(request);
  62. System.out.println(JSONObject.toJSONString(reponse.getJobResultList()));
  63. return reponse.getJobResultList().get(0).getJob().getJobId();
  64. }
  65. public static void main(String[] args) throws ClientException {
  66. DataEncryptionDemo demo = new DataEncryptionDemo();
  67. String jobId= demo.submitJobs();
  68. }
  69. }
本文导读目录
本文导读目录
以上内容是否对您有帮助?