P15GEN2\59518
2025-10-10 9f6890646993d16260d4201d613c092132856127
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
51
52
53
54
55
56
57
58
59
60
61
62
63
package foundation.util;
 
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
 
import com.alibaba.druid.util.Base64;
 
public class EncipherUtil {
 
    public static String sha1Decode(String value) {
         String hashedData = null;
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-1");
            byte[] bytes = value.getBytes();
 
            digest.update(bytes);
            byte[] hashedBytes = digest.digest();
 
            StringBuilder hexString = new StringBuilder();
            for (byte b : hashedBytes) {
                String hex = Integer.toHexString(0xFF & b);
                if (hex.length() == 1) {
                    hexString.append('0');
                }
                hexString.append(hex);
            }
 
            hashedData = hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        
        return hashedData;
    }
     
     public static String encode(String value) {
        if (Util.isEmpty(value)) {
            return value;
        }
        
        if (value.startsWith("H") && value.endsWith("DS")) {
            return value;
        }
        
        value = Base64.byteArrayToBase64(value.getBytes());
        return "H" + value + "DS";
    }
        
    public static String decode(String value) {
        if (Util.isEmpty(value)) {
            return value;
        }
        
        if (!value.startsWith("H") || !value.endsWith("DS")) {
            return value;
        }
        
        value = value.substring(1, value.length() - 2);
        value = new String(Base64.base64ToByteArray(value));
        
        return value;
    }
}