File tree Expand file tree Collapse file tree 1 file changed +30
-2
lines changed
src/main/java/io/github/talelin/latticy/common/configuration Expand file tree Collapse file tree 1 file changed +30
-2
lines changed Original file line number Diff line number Diff line change 3
3
import io .github .talelin .latticy .common .util .CaptchaUtil ;
4
4
import lombok .Getter ;
5
5
import lombok .Setter ;
6
+ import lombok .extern .slf4j .Slf4j ;
6
7
import org .springframework .boot .context .properties .ConfigurationProperties ;
7
8
import org .springframework .stereotype .Component ;
9
+ import org .springframework .util .StringUtils ;
8
10
9
11
/**
10
12
* @author Gadfly
11
13
*/
14
+ @ Slf4j
12
15
@ Getter
13
16
@ Setter
14
17
@ Component
@@ -17,13 +20,38 @@ public class LoginCaptchaProperties {
17
20
/**
18
21
* aes 密钥
19
22
*/
20
- private String secret = CaptchaUtil . getRandomString ( 32 ) ;
23
+ private String secret ;
21
24
/**
22
25
* aes 偏移量
23
26
*/
24
- private String iv = CaptchaUtil . getRandomString ( 16 ) ;
27
+ private String iv ;
25
28
/**
26
29
* 启用验证码
27
30
*/
28
31
private Boolean enabled = Boolean .FALSE ;
32
+
33
+ public void setSecret (String secret ) {
34
+ this .secret = CaptchaUtil .getRandomString (32 );
35
+ if (StringUtils .hasText (secret )) {
36
+ byte [] bytes = secret .getBytes ();
37
+ if (bytes .length == 16 || bytes .length == 24 || bytes .length == 32 ) {
38
+ this .secret = secret ;
39
+ } else {
40
+ log .warn ("AES密钥必须为128/192/256bit,输入的密钥为{}bit,已启用随机密钥{}" , bytes .length * 8 , this .secret );
41
+ }
42
+ }
43
+ }
44
+
45
+ public void setIv (String iv ) {
46
+ this .iv = CaptchaUtil .getRandomString (16 );
47
+ if (StringUtils .hasText (iv )) {
48
+ byte [] bytes = iv .getBytes ();
49
+ if (bytes .length == 16 ) {
50
+ this .iv = iv ;
51
+ } else {
52
+ log .warn ("AES初始向量必须为128bit,输入的密钥为{}bit,已启用随机向量{}" , bytes .length * 8 , this .iv );
53
+ }
54
+ }
55
+ }
56
+
29
57
}
You can’t perform that action at this time.
0 commit comments