forked from hellokaton/write-readable-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample6.java
More file actions
50 lines (39 loc) · 1.09 KB
/
Copy pathExample6.java
File metadata and controls
50 lines (39 loc) · 1.09 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
package chapter_11;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
/**
* 按需重构接口
*
* @author biezhi
* @date 2018/8/13
*/
public class Example6 {
class Cipher {
String method;
String key;
public Cipher(String method, String key) {
this.method = method;
this.key = key;
}
public byte[] update(String str) {
return str.getBytes();
}
}
private String toJson(Map<String, String> map) {
return null;
}
public void foo() {
Map<String, String> map = new HashMap<>();
map.put("username", "biezhi");
map.put("password", "123456");
String url = "http://exmaple.com/?user_info=" + urlSafeEncrypt(map);
// ...
}
private String urlSafeEncrypt(Map<String, String> map){
String json = toJson(map);
Cipher cipher = new Cipher("aes_256", "pas5#w0rd");
byte[] encryptedBytes = cipher.update(json);
return Base64.getEncoder().encodeToString(encryptedBytes);
}
}