title: SHA1 hashing in Delphi XE
body: <p>I'm in the process of implementing XML digital signatures. I'm starting with little steps, so right now I want to solve the problem of SHA-1 hashing.</p>
  
  <p>There are lots of questions about this in SO:</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/1783077/digitially-sign-key-with-lockbox">Digitially Sign Key with Lockbox</a></li>
  <li><a href="https://stackoverflow.com/questions/1402380/encryption-library-for-delphi">Encryption library for Delphi</a></li>
  <li><a href="https://stackoverflow.com/questions/1792541/convert-this-php-digital-signing-to-delphi">Convert this php digital signing to Delphi</a></li>
  <li><a href="https://stackoverflow.com/questions/4080825/delphi-is-there-a-version-of-lockbox-for-delphi-xe">Delphi: is there a version of LockBox for Delphi-XE</a></li>
  <li><a href="https://stackoverflow.com/questions/2020216/delphi-2010-cryptography-libraries">Delphi 2010 Cryptography libraries</a></li>
  </ol>
  
  <p>...and probably more. However, I'm using Delphi XE. So far, I've tried LockBox 2 (both the Songbeamer and Sourceforge versions), Lock Box 3, DCPCrypto2 and some others (<a href="http://delphi.jmrds.com/?q=node/36" rel="nofollow noreferrer">Hashes</a> is an easy to use unit which uses Windows crypto functions)</p>
  
  <p>I prepared a small test rig that gives me the following:</p>
  
  <p><strong>LockBox2</strong></p>
  
  <pre><code>FAILED: 1 ('abc') 
         Got: '9f04f41a848514162050e3d68c1a7abb441dc2b5'
    Expected: 'a9993e364706816aba3e25717850c26c9cd0d89d'
  FAILED: 2 ('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq') 
         Got: '51d7d8769ac72c409c5b0e3f69c60adc9a039014'
    Expected: '84983e441c3bd26ebaae4aa1f95129e5e54670f1'
  </code></pre>
  
  <p><strong>LockBox3</strong></p>
  
  <pre><code>FAILED: 1 ('abc') 
         Got: '9f04f41a848514162050e3d68c1a7abb441dc2b5'
    Expected: 'a9993e364706816aba3e25717850c26c9cd0d89d'
  FAILED: 2 ('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq') 
         Got: '51d7d8769ac72c409c5b0e3f69c60adc9a039014'
    Expected: '84983e441c3bd26ebaae4aa1f95129e5e54670f1'
  </code></pre>
  
  <p><strong>DCPCrypto2</strong></p>
  
  <pre><code>FAILED: 1 ('abc') 
         Got: '9f04f41a848514162050e3d68c1a7abb441dc2b5'
    Expected: 'a9993e364706816aba3e25717850c26c9cd0d89d'
  FAILED: 2 ('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq') 
         Got: '51d7d8769ac72c409c5b0e3f69c60adc9a039014'
    Expected: '84983e441c3bd26ebaae4aa1f95129e5e54670f1'
  </code></pre>
  
  <p><strong>Hashes</strong></p>
  
  <pre><code>Test 1 passes
  Test 2 passes
  </code></pre>
  
  <p>Have you succeeded in compile the mentioned libraries under Delphi XE and make them give the appropriate values? I'm particularly interested in <strong>DCPCrypt2</strong> <code>SelfTest</code> procedure.</p>
  
  <p><strong>Edit</strong>: I've added <a href="https://stackoverflow.com/questions/4929650/sha1-hashing-in-delphi-xe/4941040#4941040">this answer</a> with the fixed source code. Thank you all for your help, it is most appreciated.</p>