title: How to get same hash for numbers in Oracle and in C#?
body: <p>In my Oracle 12c database I have sequential primary keys I want to encrypt using SHA256 (SHA1 might suffice too) so that when using them in URLs it will not be easy to guess other relevant keys.</p>
  
  <p>As I understand I can use Oracle 12c's <code>STANDARD_HASH</code> function to compute these. For example:</p>
  
  <pre><code>select standard_hash(5000000884, 'SHA256') from dual;
  &gt;&gt; 340B6B758A184AD6A17959278F1419AF180CCAA26CC53D39853E45F572523E0D
  </code></pre>
  
  <p>I can create an index on the table using that function. I will also need to generate the same hash in C# so that later I can match it to the index. I tried using <code>System.Security.Cryptography.SHA256Managed</code> to compute the same hash but its <code>ComputeHash</code> method only accepts either a <code>string</code> or a <code>byte[]</code> while I have a <code>decimal</code>.</p>
  
  <p>I can get the same hash results if I treat the numbers as strings both in C# and in Oracle, but that's probably unnecessary overhead I want to avoid.</p>
  
  <p>I guess the main gap is that I don't know how Oracle treats a number as input to a hash function since I can't even get the same result for:</p>
  
  <pre><code>new SHA256Managed().ComputeHash(new byte[]{0})
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>select standard_hash(0, 'SHA256') from dual;
  </code></pre>
  
  <p>How can I get same hash for numbers in Oracle and in C#?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Though it doesn't effect the question it may be relevant for alternative solutions, but I also want my URLs to be short so I will later convert them to base 62. Also, I don't want to provide my primary keys in the URL to prevent the ability to use them through other interfaces.</p>