<?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: Comparing and reading a hash value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343905#M272964</link>
    <description>&lt;P&gt;Yes that should work, but if you have the plain values for both columns in both tables, why not just match up&amp;nbsp;PLAIN_A to PLAIN_B directly? &amp;nbsp;You wouldn't need to worry about hashing anything, you could&amp;nbsp;just use a standard PROC SQL JOIN. &amp;nbsp;You could do a join on the hashed values too once you created HASH_B, but again that seems like it's just an extra step that isn't really providing any value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What problem are you actually trying to solve? &amp;nbsp;Hashing is a great tool to have handy, but I'm not sure it's doing you any favors in this case, unless you're just trying to learn how to use it for its own sake.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Mar 2017 22:29:28 GMT</pubDate>
    <dc:creator>Sven111</dc:creator>
    <dc:date>2017-03-23T22:29:28Z</dc:date>
    <item>
      <title>Comparing and reading a hash value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343841#M272956</link>
      <description>&lt;P&gt;Good afternoon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wonder if someone might be able to answer a question on a hash values? I am very new to this concept, sorry.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We are having a discussion on the security of hash values and I came up with a question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The question is if I have a hashed value (and I know the original value) and a table of many other&amp;nbsp;values (that does contain the original unhashed value someplace in the many table) can I then hash all values in the "many" table and then compare the original hash value with the hashed values from the "many" table to find the matched value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For some reason I cannot get SAS to match the values an pull out the orignal variable value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for any help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeff&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example Code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test_code;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; hash hash_copy hash_diff &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$hex64.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;hash = sha256(ss_number);&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; hash_copy = sha256(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"fox"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; hash_diff = sha256(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"fox"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(hash=hash_copy) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; test_copy = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'T'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;else&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test_copy = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'F'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(hash=hash_diff) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; test_diff = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'T'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;else&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test_diff = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'F'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Original value - fox&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Hash Value - 05A8475FEEBBFEA685ECE06045BE63722EDC61BB2ADE8060A9F03AED6D49F454&lt;/P&gt;
&lt;P&gt;Hash Copy - 776CB326AB0CD5F0A974C1B9606044D8485201F2DB19CF8E3749BDEE5F36E2&lt;/P&gt;
&lt;P&gt;Hash Diff - 776CB326AB0CD5F0A974C1B9606044D8485201F2DB19CF8E3749BDEE5F36E2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Many table&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;hen -&lt;/P&gt;
&lt;P&gt;Hash Value - 05A8475FEEBBFEA685ECE06045BE63722EDC61BB2ADE8060A9F03AED6D49F454&lt;/P&gt;
&lt;P&gt;Hash Copy - D44A08DE3981889DAE0F7BA3980EA9FD24768279FC4EC2FBBDBCF3BF9FE65C22&lt;/P&gt;
&lt;P&gt;Hash Diff -&amp;nbsp; D44A08DE3981889DAE0F7BA3980EA9FD24768279FC4EC2FBBDBCF3BF9FE65C22&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;pig -&lt;/P&gt;
&lt;P&gt;Hash Value - 05A8475FEEBBFEA685ECE06045BE63722EDC61BB2ADE8060A9F03AED6D49F454&lt;/P&gt;
&lt;P&gt;Hash Copy - F0B8C9D84DD2B877E0B952130B73E218106FEC04C23852271D390213A1FF96F4&lt;/P&gt;
&lt;P&gt;Hash Diff -&amp;nbsp; F0B8C9D84DD2B877E0B952130B73E218106FEC04C23852271D390213A1FF96F4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;fox -&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Hash Value - 05A8475FEEBBFEA685ECE06045BE63722EDC61BB2ADE8060A9F03AED6D49F454&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Hash Copy - 776CB326AB0CD5F0A974C1B9606044D8485201F2DB19CF8E3749BDEE5F36E2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Hash Diff -&amp;nbsp; 776CB326AB0CD5F0A974C1B9606044D8485201F2DB19CF8E3749BDEE5F36E2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;horse -&lt;/P&gt;
&lt;P&gt;Hash Value - 05A8475FEEBBFEA685ECE06045BE63722EDC61BB2ADE8060A9F03AED6D49F454&lt;/P&gt;
&lt;P&gt;Hash Copy - FD62862B6DC213BEE77C2BADD6311528253C6CB3107E03C16051AA15584ECA1C&lt;/P&gt;
&lt;P&gt;Hash Diff -&amp;nbsp; FD62862B6DC213BEE77C2BADD6311528253C6CB3107E03C16051AA15584ECA1C&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 19:59:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343841#M272956</guid>
      <dc:creator>Jeff_DOC</dc:creator>
      <dc:date>2017-03-23T19:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing and reading a hash value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343845#M272957</link>
      <description>&lt;P&gt;Apologies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Line 3 of the example code should read: hash = sha256("fox");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeff&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 20:02:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343845#M272957</guid>
      <dc:creator>Jeff_DOC</dc:creator>
      <dc:date>2017-03-23T20:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing and reading a hash value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343888#M272958</link>
      <description>&lt;P&gt;If you click on the "cog" or "gear" icon in you post there should be an option to "Edit Reply". You can click there to make corrections or additions needed. Then people won't have to find your post with the correction. Which can be fun with this forum as we have miminal control over the order posts appear to readers and that correction could end up below many posts. Some of which may ask about that value.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 21:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343888#M272958</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-23T21:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing and reading a hash value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343891#M272959</link>
      <description>&lt;P&gt;I'm not sure I'm 100% following your question, let me see if I got this. &amp;nbsp;You have a table (call it TABLE_A) that contains (at least) 2 columns, one of the columns being some text or numeric values (we'll call it column PLAIN_A) and another column which contains the hashed value of contents of column A (call it column HASH_A). &amp;nbsp;Is your question can you lookup values in that table using either PLAIN_A or HASH_A as a key? &amp;nbsp;If so, then yes if you know one of the values in the columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You need to be careful with hash functions though since they're very sensitive to how data is fed to them, make sure everything is (or isn't) quoted identically. &amp;nbsp;Any change in the input to the hash function will (by design) completely change the hash value.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 21:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343891#M272959</guid>
      <dc:creator>Sven111</dc:creator>
      <dc:date>2017-03-23T21:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing and reading a hash value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343894#M272960</link>
      <description>Your data step code isn't working since you refer ta a non existent variable. &lt;BR /&gt;&lt;BR /&gt;Not sure if I follow your inquiry but I think the answer is yes. &lt;BR /&gt;&lt;BR /&gt;Hashes isn't considered safe when the domain values are known. It could be better protected by using a salt (a secret string that is concatenated prior to the hash operation).</description>
      <pubDate>Thu, 23 Mar 2017 21:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343894#M272960</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-03-23T21:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing and reading a hash value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343897#M272961</link>
      <description>&lt;P&gt;Thank you for the advice.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 22:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343897#M272961</guid>
      <dc:creator>Jeff_DOC</dc:creator>
      <dc:date>2017-03-23T22:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing and reading a hash value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343898#M272962</link>
      <description>&lt;P&gt;You stated it better than I did. Yes, I have two tables. Table A has a value PLAIN_A, and hash value HASH_A. Table B has many vaues PLAIN_B. Can I use the same hash function to hash all vaues in Table B by creating HASH_B and then compare HASH_A and HASH_B to find the PLAIN_B value in Table B?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 22:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343898#M272962</guid>
      <dc:creator>Jeff_DOC</dc:creator>
      <dc:date>2017-03-23T22:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing and reading a hash value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343901#M272963</link>
      <description>Thank you. I inadvertently left an artifact. I replied to my post that it should have been fox. My apologies.</description>
      <pubDate>Thu, 23 Mar 2017 22:21:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343901#M272963</guid>
      <dc:creator>Jeff_DOC</dc:creator>
      <dc:date>2017-03-23T22:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing and reading a hash value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343905#M272964</link>
      <description>&lt;P&gt;Yes that should work, but if you have the plain values for both columns in both tables, why not just match up&amp;nbsp;PLAIN_A to PLAIN_B directly? &amp;nbsp;You wouldn't need to worry about hashing anything, you could&amp;nbsp;just use a standard PROC SQL JOIN. &amp;nbsp;You could do a join on the hashed values too once you created HASH_B, but again that seems like it's just an extra step that isn't really providing any value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What problem are you actually trying to solve? &amp;nbsp;Hashing is a great tool to have handy, but I'm not sure it's doing you any favors in this case, unless you're just trying to learn how to use it for its own sake.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 22:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343905#M272964</guid>
      <dc:creator>Sven111</dc:creator>
      <dc:date>2017-03-23T22:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing and reading a hash value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343907#M272965</link>
      <description>The question we were discussing was is it a valid strategy to hash a value prior to sending date and have the receiving end match the information to their own records. The hashed value may not be pubic information so it would be a way to obscure it prior to transport. My colleague stated it was a valid attempt at security. I know little about hashing but it seems as though if the information can be reconstructed this simply it's not the best option. &lt;BR /&gt;For some reason I cannot get SAS to match the hashed values in as being alike so I assumed I was doing something incorrect.</description>
      <pubDate>Thu, 23 Mar 2017 22:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343907#M272965</guid>
      <dc:creator>Jeff_DOC</dc:creator>
      <dc:date>2017-03-23T22:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing and reading a hash value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343911#M272966</link>
      <description>&lt;P&gt;That makes a lot of sense then, that general approach actually how passwords are validated in most cases. You should be able to match everything up, but like I mentioned previously you need to ensure everything is hashed identically. &amp;nbsp;Also if security is the driving concern, you're best off doing as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;&amp;nbsp;recommended and adding a &lt;A href="https://en.wikipedia.org/wiki/Salt_(cryptography)" target="_self"&gt;salt &lt;/A&gt;to the plain text prior to hashing, otherwise you're much more vulnerable to brute-force attacks trying to determine the plaintext value from the hash value. &amp;nbsp;GPU's today can hash at a rate of billions of hashes a second on older algorthims like MD5 and SHA1, and there's a form of attack that uses sometihng called &lt;A href="https://en.wikipedia.org/wiki/Rainbow_table" target="_self"&gt;rainbow tables&lt;/A&gt; that have precomputed plaintext values for various hashed values, but using a salt makes those approaches much harder. &amp;nbsp;There are also &lt;A href="https://en.wikipedia.org/wiki/Argon2" target="_self"&gt;alternative &lt;/A&gt;&lt;A href="https://en.wikipedia.org/wiki/Scrypt" target="_self"&gt;hashing &lt;/A&gt;&lt;A href="https://en.wikipedia.org/wiki/PBKDF2" target="_self"&gt;algorithms &lt;/A&gt;out there specifically designed to minimize the effectiveness of GPU or other brute-force attacks, but I don't think they're implemented in Base SAS. &amp;nbsp;You can also just iterate the hash multiple times to somewhat increase security, or at least increase the cost to brute-force it, but you need to make sure you doing it exactly the same on both sides or they won't match up.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 23:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-reading-a-hash-value/m-p/343911#M272966</guid>
      <dc:creator>Sven111</dc:creator>
      <dc:date>2017-03-23T23:03:20Z</dc:date>
    </item>
  </channel>
</rss>

