Simplify encryption and decryption of downloaded content
- Dominant language
- Java
- Stars
- 21.9k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I am facing a issue while encryption and decryption of offline video.I am using the download manager and download tracker to download the offline video like in the demo app.
My code is as follows:
```
private static DataSource.Factory buildCacheDataSource(DefaultDataSourceFactory upstreamSource,
boolean useAesEncryption, Cache cache) {
final String secretKey = "XXXXXXXXX";
DataSource file = new FileDataSource();
DataSource cacheReadDataSource = useAesEncryption
? new AesCipherDataSource(Util.getUtf8Bytes(secretKey), file) : file;
// Sink and cipher
CacheDataSink cacheSink = new CacheDataSink(cache, Long.MAX_VALUE);
DataSink cacheWriteDataSink = useAesEncryption
? new AesCipherDataSink(Util.getUtf8Bytes(secretKey), cacheSink) : cacheSink;
return new DataSource.Factory() {
@Override
public DataSource createDataSource() {
DataSource dataSource = upstreamSource.createDataSource();
// Wrap the DataSource from the regular factory. This will read media from the cache when
// available, with the AesCipherDataSource element in the chain performing decryption. When
// not available media will be read from the wrapped DataSource and written into the cache,
// with AesCipherDataSink performing encryption.
return new CacheDataSource(cache,
dataSource,
cacheReadDataSource,
cacheWriteDataSink,
0,
null); // eventListener
}
};
```
I call the above method while creating the datasource factory
```
public DataSource.Factory buildDataSourceFactoryCache() {
DefaultDataSourceFactory upstreamFactory =
new DefaultDataSourceFactory(this, buildHttpDataSourceFactory());
return buildCacheDataSource(upstreamFactory, true,getDownloadCache());
}
```
I call the method buildDataSourceFactoryCache in initdownload manager,
```
private synchronized void initDownloadManager() {
if (downloadManager == null) {
DownloaderConstructorHelper downloaderConstructorHelper =
new DownloaderConstructorHelper(getDownloadCache(), buildDataSourceFactoryCache());
downloadManager =
new DownloadManager(
downloaderConstructorHelper,
MAX_SIMULTANEOUS_DOWNLOADS,
DownloadManager.DEFAULT_MIN_RETRY_COUNT,
new File(getDownloadFileDirectory(), DOWNLOAD_ACTION_FILE));
downloadTracker =
new DownloadTracker(
/* context= */ this,
buildDataSourceFactoryCache(),
new File(getDownloadFileDirectory(), DOWNLOAD_TRACKER_ACTION_FILE));
downloadManager.addListener(downloadTracker);
}
}
```
My download does not take place it shows as download failed.Can anyone tell me where i am going wrong
Contributor guide
Assessment
This issue has not been assessed yet.