<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Hash a string : string to sha-256 in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Hash-a-string-string-to-sha-256/m-p/2265327#M44895</link>
    <description>&lt;P&gt;This code can hardly work. I guess the original version was intent to build MD5 hashes and these hashes are typically numbers.&lt;/P&gt; 
  &lt;P&gt;The SHA-256 hash would be by far to large for a number therefore such hashes are typically Strings (like a guid).&lt;/P&gt; 
  &lt;PRE&gt;    public static String buildSHA256Hash(String content) {
    	
    	if (content == null) {
    		return null;
    	}
    	// calculate hash
    	MessageDigest messageDigest;
		try {
			messageDigest = MessageDigest.getInstance("SHA-256");
		} catch (NoSuchAlgorithmException e) {
			throw new RuntimeException("Digest Algorithm SHA-256 could not be found in this environment.", e);
		}
    	
		final byte[] result = messageDigest.digest(content.getBytes(Charset.forName("UTF-8")));
		
		// convert hash to requested encoding
		return Base64.encodeToBase64String(result);
    }&lt;/PRE&gt; 
  &lt;P&gt;And here the Base64 class. This is a Talend Routine you should create:&lt;/P&gt; 
 &lt;BR /&gt;&lt;BR /&gt;To see the whole post, download it &lt;A href="https://community.qlik.com/legacyfs/online/tlnd_dw_files/0683p000009Md6F"&gt;here&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://community.qlik.com/legacyfs/online/tlnd_dw_files/0683p000009Md6F"&gt;OriginalPost.pdf&lt;/A&gt;</description>
    <pubDate>Tue, 24 Mar 2020 16:15:17 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-03-24T16:15:17Z</dc:date>
    <item>
      <title>Hash a string : string to sha-256</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Hash-a-string-string-to-sha-256/m-p/2265326#M44894</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to hash a string I found attached code. it's delivering a result but&amp;nbsp;non significatives 0 (zeros on the left of the string) are not provided in the result ...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for exemple I get&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b1f3daebef8a4e237e7830579a8505378ce360106b69f55805f0b255e82637&lt;/P&gt;
&lt;P&gt;but I was expecting 00b1f3daebef8a4e237e7830579a8505378ce360106b69f55805f0b255e82637&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can see that the code is manipulating a big integer ... that's probably the reason why zeros are eliminated ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;package routines;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import java.security.MessageDigest;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import java.math.BigInteger;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;public class SHA {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;public static String getMD5HashedPassword(String password, String salt) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; String sTH;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; if(password == null) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; if(salt == null) sTH = "";&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; else sTH = salt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; else {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; if(salt == null) sTH = password;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; else sTH = password + salt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; try {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; MessageDigest md5 = MessageDigest.getInstance("SHA-256");&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; md5.update(sTH.getBytes());&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; BigInteger hash = new BigInteger(1, md5.digest());&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; return hash.toString(16);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; }&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; catch (Exception e) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; return null;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 15:53:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Hash-a-string-string-to-sha-256/m-p/2265326#M44894</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-24T15:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: Hash a string : string to sha-256</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Hash-a-string-string-to-sha-256/m-p/2265327#M44895</link>
      <description>&lt;P&gt;This code can hardly work. I guess the original version was intent to build MD5 hashes and these hashes are typically numbers.&lt;/P&gt; 
  &lt;P&gt;The SHA-256 hash would be by far to large for a number therefore such hashes are typically Strings (like a guid).&lt;/P&gt; 
  &lt;PRE&gt;    public static String buildSHA256Hash(String content) {
    	
    	if (content == null) {
    		return null;
    	}
    	// calculate hash
    	MessageDigest messageDigest;
		try {
			messageDigest = MessageDigest.getInstance("SHA-256");
		} catch (NoSuchAlgorithmException e) {
			throw new RuntimeException("Digest Algorithm SHA-256 could not be found in this environment.", e);
		}
    	
		final byte[] result = messageDigest.digest(content.getBytes(Charset.forName("UTF-8")));
		
		// convert hash to requested encoding
		return Base64.encodeToBase64String(result);
    }&lt;/PRE&gt; 
  &lt;P&gt;And here the Base64 class. This is a Talend Routine you should create:&lt;/P&gt; 
 &lt;BR /&gt;&lt;BR /&gt;To see the whole post, download it &lt;A href="https://community.qlik.com/legacyfs/online/tlnd_dw_files/0683p000009Md6F"&gt;here&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://community.qlik.com/legacyfs/online/tlnd_dw_files/0683p000009Md6F"&gt;OriginalPost.pdf&lt;/A&gt;</description>
      <pubDate>Tue, 24 Mar 2020 16:15:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Hash-a-string-string-to-sha-256/m-p/2265327#M44895</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-24T16:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Hash a string : string to sha-256</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Hash-a-string-string-to-sha-256/m-p/2265328#M44896</link>
      <description>Instead of bigint you need to convert into string. Or after the value you got you convert into sting add leading zeros.</description>
      <pubDate>Tue, 24 Mar 2020 16:18:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Hash-a-string-string-to-sha-256/m-p/2265328#M44896</guid>
      <dc:creator>manodwhb</dc:creator>
      <dc:date>2020-03-24T16:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Hash a string : string to sha-256</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Hash-a-string-string-to-sha-256/m-p/2265329#M44897</link>
      <description>Bonjour jlolling,
&lt;BR /&gt;
&lt;BR /&gt;Sorry, but I am a beginner and do not know how to "use" the code you posted.
&lt;BR /&gt;
&lt;BR /&gt;With the one I posted, I was calling it from a tmap to convert row3.In just giving it as an input and the hashkey in addition :
&lt;BR /&gt;
&lt;BR /&gt;SHA.getMD5HashedString(row3.In , context.HashKey)
&lt;BR /&gt;
&lt;BR /&gt;If I create the talend routine you recommended to me, how can I use it in a simple manner ?
&lt;BR /&gt;
&lt;BR /&gt;regards
&lt;BR /&gt;Damien
&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Apr 2020 15:20:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Hash-a-string-string-to-sha-256/m-p/2265329#M44897</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-16T15:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: Hash a string : string to sha-256</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Hash-a-string-string-to-sha-256/m-p/2265330#M44898</link>
      <description>&lt;P&gt;Hi @&lt;A href="https://community.talend.com/s/profile/00539000006yr8WAAQ" alt="https://community.talend.com/s/profile/00539000006yr8WAAQ" target="_blank"&gt;DamienBlondel&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 16:42:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Hash-a-string-string-to-sha-256/m-p/2265330#M44898</guid>
      <dc:creator>nar</dc:creator>
      <dc:date>2022-04-05T16:42:01Z</dc:date>
    </item>
  </channel>
</rss>

