WangHan
2025-04-02 a8ba678a3fe5a39da2c732014cebbb66e408e97c
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
package com.iplatform.core.config.enc;
 
public class EncryptionWrapperDetector {
 
    private final String prefix;
 
    private final String suffix;
 
    public EncryptionWrapperDetector(String prefix, String suffix) {
        this.prefix = prefix;
        this.suffix = suffix;
    }
 
    /**
     * 检测配置参数值,是否带有加密前缀,如果是返回:true
     * @param property
     * @return
     */
    public boolean detected(String property) {
        return property != null && property.startsWith(prefix) && property.endsWith(suffix);
    }
 
    /**
     * 把属性值包装上加密函数
     * @param property
     * @return
     */
    public String wrapper(String property) {
        return prefix + property + suffix;
    }
 
    /**
     * 去掉加密函数,返回密文内容。
     * @param property
     * @return
     */
    public String unWrapper(String property) {
        return property.substring(prefix.length(), property.length() - suffix.length());
    }
}