File tree Expand file tree Collapse file tree
src/main/java/io/github/talelin/latticy/common/configuration Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import io .github .talelin .latticy .common .util .CaptchaUtil ;
44import lombok .Getter ;
55import lombok .Setter ;
6+ import lombok .extern .slf4j .Slf4j ;
67import org .springframework .boot .context .properties .ConfigurationProperties ;
78import org .springframework .stereotype .Component ;
9+ import org .springframework .util .StringUtils ;
810
911/**
1012 * @author Gadfly
1113 */
14+ @ Slf4j
1215@ Getter
1316@ Setter
1417@ Component
@@ -17,13 +20,38 @@ public class LoginCaptchaProperties {
1720 /**
1821 * aes 密钥
1922 */
20- private String secret = CaptchaUtil . getRandomString ( 32 ) ;
23+ private String secret ;
2124 /**
2225 * aes 偏移量
2326 */
24- private String iv = CaptchaUtil . getRandomString ( 16 ) ;
27+ private String iv ;
2528 /**
2629 * 启用验证码
2730 */
2831 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+
2957}
You can’t perform that action at this time.
0 commit comments