package com.bonus.gateway;

import org.jasypt.encryption.StringEncryptor;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

import javax.annotation.Resource;

/**
 * 网关启动程序
 * 
 * @author bonus
 */
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
public class BonusGatewayApplication  implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(BonusGatewayApplication.class, args);
        System.err.println("博诺思网关启动成功\n");
    }


    @Resource
    private StringEncryptor encryptor;
    @Override
    public void run(String... args) throws Exception {
//        String encryptStr = encrypt("f648524d-0a7b-449e-8f92-64e05236fd51" );
//        System.err.println( "原始明文密码加密后的结果为：" + encryptStr );
//        String  decrtyptStr = decrypt("ENC(b8K5x5rjN7qdGdmhgzFayK/P6ZVbC/UNBHjx2SBJkoqU149aXRtJsFhDZcgpckFf)");
//        System.err.println( "明文结果为：" + decrtyptStr );

    }

    private String encrypt( String originPassord ) {
        return encryptor.encrypt( originPassord );
    }

    private String decrypt( String encryptedPassword ) {
        return encryptor.decrypt( encryptedPassword );
    }
}
