package com.its.app;

import lombok.extern.slf4j.Slf4j;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.jasypt.salt.StringFixedSaltGenerator;
import org.junit.jupiter.api.Test;

import java.util.StringTokenizer;

@Slf4j
//@SpringBootTest(classes = VmsSafeAdapterServerApplication.class)
public class VmsSafeAdapterServerApplicationTests {

    @Test
    void token() {
        StringTokenizer areaCodes = new StringTokenizer("4711110100-4711110200", ",");
        while(areaCodes.hasMoreTokens()){
            String areaCode = areaCodes.nextToken();
            log.info("VmsSafeAdapterService.selectVmsSafeMessage: SEQ {}, AREA_CODE [{}].", 1, areaCode);
        }
    }
    @Test
    void jasypt() {
        String encKey = "asdkjfaslkjflkajslfjkajlkf";
        PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
        SimpleStringPBEConfig config = new SimpleStringPBEConfig();

        // ==> SimpleStringPBEConfig 사용시 아래 3개 반드시 설정해야함
        config.setPassword(encKey);                                         // 암호화에 사용할 키
        config.setPoolSize(1);                                              // Pool Size
        config.setSaltGenerator(new StringFixedSaltGenerator("fixedSalt")); // 고정으로 암호화(Default: Random)
        //config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
        //config.setAlgorithm("PBEWithMD5AndTripleDES");
        config.setAlgorithm("PBEWithMD5AndDES"); // Jasypt 를 이용한 암호화 알고리즘
        config.setProviderName("SunJCE");
        config.setKeyObtentionIterations("10000");
        config.setStringOutputType("base64");
        /*private Boolean proxyPropertySources = false;
        private String bean = "jasyptStringEncryptor";
        private String password;
        private String algorithm = "PBEWithMD5AndDES";
        private String keyObtentionIterations = "1000";
        private String poolSize = "1";
        private String providerName = null;
        //config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
        private String saltGeneratorClassname = "org.jasypt.salt.RandomSaltGenerator";
        private String stringOutputType = "base64";*/
        encryptor.setConfig(config);

        log.info("TEST: [{}] [{}]", encryptor.encrypt("phutis"), encryptor.encrypt("phutis"));
        log.info(" ITS: [{}] [{}]", encryptor.encrypt("itsdba"), encryptor.encrypt("sdba"));
        log.info("SAFE: [{}] [{}]", encryptor.encrypt("drdi"), encryptor.encrypt("dRDi*679432"));
//        16:06:33.352 [main] INFO com.its.app.VmsSafeAdapterServerApplicationTests -  ITS: [uSyqR8q83bI=] [KRP5DTdQgZA=]
//        16:06:33.355 [main] INFO com.its.app.VmsSafeAdapterServerApplicationTests - SAFE: [6rsuPKbWvWw=] [9974S1JCCDQafTANln2X7g==]
    }

}
