2017-06-22 36 views
0

如何將自定義函數與tmap結合使用,或者可以使用tsystem。我想用我的自定義函數即時解密加密的列。我可以將所有加密值寫入文件,然後從文件寫入tsystem或tmap,並解密值。這是最好的方法是什麼?Talend自定義函數

+0

你應該可以,只要你的jar載入到項目中來訪問您的自定義的公共職能。 – tobi6

回答

3

使用Java例程。你可以創建java方法並在任何地方調用。例如

public static String decrypt(String encryptStr){ 
        String decrypted = null; 
     try { 

      while(encryptStr != null){ 
       try 
       { 

        String key = "Bar12345Bar12345"; // 128 bit key 
        // Create key and cipher 
        Key aesKey = new SecretKeySpec(key.getBytes(), "AES"); 
        Cipher cipher = Cipher.getInstance("AES"); 
        // encrypt the text 
        cipher.init(Cipher.ENCRYPT_MODE, aesKey); 

        // for decryption 
        byte[] bb = new byte[encryptStr.length()]; 
        for (int i=0; i<encryptStr.length(); i++) { 
         bb[i] = (byte) encryptStr.charAt(i); 
        } 

        // decrypt the text 
        cipher.init(Cipher.DECRYPT_MODE, aesKey); 
        decrypted = new String(cipher.doFinal(bb)); 

       } 
       catch(Exception e) 
       { 
        e.printStackTrace(); 
       } 
      } 
     } catch (IOException ex) { 
      Logger.getLogger(Snake_H.class.getName()).log(Level.SEVERE, null, ex); 
     } 
     return decrypted; 
    } 

對於加密,請遵循相同類型的方法。你可以隨時隨地在像調用這個Java方法TMAP
參考Talend Routines

1

如果您正在講例程,只需調用所需的方法,您可以在任何地方放置一些java代碼。
例如,作爲輸出流的表達式,您可以使用類似於:
yourClass.yourMethod(...)

希望這會有所幫助。