本文实例为大家分享了基于springboot和redis实现单点登录的具体代码,供大家参考,具体内容如下
1、具体的加密和解密方法
package com.example.demo.util;
import com.google.common.base.Strings;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;
import java.security.SecureRandom;
/**
* Create by zhuenbang on 2018/12/3 11:27
*/
public class AESUtil {
private static final String defaultKey = "7bf72345-6266-4381-a4d3-988754c5f9d1";
/**
* @Description: 加密
* @Param:
* @returns: java.lang.String
* @Author: zhuenbang
* @Date: 2018/12/3 11:33
*/
public static String encryptByDefaultKey(String content) throws Exception {
return encrypt(content, defaultKey);
}
/**
* @Description: 解密
* @Param:
* @returns: java.lang.String
* @Author: zhuenbang
* @Date: 2018/12/3 11:30
*/
public static String decryptByDefaultKey(String encryptStr) throws Exception {
return decrypt(encryptStr, defaultKey);
}
/**
* AES加密为base 64 code
*
* @param content 待加密的内容
* @param encryptKey 加密密钥
* @return 加密后的base 64 code
* @throws Exception
*/
public static String encrypt(String content, String encryptKey) throws Exception {
return base64Encode(aesEncryptToBytes(content, encryptKey));
}
/**
* AES加密
*
* @param content 待加密的内容