KeyAuthData.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. //-----------------------------------------------------------------------------
  3. // Copyright 2020-2021 RenderHeads Ltd. All rights reserved.
  4. //-----------------------------------------------------------------------------
  5. namespace RenderHeads.Media.AVProVideo
  6. {
  7. /// <summary>
  8. /// Data for handling authentication of encrypted AES-128 HLS streams
  9. /// </summary>
  10. [System.Serializable]
  11. public class KeyAuthData : ISerializationCallbackReceiver
  12. {
  13. public string keyServerToken = null;
  14. //public string keyServerURLOverride = null;
  15. [SerializeField, Multiline]
  16. private string overrideDecryptionKeyBase64 = null;
  17. public byte[] overrideDecryptionKey = null;
  18. public bool IsModified()
  19. {
  20. return (overrideDecryptionKey != null && overrideDecryptionKey.Length > 0)
  21. || (string.IsNullOrEmpty(overrideDecryptionKeyBase64) == false);
  22. }
  23. public void OnBeforeSerialize()
  24. {
  25. if (overrideDecryptionKey != null && !string.IsNullOrEmpty(overrideDecryptionKeyBase64))
  26. {
  27. overrideDecryptionKey = null;
  28. }
  29. }
  30. public void OnAfterDeserialize()
  31. {
  32. if (string.IsNullOrEmpty(overrideDecryptionKeyBase64))
  33. return;
  34. try
  35. {
  36. // Convert overrideDecryptionKeyBase64 to overrideDecryptionKey
  37. overrideDecryptionKey = System.Convert.FromBase64String(overrideDecryptionKeyBase64);
  38. }
  39. catch (System.FormatException e)
  40. {
  41. Debug.LogError("Failed to deserialize decryption key, error: " + e);
  42. overrideDecryptionKeyBase64 = null;
  43. overrideDecryptionKey = null;
  44. }
  45. }
  46. }
  47. }