package com.kwan.springbootkwan.utils; import com.kwan.springbootkwan.SpringBootKwanApplication; import org.jasypt.encryption.StringEncryptor; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** * 加解密工具测试 * * @author : qinyingjie * @version : 2.2.0 * @date : 2023/8/26 15:49 */ @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ContextConfiguration(classes = SpringBootKwanApplication.class) public class StringEncryptorUtil { @Autowired private StringEncryptor encryptor; @Test public void getPass() { String url = encryptor.encrypt("jdbc:mysql://localhost:3306/mydb?autoReconnect=true&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8"); String name = encryptor.encrypt("root"); String password = encryptor.encrypt("123456"); System.out.println("database url: " + url); System.out.println("database name: " + name); System.out.println("database password: " + password); Assert.assertTrue(url.length() > 0); Assert.assertTrue(name.length() > 0); Assert.assertTrue(password.length() > 0); } }