Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[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
Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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;
    }
   }
}

View solution in original post

5 Replies
Anonymous
Not applicable
Author

Hi<BR />You need to hard code to convert a string to SHA-256.&nbsp;<BR />Hope the following articles are helpful for you.<BR /><A href="https://community.talend.com/s/article/Create-a-user-routine-and-call-it-in-a-Job-0hHmU" target="_blank" rel="nofollow noopener noreferrer">Creating a user routine and call it in a job.&nbsp;</A><BR /><A href="https://help.talend.com/pages/viewpage.action?pageId=190513200" target="_blank" rel="nofollow noopener noreferrer">Install custom component to Talend Studio</A>.&nbsp;

Anonymous
Not applicable
Author

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;
    }
   }
}
Anonymous
Not applicable
Author

Bonjour, 

can you explain how to call it from TMAP ?

routines.SHA(mystring) I suppose ... but how to pass password and salt ?

thanks in advance for your answer.

Damien

Anonymous
Not applicable
Author

Hello everyone,

it works ... I means, it's giving a result but non significatives 0 (zeros on the left of the string) are not provided in the result ... that's an issue because my provider is hashing with different tools and they cannot match the hashed strings.

Any idea on how to get them in the result ?

regards

Damien

nar
Contributor
Contributor

Hi @DamienBlondel  ,

Did you find the solution to this, I'm getting same issue with leading zeros, If you find the solution could you please help me on this.