-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAESTester.java
More file actions
56 lines (46 loc) · 1.78 KB
/
AESTester.java
File metadata and controls
56 lines (46 loc) · 1.78 KB
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
package wolf.com.github.myjava;
import org.junit.jupiter.api.Test;
import wolf.com.github.myjava.common.AESUtils;
import wolf.com.github.myjava.common.Base64Utils;
public class AESTester {
static String key;
static {
try {
//key = "3HBhJdf1e989mQYGW3Sdiw==";
key = "ZyZXJEyouSqVUcBqhjNh515fLeni09z90EW/i9WuOXc=";
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void encrypt() throws Exception {
long begin = System.currentTimeMillis();
// 加密
// encryptFile();
// 解密
decryptFile();
//test();
long end = System.currentTimeMillis();
System.err.println("耗时:" + (end-begin) + "ms");
}
static void decryptFile() throws Exception {
String sourceFilePath = "/Users/huangjiang/Downloads/common-2.encrypt";
String destFilePath = "common-128.zip";
AESUtils.decryptFile(key, sourceFilePath, destFilePath);
}
static void encryptFile() throws Exception {
String sourceFilePath = "common-2.zip";
String destFilePath = "/Users/huangjiang/Downloads/common-2.encrypt";
AESUtils.encryptFile(key, sourceFilePath, destFilePath);
}
static void test() throws Exception {
String source = "这是一行测试DES加密/解密的文字,你看完也等于没看,是不是啊?!";
System.err.println("原文:\t" + source);
byte[] inputData = source.getBytes();
inputData = AESUtils.encrypt(inputData, key);
System.err.println("加密后:\t" + Base64Utils.encode(inputData));
byte[] outputData = AESUtils.decrypt(inputData, key);
String outputStr = new String(outputData);
System.err.println("解密后:\t" + outputStr);
}
}