MainController.java
1.22 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
package com.viontech.domain;
import cn.hutool.core.io.FileUtil;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
@RestController
public class MainController {
@Resource
private StringEncryptor stringEncryptor;
@RequestMapping(value = "/encrypt/{value}", method = RequestMethod.GET)
@ResponseBody
public String encrypt(@PathVariable("value") String value) throws IOException {
String path;
String encrypt = "ENC(" + this.stringEncryptor.encrypt(value) + ")\n";
try {
path = ResourceUtils.getFile("").getAbsolutePath();
} catch (FileNotFoundException e) {
e.printStackTrace();
path = System.getProperty("java.io.tmpdir");
}
File file = new File(path + "\\result.txt");
// 明文和加密后的内容写入文件
FileUtil.writeLines(Arrays.asList(value, encrypt), file, StandardCharsets.UTF_8, true);
return "文件写入成功";
}
}