package com.cm;

import com.cm.token.TokenEncoder;
import org.apache.commons.codec.binary.Base64;

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

/**
 * @author Administrator
 * @version 1.0
 * @className EncodeTest
 * @description TODO
 * @date 2018/12/7 17:31
 **/
public class EncodeTest {

    public void tokenTest() throws Exception {
        String token1 = TokenEncoder.createToken().getToken();
        System.out.println("token1: "+ token1);
        String token2 = TokenEncoder.createToken("this is content").getToken();
        System.out.println("token2: "+ token2);
        String token3 = TokenEncoder.createToken("zhangsan", "123456").getToken();
        System.out.println("token3: "+ token3);
    }

    public void paramsTest() throws Exception {
//        System.out.println(ParamsOut.paramsInDecoder("UjlBUXNXQkJvSG9ZRmlkR3hvYmhqM2phY2hBTFQzQTBJQUlhbmRRcEsrWT0="));
//        System.out.println(ParamsOut.paramsOutEncode("out -> in -> encoder"));

        String password = "cmxxParamsIn";//AES的密钥
        KeyGenerator kgen = KeyGenerator.getInstance("AES");
        SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
        secureRandom.setSeed(password.getBytes());
        kgen.init(128, secureRandom);

        SecretKey secretKey = kgen.generateKey();
        byte[] enCodeFormat = secretKey.getEncoded();//AES加密实际的Key值
        System.out.println(new String(Base64.encodeBase64String(enCodeFormat)));


    }

}
