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
60
61
62
package cn.wisenergy.chnmuseum.party.common.video;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@Slf4j
public class VideoTestUtil {
private static final String plainFilePath = "D:\\200.tmp\\";
//此为AES128位,如果要求AES256位,需要更新jdk内的包,jdk8发布版本默认不支持
private static final String cipher = "3348c95c60520be7";
private static final int dataLength = 4096;
public static void main(String[] args) {
//加密视频
new Thread(() -> {
try {
log.info("开始加解密");
File f = new File(plainFilePath, "中华人民共和国成立.mp4");
FileInputStream fis = new FileInputStream(f);
File encryptFile = new File(plainFilePath, "中华人民共和国成立.chnmuseum");
AesCipherDataSink encryptingDataSink = new AesCipherDataSink(
"3348c95c60520be7".getBytes(StandardCharsets.UTF_8),
new DataSink() {
private FileOutputStream fileOutputStream;
@Override
public void open() throws IOException {
fileOutputStream = new FileOutputStream(encryptFile);
}
@Override
public void write(byte[] buffer, int offset, int length) throws IOException {
fileOutputStream.write(buffer, offset, length);
}
@Override
public void close() throws IOException {
fileOutputStream.close();
}
});
encryptingDataSink.open();
int len;
byte[] buffer = new byte[dataLength];
while ((len = fis.read(buffer)) != -1) {
encryptingDataSink.write(buffer, 0, len);
}
encryptingDataSink.close();
fis.close();
log.info("加解密完成");
} catch (Exception e) {
log.info(e.getLocalizedMessage());
}
}).start();
}
}