package com.gtiit.shr.config;

import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class JasyptUtils {
    private static Logger logger = LoggerFactory.getLogger(JasyptUtils.class);
    @Autowired
    StringEncryptor encryptor;



    public String getEncryptResult(String string) {
        String encryptResult = this.encryptor.encrypt(string);
        logger.info("原字符串：{} ,加密后字符串: {}", string, encryptResult);
        System.out.println("原字符串：" + string + ",加密后字符串:" + encryptResult);
        return encryptResult;
    }

    public String getDecryptResult(String string) {
        String decryptResult = this.encryptor.decrypt(string);
        logger.info("加密后字符串：{} ,原字符串: {}", string, decryptResult);
        System.out.println("加密后字符串：" + string + ",原字符串:" + decryptResult);
        return decryptResult;
    }

    public static void main(String[] args) {
        StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
        encryptor.setPassword("mySecretKey");
        String string = "Gtiit@2025";
        String encryptResult = encryptor.encrypt(string);
        logger.info("原字符串：{} ,加密后字符串: {}", string, encryptResult);
        System.out.println("原字符串：" + string + "加密后字符串:" + encryptResult);
        String string2 = "KyyuLbN5UGc02OArDKNVMA==";
        String decryptResult = encryptor.decrypt(string2);
        logger.info("加密后字符串：{} ,原字符串: {}", string2, decryptResult);
    }
}
