2015-05-28 129 views
0

最近我遇到了一個要求,用於使用symmetric key algorithm來加密數據庫密碼,該密碼用於爲獨立調度程序創建連接。AIX jre沒有拋出任何異常

第一個數據庫密碼使用java swing utility進行加密,其中我使用aes128位加密並將其放入屬性文件中。 然後在創建連接的connection manager類中,從屬性文件中讀取密碼並使用相同的密鑰進行解密。在我的最後,我已經在aix服務器上測試了這個代碼在工作,但是在客戶端它不工作。它無法解密。在連接管理器類中執行以下語句後,它將從方法中退出而無任何異常。

pwd=AES128Encryption.decrypt(PAYTFHomeProperties.getProperty("PWD").toString().trim()); 

我假設這與jce.jar有關。這裏是我解密和連接管理器類的解密密碼的方法。

protected Connection getConnection(){ 

      try{ 

       mcName=PAYTFHomeProperties.getProperty("MACHINE_NAME"); 
       sid=PAYTFHomeProperties.getProperty("SID"); 
       port=PAYTFHomeProperties.getProperty("DB_PORT"); 
       UserName=PAYTFHomeProperties.getProperty("USER_NAME"); 
       pwd=AES128Encryption.decrypt(PAYTFHomeProperties.getProperty("PWD").toString().trim()); 
debug("getEncrptdData||encrypted pwd::"+PAYTFHomeProperties.getProperty("PWD")); 
       System.out.println("decrypted pwd::"+pwd); 
       tns=PAYTFHomeProperties.getProperty("TNS"); 
       hostString="jdbc:oracle:thin:@"+mcName+":"+port+":"+sid; 
        OracleConnectionPoolDataSourcecpds=new     OracleConnectionPoolDataSource(); 
          cpds.setDriverType("thin"); 
         cpds.setNetworkProtocol("tcp"); 
         cpds.setServerName(mcName); 
         cpds.setDatabaseName(sid); 
         cpds.setPortNumber(Integer.parseInt(port)); 
         cpds.setUser(UserName); 
         cpds.setPassword(pwd); 


         pc = (oracle.jdbc.pool.OraclePooledConnection)cpds.getPooledConnection(); 


         connection con= (Connection)pc.getConnection(); 

      } catch(Exception e){ 
      System.out.println("getConnection"+e.toString()); 
      } 
     return con; 
     } 

這裏是我AES128Encryption類的解密方法

import javax.crypto.*; 
import javax.crypto.spec.SecretKeySpec; 
import sun.misc.*; 

public class AES128Encryption { 

    private static final String ALGO = "AES/ECB/PKCS5Padding"; 
    public static String decrypt(String encryptedData) throws Exception { 
     Cipher c = Cipher.getInstance(ALGO); 
     byte[] raw = "************".getBytes(); 
     SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); 
     c.init(Cipher.DECRYPT_MODE, skeySpec); 
     byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedData); 
     byte[] decValue = c.doFinal(decordedValue); 
     String decryptedValue = new String(decValue); 
     return decryptedValue; 
    } 
    } 
+0

異常跟蹤? –

+0

@JunedAhsan根本沒有。 –

回答

0

這不是一個答案,但努力趕上的Throwable:

try { 
    // do something 
} catch (Throwable t) { 
    t.printStackTrace(); 
} 

而且ASLO檢查,如果你有你的類/方法沒有身體的例外:

try { 
    // do something 
} catch (Exception e) { 
    // do nothing 
} 
+0

異常處理。我沒有得到任何東西。 –