package com.its.op;

import com.its.utils.AES256Util;
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 org.springframework.boot.test.context.SpringBootTest;

@Slf4j
@SpringBootTest
public class ItsOpServerApplicationTests {

    @Test
    void test1() {
        for (int ii = 0; ii < 24; ii++) {
            for (int jj = 0; jj < 12; jj++) {
                log.error("{}:{}", ii, jj*5);
            }
        }

        String prcsDt = "20220120173526";
        log.error("{}", prcsDt.substring(0, 2));
        log.error("{}", prcsDt.substring(8, 10));
        log.error("{}", prcsDt.substring(10, 12));

        String svcDt = "20210120173526";

        log.error("compareTo: {}", svcDt.compareTo(prcsDt));
    }


    @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);

        String yiits = encryptor.encrypt("yiits");
        String rutis = encryptor.encrypt("rutis");
        log.info("{}", yiits);
        log.info("{}", rutis);
    }

    @Test
    void sha256() {
        String data = AES256Util.encryptSHA256("yonginits");
        log.info("{}", data);
        log.info("{}", data.toUpperCase());
        log.info("{}", AES256Util.encryptSHA256("yiits"));
        log.info("{}", AES256Util.encryptSHA256("yonginits"));
        log.info("{}", AES256Util.encryptSHA256("yonginits"));
        log.info("{}", AES256Util.encryptSHA256("yonginits"));
        log.info("{}", AES256Util.encryptSHA256("yonginits"));
        log.info("{}", AES256Util.encryptSHA256("yonginits"));
        log.info("{}", AES256Util.encryptSHA256("yonginits"));
        log.info("{}", AES256Util.encryptSHA256("yonginits"));
        log.info("{}", AES256Util.encryptSHA256("yonginits"));
    }
}
