001package top.cenze.utils; 002 003import org.jasypt.util.text.BasicTextEncryptor; 004 005/** 006 * 配置文件加密解密工具 007 */ 008public class JasyptUtil { 009 private final static BasicTextEncryptor encryptor = new BasicTextEncryptor(); 010 011 /** 012 * 加密 013 * @param s 待加密字符串 014 * @param secretKey 密钥 015 * @return 016 */ 017 public static String encrypt(String s, String secretKey) { 018 encryptor.setPassword(secretKey); 019 return encryptor.encrypt(s); 020 } 021 022 /** 023 * 解密 024 * @param s 待加密字符串 025 * @param secretKey 密钥 026 * @return 027 */ 028 public static String decrypt(String s, String secretKey) { 029 encryptor.setPassword(secretKey); 030 return encryptor.decrypt(s); 031 } 032 033// public static void main(String[] args) { 034// // Olmysoft*123 035// // root 036// // nacos 037// String encrypt = JasyptUtil.encrypt("root", "Otms-Ltl"); 038// System.out.println(encrypt); 039// } 040}