Clean up Aes128DataSource.
This commit is contained in:
parent
6bf52dd69c
commit
38efb1fc3f
@ -474,7 +474,7 @@ public class HlsChunkSource {
|
|||||||
System.arraycopy(ivData, offset, ivDataWithPadding, ivDataWithPadding.length - ivData.length
|
System.arraycopy(ivData, offset, ivDataWithPadding, ivDataWithPadding.length - ivData.length
|
||||||
+ offset, ivData.length - offset);
|
+ offset, ivData.length - offset);
|
||||||
|
|
||||||
encryptedDataSource = new Aes128DataSource(secretKey, ivDataWithPadding, upstreamDataSource);
|
encryptedDataSource = new Aes128DataSource(upstreamDataSource, secretKey, ivDataWithPadding);
|
||||||
encryptionKeyUri = keyUri;
|
encryptionKeyUri = keyUri;
|
||||||
encryptedDataSourceIv = iv;
|
encryptedDataSourceIv = iv;
|
||||||
encryptedDataSourceSecretKey = secretKey;
|
encryptedDataSourceSecretKey = secretKey;
|
||||||
|
@ -34,20 +34,24 @@ import javax.crypto.spec.SecretKeySpec;
|
|||||||
/**
|
/**
|
||||||
* A {@link DataSource} that decrypts the data read from an upstream source, encrypted with AES-128
|
* A {@link DataSource} that decrypts the data read from an upstream source, encrypted with AES-128
|
||||||
* with a 128-bit key and PKCS7 padding.
|
* with a 128-bit key and PKCS7 padding.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class Aes128DataSource implements DataSource {
|
public class Aes128DataSource implements DataSource {
|
||||||
|
|
||||||
private final DataSource upstream;
|
private final DataSource upstream;
|
||||||
private final byte[] secretKey;
|
private final byte[] encryptionKey;
|
||||||
private final byte[] iv;
|
private final byte[] encryptionIv;
|
||||||
|
|
||||||
private CipherInputStream cipherInputStream;
|
private CipherInputStream cipherInputStream;
|
||||||
|
|
||||||
public Aes128DataSource(byte[] secretKey, byte[] iv, DataSource upstream) {
|
/**
|
||||||
|
* @param upstream The upstream {@link DataSource}.
|
||||||
|
* @param encryptionKey The encryption key.
|
||||||
|
* @param encryptionIv The encryption initialization vector.
|
||||||
|
*/
|
||||||
|
public Aes128DataSource(DataSource upstream, byte[] encryptionKey, byte[] encryptionIv) {
|
||||||
this.upstream = upstream;
|
this.upstream = upstream;
|
||||||
this.secretKey = secretKey;
|
this.encryptionKey = encryptionKey;
|
||||||
this.iv = iv;
|
this.encryptionIv = encryptionIv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,8 +65,8 @@ public class Aes128DataSource implements DataSource {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Key cipherKey = new SecretKeySpec(secretKey, "AES");
|
Key cipherKey = new SecretKeySpec(encryptionKey, "AES");
|
||||||
AlgorithmParameterSpec cipherIV = new IvParameterSpec(iv);
|
AlgorithmParameterSpec cipherIV = new IvParameterSpec(encryptionIv);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherIV);
|
cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherIV);
|
||||||
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
|||||||
/**
|
/**
|
||||||
* Thrown when the length of some data does not match an expected length.
|
* Thrown when the length of some data does not match an expected length.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public final class UnexpectedLengthException extends IOException {
|
public final class UnexpectedLengthException extends IOException {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user