Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Raghunath
Creator

sha1 hash key

i need to generate hash key with sha1 algorithm how can we do it with java code or sqlserver query
Labels (3)
3 Replies
Anonymous
Not applicable

Hi
You can create Routine(hard code Java class and methods) in 'Repository-Code-Routines'.
Then call the methods of Java SHA1 implement in Talend components such as tMap, tJava and so on.
Hope this will help you.
Best regards!
Pedro
Anonymous
Not applicable

Hi,
I am new to Talend and i had the same query like i have to generate hash key using SHA-1 Algorithm.So please provide me the detailed process of doing it...
Thanks
Anonymous
Not applicable

Here's some examples of methods that you can add to a Talend routine, for doing this.
    public static String getMD5(String field) {
    if(field == null) return null;
   
    try {
    java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
    md.reset();
    md.update(field.getBytes("UTF-8"));
    byte[] digest = md.digest();
    java.math.BigInteger bigInt = new java.math.BigInteger(1, digest);
    String hashText = bigInt.toString(16);
    // Now we need to zero pad it if you actually want the full 32 chars.
    while(hashText.length() < 32 ){
    hashText = "0" + hashText;
    }
        return hashText;
    }
    catch (Exception e) {
    return null;
    }
    }
 
    public static String getSHA256(String field) {
    if(field == null) return null;
   
    try {
    java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256");
    md.reset();
    md.update(field.getBytes("UTF-8"));
    byte[] digest = md.digest();
    java.math.BigInteger bigInt = new java.math.BigInteger(1, digest);
    String hashText = bigInt.toString(16);
    // Now we need to zero pad it if you actually want the full 32 chars.
    while(hashText.length() < 32 ){
    hashText = "0" + hashText;
    }
        return hashText;
    }
    catch (Exception e) {
    return null;
    }
    }