1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
| public class PasswordDecrypt {
public static void main(String[] args) throws FileNotFoundException {
EaseDecrypt(); }
public static List<String> Encrypt(String url,String username,String pwd){
StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor(); EnvironmentPBEConfig config = new EnvironmentPBEConfig();
config.setAlgorithm("PBEWithMD5AndDES"); config.setPassword("sigtuna"); standardPBEStringEncryptor.setConfig(config);
System.out.println("url "+ standardPBEStringEncryptor.encrypt(url)); System.out.println("root "+ standardPBEStringEncryptor.encrypt(username)); System.out.println("pwd "+ standardPBEStringEncryptor.encrypt(pwd)); return null; }
public static List<String> decrypt(String url, String username, String pwd){
StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor(); EnvironmentPBEConfig config = new EnvironmentPBEConfig(); config.setAlgorithm("PBEWithMD5AndDES"); config.setPassword("sigtuna"); standardPBEStringEncryptor.setConfig(config); String plainTextUrl = standardPBEStringEncryptor.decrypt(url); String plainTextUser = standardPBEStringEncryptor.decrypt(username); String plainTextPwd = standardPBEStringEncryptor.decrypt(pwd); System.out.println("url: "+plainTextUrl); System.out.println("username: "+plainTextUser); System.out.println("password: "+plainTextPwd); return null; }
public static List<String> EaseDecrypt() throws FileNotFoundException{
InputStream io = new FileInputStream("x:\\xxx\\application-dev.yml"); Yaml yaml=new Yaml(); Map<String, Object> map =yaml.load(io); String url = ""; String username = ""; String pwd = "";
if (map.get("spring") != null && !map.get("spring").equals("")) { Map<String,Object> mapd = (Map<String, Object>) map.get("spring"); if (mapd.get("datasource") != null) { Map<String,Object> mapdata = (Map<String, Object>) mapd.get("datasource"); if (mapdata.get("druid") != null) { Map<String,Object> mapdata1 = (Map<String, Object>) mapdata.get("druid"); if (mapdata1.get("master") != null) { Map<String,Object> mapdata2 = (Map<String, Object>) mapdata1.get("master"); if (mapdata2.get("url") != null) { url = (String) mapdata2.get("url"); username = (String) mapdata2.get("username"); pwd = (String) mapdata2.get("password");; } } } } }
String algorithm = ""; String password = ""; String prefix = ""; String suffix = ""; if (map.get("jasypt") != null && !map.get("jasypt").equals("")) { Map<String,Object> mapd = (Map<String, Object>) map.get("jasypt"); if (mapd.get("encryptor") != null) { Map<String,Object> mapdata = (Map<String, Object>) mapd.get("encryptor"); algorithm = (String) mapdata.get("algorithm"); password = (String) mapdata.get("password");
if(mapdata.get("property")!= null){ Map<String,Object> mapdata1 = (Map<String, Object>) mapdata.get("property"); prefix = (String) mapdata1.get("prefix"); suffix = (String) mapdata1.get("suffix"); } } }
StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor(); url = removePro(url,prefix,suffix); username = removePro(username,prefix,suffix); pwd = removePro(pwd,prefix,suffix);
EnvironmentPBEConfig config = new EnvironmentPBEConfig(); config.setAlgorithm(algorithm); config.setPassword(password); standardPBEStringEncryptor.setConfig(config); String plainTextUrl = standardPBEStringEncryptor.decrypt(url); String plainTextUser = standardPBEStringEncryptor.decrypt(username); String plainTextPwd = standardPBEStringEncryptor.decrypt(pwd); System.out.println("url: "+plainTextUrl); System.out.println("username: "+plainTextUser); System.out.println("password: "+plainTextPwd); return null; }
public static String removePro(String oString,String prefix,String suffix){
String str = oString; if (prefix!=null) { str = oString.substring(prefix.length(), oString.length()); oString = str; if (suffix!=null) { str = oString.substring(0, oString.length()-suffix.length()); } } return str; }
public static List<String> getMapKey(String key , Map<String,Object> map){
List<String> list = new ArrayList<>(); Map<String,Object> keyMap = new HashMap<>(); if (key != null) { if (map.get(key) != null) { keyMap = (Map<String, Object>) map.get(key); }else{ return null; } }else{ keyMap = map; } for(String x : keyMap.keySet()){
} return null; }
}
|