package com.cpop.mall.web;

import com.cpop.core.service.CoreService;
import com.cpop.core.utils.RsaUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Map;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class CpopMallWebApplicationTests {

    @Autowired
    private CoreService coreService;

    @Autowired
    private RsaUtils rsaUtils;

    @Test
    void contextLoads() {
    }

    /**
     * 初始化密钥对
     */
    @Test
    public void initKeyPair() {
        String publicFileUrl = "E:/Cpop/Jambox-Union/Jambox-Core/src/main/resources/static/keypair/publicKey";
        String privateFileUrl = "E:/Cpop/Jambox-Union/Jambox-Core/src/main/resources/static/keypair/privateKey";
        Map<String, String> keyPairMap = rsaUtils.initKeyPair(publicFileUrl,privateFileUrl);
        String publicKey = keyPairMap.get("publicKey");
        String privateKey = keyPairMap.get("privateKey");
        System.out.println("公钥：");
        System.out.println(publicKey);
        System.out.println();
        System.out.println("私钥：");
        System.out.println(privateKey);
        System.out.println();
        String source = "Admin@123";
        System.out.println("待加密字符串："+source);
        System.out.println();
        String strEncrypt = rsaUtils.encrypt(source);
        System.out.println("加密后的字符串：");
        System.out.println(strEncrypt);
        System.out.println();
        String strDecrypt = rsaUtils.decrypt(strEncrypt);
        System.out.println("解密后的字符串：");
        System.out.println(strDecrypt);
    }

}
