Couple of concerns - You are using the old legacy v2 REST API which is on the deprecation path. That will only be supported until Feb 29th 2024 and then shuts off completely.
If you are building a new solution, switch to the v3 API.
The v3 API should be used from one of our supported client language SDKS and not via REST directly if you can avoid it.
In v3, there is now only contentKeyPolicies and StreamingPolicies
https://learn.microsoft.com/en-us/azure/media-services/latest/drm-content-key-policy-concep t
https://learn.microsoft.com/en-us/azure/media-services/latest/stream-streaming-policy-concept
https://learn.microsoft.com/en-us/azure/media-services/latest/drm-fairplay-license-overview
There are two ways for protecting a content in v3:
- Simpler but less flexible approach: use AMS v3 internally generated content key, and AMS built-in StreamingPolicy. This approach does not allow us to use our “pre-specified” content key with IV. So you may not be able to use this approach.
- More flexible approach: Use a custom StreamingPolicy and StreamingLocator so that you can use our “pre-specified” content key. You might need to use this approach. This does require more code since you need to use the specified content key.
Create IV for each content key.
The content key can be generated in any way you prefer: with or without key seed, if with key seed: either fixed or random. After a content key is created, you specify its IV in the following way:
IV = GetIVFromKIDString(keyId.ToString())
public static byte[] StringToByteArray(string hex)
{
int numberChars = hex.Length;
byte[] bytes = new byte[numberChars / 2];
for (int i = 0; i < numberChars; i += 2)
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
return bytes;
}
//currently IV=KID and is not exposed via API
public static string GetIVFromKIDString(string kid)
{
Guid guid = Guid.Parse(kid);
return Convert.ToBase64String(StringToByteArray(guid.ToString().Replace("-", string.Empty)));
}
Couple more things..
- The CustomLicenseAcquisitionUrlTemplate API allows you to define the custom LA_URL template instead of actual value. The template variable is {ContentKeyId} for content key ID. For example: http://use2-2.api.microsoftstream.come/videos/video01/ProtectionKey?kid={ContentKeyId}. In this way, you can use a single StreamingPolicy for many assets instead of one for each asset. Therefore you do not need to increase the quota on your account if you have a lot of assets.
- In general, you should use a single set of ContentKeyPolicy and StreamingPolicy for many assets (a type of assets) for better scalability. So that ContentKeyPolicy and StreamingPolicy are cached and reused across many assets.
UPDATED: Finally, I think this was your solution:
We looked into the specific failure for the request ID you shared and it is because the content IV is malformed. This may be because you are mixing V2 and V3 usage (portal uses V3 API). If you use V2 only please ensure that your IV is a hex string.