$mezzanineFileName = "Azure-Video.wmv"; $tokenRestriction = true; $tokenType = TokenType::JWT; print "Azure SDK for PHP - AES Dynamic Encryption Sample\r\n"; // 0 - set up the MediaServicesService object to call into the Media Services REST API. $restProxy = ServicesBuilder::getInstance()->createMediaServicesService(new MediaServicesSettings($account, $secret)); // 1 - Upload the mezzanine $sourceAsset = uploadFileAndCreateAsset($restProxy, $mezzanineFileName); // 2 - encode the output asset $encodedAsset = encodeToAdaptiveBitrateMP4Set($restProxy, $sourceAsset); // 3 - Create Content Key $contentKey = createEnvelopeTypeContentKey($restProxy, $encodedAsset); // 4 - Create the ContentKey Authorization Policy $tokenTemplateString = null; if ($tokenRestriction) { $tokenTemplateString = addTokenRestrictedAuthorizationPolicy($restProxy, $contentKey, $tokenType); } else { addOpenAuthorizationPolicy($restProxy, $contentKey); } // 5 - Create the AssetDeliveryPolicy createAssetDeliveryPolicy($restProxy, $encodedAsset, $contentKey); // 6 - Publish publishEncodedAsset($restProxy, $encodedAsset); // 7 - Generate Test Token if ($tokenRestriction) { generateTestToken($tokenTemplateString, $contentKey); } // Done print "Done!"; //////////////////// // Helper methods //
$fairPlayPFXFile = '<path to the pfx file>'; $fairPlayPFXPassword = '******'; $fairPlayIV = bin2hex(openssl_random_pseudo_bytes(16)); echo "Azure SDK for PHP - FairPlay Dynamic Encryption Sample" . PHP_EOL; // 0 - set up the MediaServicesService object to call into the Media Services REST API. $restProxy = ServicesBuilder::getInstance()->createMediaServicesService(new MediaServicesSettings($account, $secret)); // 1 - Upload the mezzanine $sourceAsset = uploadFileAndCreateAsset($restProxy, $mezzanineFileName); // 2 - encode the output asset $encodedAsset = encodeToAdaptiveBitrateMP4Set($restProxy, $sourceAsset); // 3 - Create Content Key $contentKey = createCommonCBCTypeContentKey($restProxy, $encodedAsset); // 4 - Create the ContentKey Authorization Policy $tokenTemplateString = null; if ($tokenRestriction) { $tokenTemplateString = addTokenRestrictedAuthorizationPolicy($restProxy, $contentKey, $tokenType, $fairPlayASK, $fairPlayPFXPassword, $fairPlayPFXFile, $fairPlayIV); } else { addOpenAuthorizationPolicy($restProxy, $contentKey, $fairPlayASK, $fairPlayPFXPassword, $fairPlayPFXFile, $fairPlayIV); } // 5 - Create the AssetDeliveryPolicy createAssetDeliveryPolicy($restProxy, $encodedAsset, $contentKey, $fairPlayIV); // 6 - Publish publishEncodedAsset($restProxy, $encodedAsset); // 7 - Generate Test Token if ($tokenRestriction) { generateTestToken($tokenTemplateString, $contentKey); } // Done echo "Done!"; //////////////////// // Helper methods //
function applyAesDynamicEncryption($restProxy, $asset, $options) { $testToken = null; // 1 - Create Content Key $contentKey = createEnvelopeTypeContentKey($restProxy, $asset); // 2 - Create the ContentKey Authorization Policy and Options if ($options->tokenRestriction) { // 2.1 - Apply Token restriction $template = addTokenRestrictedAuthorizationPolicy($restProxy, $contentKey, $options->tokenType); // 2.2 - Generate Test Token $testToken = generateTestToken($template, $contentKey); } else { // 2.1 - Apply Open restriction addOpenAuthorizationPolicy($restProxy, $contentKey); } // 3 - Create the AssetDeliveryPolicy createAssetDeliveryPolicy($restProxy, $asset, $contentKey); return $testToken; }