| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package cn.com.goldenwater.dcproj.utils;
- import org.springframework.util.Base64Utils;
- import javax.crypto.Cipher;
- import javax.crypto.KeyGenerator;
- import javax.crypto.SecretKey;
- import java.net.URLDecoder;
- import java.nio.charset.StandardCharsets;
- import java.security.SecureRandom;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * @author rf
- * @version 1.0
- * @date 2021-1-15 15:16
- */
- public class DecryptUtil {
- private final static String KEY = "}a?7_sa@KXE>NV%@";
- public static Map<String, String> decrypt(String accessId) throws Exception {
- final KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
- SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
- random.setSeed(KEY.getBytes());
- keyGenerator.init(128, random);
- final SecretKey secretKey = keyGenerator.generateKey();
- final Cipher cipher = Cipher.getInstance("AES");
- cipher.init(Cipher.DECRYPT_MODE, secretKey);
- final String decode = new String(cipher.doFinal(Base64Utils.decodeFromString(URLDecoder.decode(accessId, "UTF-8"))), StandardCharsets.UTF_8);
- final String[] infos = decode.split("\\|");
- String userLoginName = infos[0];
- String userGuid = infos[1];
- String userMobile = infos[2];
- String timestamp = infos[3];
- if (Long.parseLong(timestamp) - System.currentTimeMillis() > 30 * 1000)
- throw new Exception("已过期");
- HashMap<String, String> res = new HashMap<>();
- res.put("userLoginName", userLoginName);
- res.put("userGuid", userGuid);
- res.put("userMobile", userMobile);
- return res;
- }
- }
|