2017-06-22 118 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(...)

希望这会有所帮助。