Last update:2025-03-21 15:04:15
HLS AES encryption secures your video content during streaming by encrypting video segments using the Advanced Encryption Standard (AES-128) algorithm. This symmetric key encryption method uses the same key for both encryption (by the server) and decryption (by the viewer’s player).
When encrypted, your HLS playlist (m3u8 file) contains an EXT-X-KEY
tag that provides the necessary information for players to decrypt the content:
#EXT-X-KEY:METHOD=AES-128,URI="https://keypathURI/hls_aes.key",IV=0x00000000000000000000000000000000
During playback, the player first retrieves the decryption key from the URI specified in the playlist before it can begin decoding the video segments.
Before implementing HLS AES encryption, ensure:
To securely transmit the AES encryption key in API requests, you must encrypt it with RSA encryption. This involves generating a key pair and registering your private key with our system.
Run these commands to create RSA private and public keys:
# Generate private key (2048-bit)
openssl genrsa -out private.key 2048
# Extract public key from private key
openssl rsa -in private.key -pubout -out pub.key
Store both key files securely. The public key will encrypt your AES key, while the private key will be used by our backend to decrypt it.
When creating your encryption request, you’ll need to construct the fops
(file operation parameters) that include special encryption settings:
<op>/<Format>
/hlsKey/<hlsKey>
/hlsKeyUrl/<hlsKeyUrl>
|saveas/<Urlsafe_Base64_Encode(bucket:filekey)>
The hlsKey
is your AES encryption key that must be RSA-encrypted before inclusion in the API request:
Example with the AES key value 01234566543210abcdef888888abcdef
:
# Generate a random 16-byte hex key (if needed)
openssl rand -hex 16
# Encrypt your key with RSA-OAEP and encode it for API transmission
echo -n "01234566543210abcdef888888abcdef" | openssl rsautl -encrypt -pubin -inkey pub.key -oaep | openssl base64 -A | tr "+/" "-_"
The output string is your encrypted hlsKey
parameter value.
The hlsKeyUrl
specifies where players will retrieve the decryption key. You have two options:
To create a key file for option 2:
# Create a binary key file from your hex key
echo -ne "\x01\x23\x45\x66\x54\x32\x10\xab\xcd\xef\x88\x88\x88\xab\xcd\xef" > key.hex
After uploading this file to your bucket, use its accessible URL as the hlsKeyUrl
parameter, for example:
https://bucketname.s3-cn-north-1.wcsapi.com/key.hex
With your parameters prepared, you can now make the API request to encrypt your video content.
This example encrypts a video file named test_hls.m3u8
stored in the vod-wcs-test001
bucket:
curl -v -X POST \
-d "bucket=Urlsafe_Base64_Encode(vod-wcs-test001)&key=Urlsafe_Base64_Encode(test_hls.m3u8)&fops=Urlsafe_Base64_Encode(avthumb/m3u8/hlsKey/encrypted hlsKey/hlsKeyUrl/https://bucketname.s3-cn-north-1.wcsapi.com/key.hex|saveas/Urlsafe_Base64_Encode(vod-wcs-test001:hls_aes_.m3u8))&force=1&separate=1" \
-H "Authorization: AccessKey EncodeSign" \
--url "http://mgrDomain/fops"
When transcoding completes successfully, your encrypted video will be available in the designated bucket. The resulting HLS manifest (m3u8 file) will include the EXT-X-KEY
tag, indicating that the content is encrypted and providing the key location for players.