Apache Shiro使用官方自带的生成AES密钥

 

 

 

package test;

import org.apache.shiro.codec.Base64;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.security.NoSuchAlgorithmException;

public class Test {
	public static void main(String[] args) {
		KeyGenerator keygen = null;
		try {
			keygen = KeyGenerator.getInstance("AES");
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		SecretKey deskey = keygen.generateKey();
		System.out.println(Base64.encodeToString(deskey.getEncoded()));
	}
}

  

posted @ 2020-03-13 12:58  yvioo  阅读(7133)  评论(0编辑  收藏  举报