google / google/ExoPlayer

Specific DataSource for key requests with HLS (AES-128)

Open
#9,816 3 comments 0 reactions 1 assignee Claimed by @marcbaechinger View on GitHub
question
Dominant language
Java
Stars
21.9k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

I have a problem trying to play HLS-AES 128 encrypted video.

```
>#EXTM3U
>#EXT-X-VERSION:3
>#EXT-X-MEDIA-SEQUENCE:84497
>#EXT-X-TARGETDURATION:4
>#EXT-X-KEY:METHOD=AES-128,URI="https://xxxxxxxx.xxx/videokey.php?e=wstream2&key=flowb27e3429c9a0072-84497.key",IV=0x00000000000000000000000000014A11
>#EXTINF:4.004,
>flowb27e3429c9a0072-84497.ts
>....
```

**The problem is that the encryptionKey obtained from the server is 17 bytes long. The last byte contains a newline character that needs to be removed to play correctly the video.**

>encryptionKey = [57, -112, 124, -11, -120, -3, -77, 53, 83, -78, -82, -44, 43, 43, -119, 4, 10]

It is also necessary to send two sets of headers, one for the m3u8 server and others for the key server

For this, I am using a customHttpDatasource.

```
CustomHttpDataSourceFactory dataSourceFactory = new CustomHttpDataSourceFactory(
UserAgent,
null,
CustomHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
CustomHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
true
requestPropertiesKeyServer, // request headers for key Server
proxy);
....
dataSourceFactory.getDefaultRequestProperties().set(mHeaders); // request headers for m3u8 server.

.....

mediaSource = new HlsMediaSource.Factory(dataSourceFactory)
.setMinLoadableRetryCount(3)
.setAllowChunklessPreparation(true)
.createMediaSource(uri);
```
> ...

```
player.prepare(mediaSource, true, false);
```

The problem now is how to obtain **the encryptionKey** and thus be able to eliminate that last byte with something like this:

```
byte[] b = Arrays.copyOfRange(encryptionKey, 0, 16);
cipherKey = new SecretKeySpec(b, "AES");
```

I hope someone can help me.
Thanks for your help.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.