DbVisualizer 加密密码解密
DbVisualizer 保存的连接信息存储在用户目录的 ".dbvis/config70/dbvis.xml" 中,其中密码是经过加密处理的。由于DbVisualizer 是由java开发的,我们可以很方便地对其进行反编译,得到他的加/解密方法并恢复数据库密码
以下是加解密程序源代码:
1 import java.io.UnsupportedEncodingException; 2 import java.security.GeneralSecurityException; 3 import java.security.spec.AlgorithmParameterSpec; 4 5 import javax.crypto.Cipher; 6 import javax.crypto.SecretKey; 7 import javax.crypto.SecretKeyFactory; 8 import javax.crypto.spec.PBEKeySpec; 9 import javax.crypto.spec.PBEParameterSpec; 10 11 12 import com.sun.org.apache.xml.internal.security.utils.Base64; 13 14 public class Test { 15 16 public static void main(String args[]) throws GeneralSecurityException { 17 18 System.out.println(encrypt("password", "qinda")); //qinda是在源码中发现的key 19 System.out.println(decrypt("AK+fe8JpLKE2kLaW6+Z31g==", "qinda")); 20 } 21 22 public static String encrypt(String paramString1, String paramString2) 23 throws GeneralSecurityException { 24 return encrypt(paramString1, paramString2, "8859_1"); 25 } 26 27 private static Cipher getCipher(String paramString, SecretKey paramSecretKey, 28 AlgorithmParameterSpec paramAlgorithmParameterSpec, int paramInt) 29 throws GeneralSecurityException { 30 String str = ""; 31 32 Cipher localCipher = null; 33 try { 34 str = str + " , getting encrypt cipher"; 35 36 localCipher = Cipher.getInstance(paramString); 37 38 str = str + " , initializing cipher"; 39 40 localCipher.init(paramInt, paramSecretKey, 41 paramAlgorithmParameterSpec); 42 } catch (GeneralSecurityException localGeneralSecurityException) { 43 localGeneralSecurityException.printStackTrace(); 44 } 45 return localCipher; 46 } 47 48 private static Cipher getCipher(String paramString, int paramInt) 49 throws GeneralSecurityException { 50 Cipher localCipher = null; 51 52 SecretKey localSecretKey = getSecretKey(paramString); 53 54 byte[] arrayOfByte = { -114, 18, 57, -100, 7, 114, 111, 90 }; 55 56 PBEParameterSpec localPBEParameterSpec = new PBEParameterSpec( 57 arrayOfByte, 10); 58 59 String str = "PBEWithMD5AndDES"; 60 61 localCipher = getCipher(str, localSecretKey, localPBEParameterSpec, paramInt); 62 63 return localCipher; 64 } 65 66 private static SecretKey getSecretKey(String paramString) 67 throws GeneralSecurityException { 68 SecretKey localSecretKey = null; 69 try { 70 PBEKeySpec localPBEKeySpec = new PBEKeySpec( 71 paramString.toCharArray()); 72 73 SecretKeyFactory localSecretKeyFactory = SecretKeyFactory 74 .getInstance("PBEWithMD5AndDES"); 75 76 localSecretKey = localSecretKeyFactory 77 .generateSecret(localPBEKeySpec); 78 } catch (GeneralSecurityException localGeneralSecurityException) { 79 80 } 81 return localSecretKey; 82 } 83 84 public static String encrypt(String paramString1, String paramString2, 85 String paramString3) throws GeneralSecurityException { 86 Cipher localCipher = getCipher(paramString2, 1); 87 try { 88 byte[] arrayOfByte1 = paramString1.getBytes(paramString3); 89 90 byte[] arrayOfByte2 = Base64.encode( 91 localCipher.doFinal(arrayOfByte1)).getBytes(); 92 93 return new String(arrayOfByte2, paramString3); 94 95 } catch (UnsupportedEncodingException localUnsupportedEncodingException) { 96 97 } 98 return null; 99 } 100 101 public static String decrypt(String text, String key) 102 throws GeneralSecurityException { 103 return decrypt(text, key, "8859_1"); 104 } 105 106 public static String decrypt(String encrptedText, String key, String encoding) 107 throws GeneralSecurityException { 108 Cipher localCipher = getCipher(key, 2); 109 try { 110 byte[] arrayOfByte1 = encrptedText.getBytes(encoding); 111 112 byte[] arrayOfByte2 = Base64.decode((arrayOfByte1)); 113 114 byte[] arrayOfByte3 = localCipher.doFinal(arrayOfByte2); 115 116 return new String(arrayOfByte3, encoding); 117 } catch (Exception e) { 118 e.printStackTrace(); 119 } 120 121 return null; 122 } 123 }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。