package com.jiayue.ssi;

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.util.text.BasicTextEncryptor;

/**
 * @author xsl
 * @since 2023/04/25
 */
public class JasyptStringEncryptorDemo {
    public static void main(String[] args) {
        BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
        textEncryptor.setPassword("atpingan");
        System.out.println("==========ssl配置==========");
        // key-store-password
        String keyStorePassword = textEncryptor.encrypt("s37d1gxm");
        System.out.println("keyStorePassword===>"+keyStorePassword);
        // mysql:url
        System.out.println("==========mysql配置==========");
        String mysqlURL = textEncryptor.encrypt("jdbc:mysql://localhost:3307/ssi?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&autoReconnect=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai");
//        String mysqlURL = textEncryptor.encrypt("jdbc:mysql://192.168.1.208:3308/ssi?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&autoReconnect=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai&useSSL=true&verifyServerCertificate=true&requireSSL=true&clientCertificateKeyStoreUrl=classpath:mysql_ssl/mysql-keystore&clientCertificateKeyStorePassword=jieyue6677*&trustCertificateKeyStoreUrl=classpath:mysql_ssl/mysql-truststore&trustCertificateKeyStorePassword=jieyue6677*");
        System.out.println("mysqlURL===>"+mysqlURL);
        String mysqlUserName = textEncryptor.encrypt("root");
        System.out.println("mysqlUserName===>"+mysqlUserName);
        String mysqlPassWord = textEncryptor.encrypt("!QAZ2root");
        System.out.println("mysqlPassWord===>"+mysqlPassWord);
        // mail
        System.out.println("==========mail配置==========");
        String mailUserName = textEncryptor.encrypt("xushilong@jiayuepowertech.com");
        System.out.println("mailUserName===>"+mailUserName);
        String mailPassWord = textEncryptor.encrypt("jiayue123456");
        System.out.println("mailPassWord===>"+mailPassWord);
    }

    /**
     * Jasypt 加密
     *
     * @param encryptor 加解密工具
     * @param plaintext 需要加密的字符串
     **/
    public static void encryption(StandardPBEStringEncryptor encryptor, String plaintext) {
        String ciphertext = encryptor.encrypt(plaintext);
        System.out.println(plaintext + " : " + ciphertext);
    }

    /**
     * Jasypt 解密
     *
     * @param encryptor  加解密工具
     * @param ciphertext 需要解密的字符串
     **/
    public static void decrypt(StandardPBEStringEncryptor encryptor, String ciphertext) {
        String plaintext = encryptor.decrypt(ciphertext);
        System.out.println(ciphertext + " : " + plaintext);
    }
}
