package com.example;

import com.example.frame.utils.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * UtilTest -  - 测试用例
 *
 * @author wangbing
 * @version 0.0.1
 * @since 2017-01-01
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class UtilTest {

    @Test
    public void testIDgenerator() {
        for (int i = 0; i < 10; i++) {
            long l = IDgenerator.nextId();
            System.out.println(l);
        }
    }

    @Test
    public void testAESUtil() {
        // 加密
        String data = "我有一个苹果";
        String secret = "1234567890123456";
        System.out.println("加密后的Base64密文是:" + AESUtil.encrypt2Base64(data.getBytes(), secret));

        // 解密
        String encrypt2Base64 = AESUtil.encrypt2Base64(data.getBytes(), secret);
        byte[] decrypt = AESUtil.decrypt(Base64Util.decode(encrypt2Base64), secret);
        System.out.println("解密后的明文是:" + new String(decrypt));
    }

    @Test
    public void testBase64Util() {
        String s = Base64Util.encodeToString(("我搜搜").getBytes());
        System.out.println(s);

        byte[] decode = Base64Util.decode(s);
        System.out.println(new String(decode));
    }

    @Test
    public void testMD5Util() {
        String encode = MD5Util.encode("123456");
        System.out.println(encode);
    }

    @Test
    public void testProcessUtil() {
        ProcessUtil.execExe("D:\\example.exe");
        ProcessUtil.execBat("D:\\example.bat");
    }

    @Test
    public void testRSAUtil() {
        {//创建秘钥对
            RSAUtil.createKey();
        }

        {//加解密

            //加密
            String encrypt = RSAUtil.encrypt2Base64("我有一个苹果".getBytes());
            System.out.println(encrypt);

            //解密
            String decrypt = RSAUtil.decrypt2String(encrypt);
            System.out.println(decrypt);
        }


        String sign = RSAUtil.sign2Base64("我有一个苹果".getBytes());
        System.out.println(sign);

        boolean b = RSAUtil.doCheck("我有一个苹果".getBytes(), sign);
        System.out.println(b);
    }
}
