Upload encrypted assets
Learn how to upload and play back an encrypted video asset
Livepeer enables you to upload encrypted video content or import it from decentralized storages. It creates a playback URL that can have independent access control through Livepeer’s access control feature.
This guide is written for developers using JavaScript, but the concepts can be applied to any language.
Generate an encryption key
First, we generate a 256-bit encryption key to encrypt the file.
Encrypt your video
To encrypt a video file with the key we just generated, we follow these steps:
- Generate a random 128-bit initialization vector (IV).
- Pad the data using PKCS#7 padding.
- Encrypt the data using AES-CBC.
Currently Livepeer supports only video content encrypted using
SubtleCrypto.encrypt
with AES-CBC
algorithm, which is also the encryption used by other web3
protocols like
Lit. It can
implemented in other environments with regular AES-CBC encryption using PKCS#7
padding.
Retrieve the Livepeer Public Key
After obtaining an encryption key and encrypting a video file with it, the next step is to retrieve the Livepeer Public Key. This key will be used to encrypt our encryption key, which can then be shared with Livepeer when creating a video asset.
Encrypt the encryption key
Now, we can use asymmetric encryption with the Livepeer Public Key to encrypt our Encryption Key. The resulting data is then encoded in base64 before being sent to Livepeer along with the video file.
The Web Cryptography API built into modern browsers does not directly support
PEM or PKCS#1 formatted keys. It only supports the SPKI format for public keys
and the PKCS8 format for private keys. In Javascript, you need to use the
spki_public_key
.
Upload/import the video file
When requesting an upload to the Livepeer API, you can simply
add an encryption
field with your
encrypted key.
When uploading an encrypted video, specifying a playbackPolicy
is required.
You can still specify the type of the playback policy as public
, but be
aware that anyone with the playbackId
or playbackUrl
would be able to
watch it.
Was this page helpful?