Four Stars

[resolved] String to SHA-256

Hello!  
I'm new to java,  I don't konw if talend have a component to  convert a string to SHA-256?  
Or how could we write a code routines in order to use it?  
I have tried download the custom component  tFileDigester  and install in talend, but it can't find in palette. 

Could you help me please? 
Thanks to all
1 ACCEPTED SOLUTION

Accepted Solutions
Four Stars

Re: [resolved] String to SHA-256

Hi
You need to hard code to convert a string to SHA-256. 
Hope the following articles are helpful for you.
Creating a user routine and call it in a job. 
Install custom component to Talend Studio

Thanks shong, i found the code and it worked.  I'd like to share here for others if needed. 
package routines;
import java.security.MessageDigest;
import java.math.BigInteger;
public class SHA {
public static String getMD5HashedPassword(String password, String salt) {
    String sTH;
    if(password == null) {
    if(salt == null) sTH = "";
    else sTH = salt;
    }
    else {
    if(salt == null) sTH = password;
    else sTH = password + salt;
    }
   
    try {
    MessageDigest md5 = MessageDigest.getInstance("SHA-256");
    md5.update(sTH.getBytes());
    BigInteger hash = new BigInteger(1, md5.digest());
    return hash.toString(16);
    } 
    catch (Exception e) {
    return null;
    }
   }
}
2 REPLIES
Community Manager

Re: [resolved] String to SHA-256

Hi
You need to hard code to convert a string to SHA-256. 
Hope the following articles are helpful for you.
Creating a user routine and call it in a job. 
Install custom component to Talend Studio
----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars

Re: [resolved] String to SHA-256

Hi
You need to hard code to convert a string to SHA-256. 
Hope the following articles are helpful for you.
Creating a user routine and call it in a job. 
Install custom component to Talend Studio

Thanks shong, i found the code and it worked.  I'd like to share here for others if needed. 
package routines;
import java.security.MessageDigest;
import java.math.BigInteger;
public class SHA {
public static String getMD5HashedPassword(String password, String salt) {
    String sTH;
    if(password == null) {
    if(salt == null) sTH = "";
    else sTH = salt;
    }
    else {
    if(salt == null) sTH = password;
    else sTH = password + salt;
    }
   
    try {
    MessageDigest md5 = MessageDigest.getInstance("SHA-256");
    md5.update(sTH.getBytes());
    BigInteger hash = new BigInteger(1, md5.digest());
    return hash.toString(16);
    } 
    catch (Exception e) {
    return null;
    }
   }
}