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
use base64::Engine;
use base64::engine::general_purpose::STANDARD;
use log::info;

/// 加密-Base64URL
pub fn encode(string: String) -> String {
    STANDARD.encode(string)
}
/// 加密-Base64URL
pub fn url_encode(string: String) -> String {
    let base64 = STANDARD.encode(string);
    let base64 = base64.replace("=", "*");
    let base64 = base64.replace("+", "-");
    let base64 = base64.replace("/", "_");
    base64
}
/// 解密
pub fn decode(base64: String) -> String {
    if base64.is_empty() {
        return "".to_string();
    }
    match STANDARD.decode(base64.clone()) {
        Ok(e) => {
            let tt = String::from_utf8_lossy(&*e);
            tt.to_string()
        }
        Err(e) => {
            info!("{}", e);
            return base64;
        }
    }
}
/// url解密
pub fn url_decode(base64: String) -> String {
    let base64 = base64.replace("*", "=");
    let base64 = base64.replace("-", "+");
    let base64 = base64.replace("_", "/");
    if base64.is_empty() {
        return "".to_string();
    }
    match STANDARD.decode(base64.clone()) {
        Ok(e) => {
            let tt = String::from_utf8_lossy(&*e);
            tt.to_string()
        }
        Err(e) => {
            info!("{}", e);
            return base64;
        }
    }
}