long blogs

进一步有进一步惊喜


  • Home
  • Archive
  • Tags
  •  

© 2025 long

Theme Typography by Makito

Proudly published with Hexo

m3u8解码和合并工具

Posted at 2019-10-09 笔记 java 

AES-128解密函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* 解密文件
* @param sourcePath 源文件
* @param destinationPath 保存的文件
* @param key 密钥
*/
public static void decryptFile(String sourcePath,String destinationPath,String key) throws Exception {
File outFile = new File(destinationPath);
if (!outFile.exists()){
outFile.createNewFile();
}
// 待解密的文件输入流
FileInputStream fis = new FileInputStream(sourcePath);
FileOutputStream fos = new FileOutputStream(outFile);

Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
byte[] bytes = key.getBytes();
SecretKeySpec secretKey = new SecretKeySpec(bytes,"AES");
IvParameterSpec iv = new IvParameterSpec(key.getBytes());
cipher.init(Cipher.DECRYPT_MODE,secretKey,iv);
// 解密流
CipherInputStream cis = new CipherInputStream(fis,cipher);
byte[] buffer = new byte[1024];
int n = 0;
while ((n = cis.read(buffer)) != -1){
fos.write(buffer,0,n);
}
System.out.println("解密成功:");
cis.close();
fos.close();
}

主类

用来识别m3u8文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
public static void main(String[] args) {
String sourcePath ="G:\\win下载\\m3u8\\";
String destination = "G:\\win下载\\m3u8\\";
String m3u8 = "G:\\win下载\\m3u8\\m3u8.m3u8";
String key = "tkr87ysao6qehn95";
FileReader fileReader = null;
BufferedReader reader = null;
ArrayList<String> files = new ArrayList<>();
try{
fileReader = new FileReader(m3u8);
reader = new BufferedReader(fileReader);
String filename = null;
while (( filename = reader.readLine())!=null){
if(filename.charAt(0)!='#'){
files.add(filename);
}
}
if(fileReader!=null){
fileReader.close();
}
if(reader!=null){
reader.close();
}
}catch (IOException e){
e.printStackTrace();
}

int partSize = files.size();
String sourceFile;
String destFile;
try{
for(int i=0;i < partSize ;i++){
sourceFile = sourcePath + files.get(i);
destFile = destination + "e"+files.get(i);
EncryFileUtil.decryptFile(sourceFile,destFile,key);
}
System.out.println("========全部解密成功============");
}catch (Exception e){
e.printStackTrace();
}
try {
// 合并数据
String mergeFilePath = sourcePath+"merge.ts";
FileOutputStream mergeFile = new FileOutputStream(mergeFilePath);
for (int i=0;i<partSize;i++){
String encodeFile = sourcePath +"e"+files.get(i);
FileInputStream inputStream = new FileInputStream(encodeFile);
byte[] buffer = new byte[1024];
int n=0;
while ((n = inputStream.read(buffer))!= -1){
mergeFile.write(buffer,0,n);
}
inputStream.close();
}
System.out.println("合并数据成功");
}catch (IOException e){
e.printStackTrace();
}
}

Share 

 Previous post: book118预览文档下载 Next post: blibli动态9宫格图片下载脚本 

© 2025 long

Theme Typography by Makito

Proudly published with Hexo