Search in sources :

Example 1 with KeyValueWrapper

use of com.acgist.snail.pojo.wrapper.KeyValueWrapper in project snail by acgist.

the class M3u8Builder method buildCipher.

/**
 * <p>新建加密套件</p>
 *
 * @return 加密套件
 *
 * @throws NetException 网络异常
 */
private Cipher buildCipher() throws NetException {
    final var optional = this.labels.stream().filter(label -> LABEL_EXT_X_KEY.equalsIgnoreCase(label.getName())).findFirst();
    if (optional.isEmpty()) {
        // 没有加密标签:不用解密
        return null;
    }
    final KeyValueWrapper wrapper = optional.get().attrs();
    final String method = wrapper.getIgnoreCase(ATTR_METHOD);
    final M3u8.Protocol protocol = M3u8.Protocol.of(method);
    LOGGER.debug("HLS加密算法:{}", method);
    if (protocol == null || protocol == M3u8.Protocol.NONE) {
        throw new NetException("不支持的HLS加密算法:" + method);
    }
    if (protocol == M3u8.Protocol.AES_128) {
        return this.buildCipherAes128(wrapper.getIgnoreCase(ATTR_IV), wrapper.getIgnoreCase(ATTR_URI));
    } else {
        throw new NetException("不支持的HLS加密算法:" + method);
    }
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) Cipher(javax.crypto.Cipher) SymbolConfig(com.acgist.snail.config.SymbolConfig) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) ArrayList(java.util.ArrayList) UrlUtils(com.acgist.snail.utils.UrlUtils) IvParameterSpec(javax.crypto.spec.IvParameterSpec) NetException(com.acgist.snail.context.exception.NetException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) LoggerFactory(com.acgist.snail.logger.LoggerFactory) M3u8(com.acgist.snail.pojo.bean.M3u8) StringUtils(com.acgist.snail.utils.StringUtils) Type(com.acgist.snail.pojo.bean.M3u8.Type) Files(java.nio.file.Files) Logger(com.acgist.snail.logger.Logger) IOException(java.io.IOException) CollectionUtils(com.acgist.snail.utils.CollectionUtils) Collectors(java.util.stream.Collectors) DownloadException(com.acgist.snail.context.exception.DownloadException) File(java.io.File) List(java.util.List) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyValueWrapper(com.acgist.snail.pojo.wrapper.KeyValueWrapper) InvalidKeyException(java.security.InvalidKeyException) HttpClient(com.acgist.snail.net.http.HttpClient) KeyValueWrapper(com.acgist.snail.pojo.wrapper.KeyValueWrapper) NetException(com.acgist.snail.context.exception.NetException) M3u8(com.acgist.snail.pojo.bean.M3u8)

Aggregations

SymbolConfig (com.acgist.snail.config.SymbolConfig)1 DownloadException (com.acgist.snail.context.exception.DownloadException)1 NetException (com.acgist.snail.context.exception.NetException)1 Logger (com.acgist.snail.logger.Logger)1 LoggerFactory (com.acgist.snail.logger.LoggerFactory)1 HttpClient (com.acgist.snail.net.http.HttpClient)1 M3u8 (com.acgist.snail.pojo.bean.M3u8)1 Type (com.acgist.snail.pojo.bean.M3u8.Type)1 KeyValueWrapper (com.acgist.snail.pojo.wrapper.KeyValueWrapper)1 CollectionUtils (com.acgist.snail.utils.CollectionUtils)1 StringUtils (com.acgist.snail.utils.StringUtils)1 UrlUtils (com.acgist.snail.utils.UrlUtils)1 File (java.io.File)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1