liujie
2025-05-09 fdec3aa2487acee81ebc80aba88852f0f5036ef4
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
package com.stylefeng.guns.shiro;
 
import org.springframework.util.Base64Utils;
 
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
 
public class Base64Test {
 
    /**
     * Shiro 记住密码采用的是AES加密,AES key length 需要是16位,该方法生成16位的key
     */
    public static void main(String[] args) {
        
        String keyStr = "guns";
        
        byte[] keys;
        try {
            keys = keyStr.getBytes("UTF-8");
            System.out.println(Base64Utils.encodeToString(Arrays.copyOf(keys, 16)));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        
    }
 
}