<p>How do I make an MD5 hash of a string with Delphi?</p>

[{'answer_id': 58626, 'author': 'devstopfix', 'author_id': 3366, 'author_profile': 'https://Stackoverflow.com/users/3366', 'pm_score': 5, 'selected': False, 'text': '<p>If you want an MD5 digest and have the <a href="http://www.indyproject.org" rel="nofollow noreferrer">Indy</a> components installed, you can do this:</p>\n\n<pre><code>uses SysUtils, IdGlobal, IdHash, IdHashMessageDigest;\n\nwith TIdHashMessageDigest5.Create do\ntry\n    Result := TIdHash128.AsHex(HashValue(\'Hello, world\'));\nfinally\n    Free;\nend;\n</code></pre>\n\n<p>Most popular algorithms are supported in the <a href="http://www.cityinthesky.co.uk/opensource/dcpcrypt/" rel="nofollow noreferrer">Delphi Cryptography Package</a>:</p>\n\n<ul>\n<li>Haval</li>\n<li>MD4, MD5</li>\n<li>RipeMD-128, RipeMD-160</li>\n<li>SHA-1, SHA-256, SHA-384, SHA-512,</li>\n<li>Tiger</li>\n</ul>\n\n<p><strong>Update</strong>\n<code>DCPCrypt</code> is now maintained by <a href="https://stackoverflow.com/users/84704/warren-p">Warren Postma</a> and source can be found <a href="https://bitbucket.org/wpostma/dcpcrypt2010" rel="nofollow noreferrer">here</a>.</p>\n'}, {'answer_id': 59471, 'author': 'Jim McKeeth', 'author_id': 255, 'author_profile': 'https://Stackoverflow.com/users/255', 'pm_score': 2, 'selected': False, 'text': '<p>You can also use the WindowsCrypto API with Delphi:</p>\n\n<ul>\n<li><a href="http://www.davinciunltd.com/code/delphi-cryptography/" rel="nofollow noreferrer">General Crypto &amp; Hash demo and resources</a></li>\n</ul>\n\n<p>There is a unit in there that wraps all the CryptoAPI.  You can also use Lockbox, which is now open source.  </p>\n\n<p>In the end you can support pretty much any Hash algorithms with Delphi.  The Indy example is probably the closest you will get to natively in Delphi since Indy is included with most versions of Delphi.  For the rest you will need to either use a library or write some more code to access the CryptoAPI or implement it yourself.</p>\n'}, {'answer_id': 83202, 'author': 'Schalk Versteeg', 'author_id': 15724, 'author_profile': 'https://Stackoverflow.com/users/15724', 'pm_score': 4, 'selected': False, 'text': '<p>I usually use DCPCrypt2 (<a href="http://www.cityinthesky.co.uk/opensource/dcpcrypt/" rel="nofollow noreferrer">Delphi Cryptography Package</a>) from David Barton (<a href="http://www.cityinthesky.co.uk/opensource/" rel="nofollow noreferrer">City in the Sky</a>).</p>\n\n<p>It is also contains the following Encryption Algorithms:</p>\n\n<ul>\n<li>Blowfish</li>\n<li>Cast 128</li>\n<li>Cast 256</li>\n<li>DES, 3DES</li>\n<li>Ice, Thin Ice, Ice2</li>\n<li>IDEA</li>\n<li>Mars</li>\n<li>Misty1</li>\n<li>RC2, RC4, RC5, RC6</li>\n<li>Rijndael (the new AES)</li>\n<li>Serpent</li>\n<li>Tea</li>\n<li>Twofish</li>\n</ul>\n\n<p><strong>Update</strong>\n<code>DCPCrypt</code> is now maintained by <a href="https://stackoverflow.com/users/84704/warren-p">Warren Postma</a> and source can be found <a href="https://bitbucket.org/wpostma/dcpcrypt2010" rel="nofollow noreferrer">here</a>.</p>\n'}, {'answer_id': 7412013, 'author': 'mjn', 'author_id': 80901, 'author_profile': 'https://Stackoverflow.com/users/80901', 'pm_score': 3, 'selected': False, 'text': '<p>If all you want to do is use a dictionary, and you\'re not looking for security then:<br>\nIn Delphi 2009 and higher, hash values for strings can be created with</p>\n\n<p><strong><a href="http://docwiki.embarcadero.com/VCL/en/Generics.Defaults.BobJenkinsHash" rel="nofollow"><code>BobJenkinsHash</code></a><code>(Value, Length(Value) * SizeOf(Value), 0)</code></strong> </p>\n\n<p>where Value is a string. </p>\n\n<p><a href="http://docwiki.embarcadero.com/VCL/en/Generics.Defaults.BobJenkinsHash" rel="nofollow">http://docwiki.embarcadero.com/VCL/en/Generics.Defaults.BobJenkinsHash</a></p>\n'}, {'answer_id': 8505190, 'author': 'Sean B. Durkin', 'author_id': 10823, 'author_profile': 'https://Stackoverflow.com/users/10823', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://lockbox.seanbdurkin.id.au/tiki-index.php" rel="nofollow">TurboPower Lockbox</a> supports:</p>\n\n<ul>\n<li>MD-5,</li>\n<li>SHA-1 and</li>\n<li>the entire SHA-2 family including the recently published SHA-512/224 &amp; SHA-512/256 hashes.</li>\n</ul>\n'}, {'answer_id': 18233500, 'author': 'Stéphane B.', 'author_id': 281600, 'author_profile': 'https://Stackoverflow.com/users/281600', 'pm_score': 4, 'selected': False, 'text': '<p>If you want an <strong>MD5 hash</strong> string as hexadeciamal and you have <strong>Delphi XE 1</strong> installed, so you have <strong>Indy 10</strong>.5.7 components  you can do this:</p>\n\n<blockquote>\n  <p>uses   IdGlobal,   IdHash,   IdHashMessageDigest;</p>\n</blockquote>\n\n<pre><code>class function getMd5HashString(value: string): string;\nvar\n    hashMessageDigest5 : TIdHashMessageDigest5;\nbegin\n    hashMessageDigest5 := nil;\n    try\n        hashMessageDigest5 := TIdHashMessageDigest5.Create;\n        Result := IdGlobal.IndyLowerCase ( hashMessageDigest5.HashStringAsHex ( value ) );\n    finally\n        hashMessageDigest5.Free;\n    end;\nend;\n</code></pre>\n'}, {'answer_id': 21187716, 'author': "Arioch 'The", 'author_id': 976391, 'author_profile': 'https://Stackoverflow.com/users/976391', 'pm_score': 3, 'selected': False, 'text': '<p>Spring For Delphi project - <a href="http://www.spring4d.org" rel="noreferrer">http://www.spring4d.org</a> - has implementation for a number of SHAxxx hashes, MD5 hash, and also number of CRC functions</p>\n'}, {'answer_id': 28132865, 'author': 'StanE', 'author_id': 1854856, 'author_profile': 'https://Stackoverflow.com/users/1854856', 'pm_score': 3, 'selected': False, 'text': "<p>This is a modification of devstopfix's answer which was accepted.</p>\n\n<p>In current Indy version you can hash strings and streams more easily. Example:</p>\n\n<pre><code>function MD5String(str: String): String;\nbegin\n  with TIdHashMessageDigest5.Create do\n    try\n      Result := HashStringAsHex(str);\n    finally\n      Free;\n    end;\nend;\n</code></pre>\n\n<p>Use <code>HashString</code>, <code>HashStringAsHex</code>, <code>HashBytes</code>, <code>HashBytesAsHex</code>, <code>HashStream</code>, <code>HashStreamAsHex</code>. The advantage is that you can also specify a text encoding</p>\n"}, {'answer_id': 60602595, 'author': 'fpiette', 'author_id': 189103, 'author_profile': 'https://Stackoverflow.com/users/189103', 'pm_score': 1, 'selected': False, 'text': '<p>Using ICS, you simply call StrMD5 function which is located in OverbytecsMD5 unit.</p>\n\n<p>Beside that specific function, there are a lot more MD5 function for other datatypes and scenarios. There are also other hash methods such as SHA.</p>\n'}, {'answer_id': 60603912, 'author': 'Schneider Infosystems Ltd', 'author_id': 2685300, 'author_profile': 'https://Stackoverflow.com/users/2685300', 'pm_score': 4, 'selected': False, 'text': '<p>Why not use the <code>system.Hash</code> unit from RTL, that contains also a hash algorithm for MD5 since Delphi Seattle?</p>\n\n<pre><code>MD5HashCode := THashMD5.GetHashString(ClearTextString);\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/58621', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3366/']