<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Code & Shield Chronicles]]></title><description><![CDATA[Code & Shield Chronicles]]></description><link>https://blog.pranilshrestha.com.np</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Apr 2026 11:34:52 GMT</lastBuildDate><atom:link href="https://blog.pranilshrestha.com.np/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Exploring Secure Hash Functions: A Guide for Developers and Security Enthusiasts]]></title><description><![CDATA[Introduction to Hash Functions
As a backend developer, you probably use hashes all the time—maybe without giving them much thought. They’re usually used in things like password storage, file integrity checks, or generating cache keys. But not all has...]]></description><link>https://blog.pranilshrestha.com.np/exploring-secure-hash-functions-a-guide-for-developers-and-security-enthusiasts</link><guid isPermaLink="true">https://blog.pranilshrestha.com.np/exploring-secure-hash-functions-a-guide-for-developers-and-security-enthusiasts</guid><category><![CDATA[hashfunctions]]></category><category><![CDATA[hash functions]]></category><category><![CDATA[securityawareness]]></category><category><![CDATA[Security]]></category><dc:creator><![CDATA[Pranil Shrestha]]></dc:creator><pubDate>Sat, 02 Aug 2025 04:40:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1754071565638/ad9ddea5-00e8-4958-ae7c-825f42b88104.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction-to-hash-functions">Introduction to Hash Functions</h2>
<p>As a backend developer, you probably use hashes all the time—maybe without giving them much thought. They’re usually used in things like password storage, file integrity checks, or generating cache keys. But not all hash functions are the same, and picking the wrong one can create a serious security risks.</p>
<p>In this post, we’ll go beyond the usual suspects like MD5 and SHA-1 and take a practical, security-focused look at hash functions. We’ll break down what hashing really is, highlight common mistakes developers make, compare popular algorithms, and even crack some hashes to get inside the mind of an attacker.</p>
<h2 id="heading-what-hash-functions-actually-do">What hash functions actually do?</h2>
<p>At their core a hash function is are mathmatical algorithms that take input data and return a fixed sized string of characters, which is usually a hexadecimal value, you can think of it like a <strong>digial fingerprint</strong> — unique to the input and irreversible by nature.</p>
<h3 id="heading-key-properties">Key properties:</h3>
<ul>
<li><p><strong>Deterministic</strong>: Same input always produces the same output.</p>
</li>
<li><p><strong>Irreversible</strong>: You cannot derive the original input from the hash.</p>
</li>
<li><p><strong>Fixed Output</strong>: Input of any length results in a fixed-sized hash.</p>
</li>
<li><p><strong>Collision-resistant</strong>: Two different input should not product same hash (though some weak hash functions fail here).</p>
</li>
</ul>
<blockquote>
<p><strong>Caution</strong>: Hashing is <strong>NOT</strong> encryption. Encryption are reversible by nature using a key while hashing is not.</p>
</blockquote>
<h2 id="heading-typical-places-hashes-are-found-in">Typical Places Hashes Are Found In:</h2>
<p>Hashing are used in many places, often with or without a developer realizing it:</p>
<ol>
<li><h3 id="heading-password-storage">Password Storage</h3>
</li>
</ol>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> bcrypt

pasword = <span class="hljs-string">b"mysecretpassword123"</span>
hashed = bcrypt.hashpw(password, bcrypt.gensalt())
</code></pre>
<ol start="2">
<li><h3 id="heading-cache-keys">Cache Keys</h3>
</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> key = crypto.createHash(<span class="hljs-string">'sha256'</span>).update(<span class="hljs-built_in">JSON</span>.stringify(query)).digest(<span class="hljs-string">'hex'</span>);
</code></pre>
<ol start="3">
<li><h3 id="heading-file-integrity-checks">File Integrity Checks</h3>
</li>
</ol>
<pre><code class="lang-bash">sha256sum myfile.zip
</code></pre>
<ol start="4">
<li><h3 id="heading-api-authentication-hmacs">API Authentication (HMACs)</h3>
</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> crypto = <span class="hljs-built_in">require</span>(<span class="hljs-string">'crypto'</span>);
<span class="hljs-keyword">const</span> hmac = crypto.createHmac(<span class="hljs-string">'sha256'</span>, secret).update(data).digest(<span class="hljs-string">'hex'</span>);
</code></pre>
<ol start="5">
<li><h3 id="heading-blockchain">Blockchain</h3>
</li>
</ol>
<p>Used for transaction verification, block headers and so on.</p>
<h2 id="heading-common-mistakes-while-using-hash-functions">Common Mistakes While Using Hash Functions:</h2>
<p>Many developers misuse or misunderstand the use of hash functions. Below are some real-word issues:</p>
<ul>
<li><p>Encrypting a password with MD5 is not secure as they are prone to hash collisions and rainbow table attacks.</p>
</li>
<li><p>No salting in your hashes which makes it equal to rainbow table fodders.</p>
</li>
<li><p>Using fast hashes (like SHA-256) for passwords which makes brute forcing it easier.</p>
</li>
<li><p>Logging hashes as plain text, which makes them vulnerable.</p>
</li>
</ul>
<blockquote>
<p>What is hash collision?</p>
<p>→ A hash collision occurs when two different input to a hash functions produce the same hash value, or output.</p>
<p>→ Typically in weaker hash algorithms</p>
<p>→ In security it is a great risk beacause if an attacker can find two different inputs with same hash output, then it can potentially compromise a system that relies on this type of hash function.</p>
<p>What are rainbow table attacks?</p>
<p>→ Rainbow table attacks are similar to dictionary attacks, but they use a rainbow table instead of word list. Although similar to dictionary attack they need less computing power.</p>
<p>→ Rainbow table are pre-computed lists used to crack hashes</p>
</blockquote>
<h2 id="heading-hash-functions-comparison">Hash Functions Comparison</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Hash</strong></td><td><strong>Secure?</strong></td><td><strong>Use Case</strong></td><td><strong>Speed</strong></td><td>Notes</td></tr>
</thead>
<tbody>
<tr>
<td><strong>MD5</strong></td><td><strong>No</strong></td><td>Legacy only</td><td>Fast</td><td>Broken, avoid at all costs</td></tr>
<tr>
<td><strong>SHA-1</strong></td><td><strong>No</strong></td><td>Git internals</td><td>Fast</td><td>Collision-prone</td></tr>
<tr>
<td><strong>SHA-256</strong></td><td><strong>Yes</strong></td><td>Checksums, HMAC</td><td>Faster</td><td>Industry standard</td></tr>
<tr>
<td><strong>SHA-3</strong></td><td><strong>Yes</strong></td><td>Modern secure apps</td><td>Not too fast Not too Slow</td><td>Highly secure</td></tr>
<tr>
<td><strong>bcrypt</strong></td><td><strong>Yes</strong></td><td>Passwords</td><td>Slow</td><td>Adds salt, adaptive</td></tr>
<tr>
<td><strong>scrypt</strong></td><td><strong>Yes</strong></td><td>Key derivation</td><td>Slow</td><td>Memory-hard</td></tr>
<tr>
<td><strong>Argon2</strong></td><td><strong>Better</strong></td><td>Passwords (best pick)</td><td>Slow</td><td>PHC winner, best practice</td></tr>
<tr>
<td><strong>Blake3</strong></td><td><strong>Yes</strong></td><td>File integrity</td><td>Fastest</td><td>Modern alternative to SHA-3</td></tr>
</tbody>
</table>
</div><h2 id="heading-think-like-an-attacker-cracking-weak-hashes">Think Like An Attacker: Cracking Weak Hashes</h2>
<p>Let’s demonstrate how fast some hashes can be cracked or broken.</p>
<h4 id="heading-example-md5">Example MD5:</h4>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> -n <span class="hljs-string">"Password@123"</span> | md5sum
d00f5d5217896fb7fd601412cb890830   <span class="hljs-comment"># &lt;- this is the output</span>
</code></pre>
<p>Using crackstation to crack the hash:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754109130253/f126269d-dafd-44e9-8d8b-1fca72531d37.png" alt class="image--center mx-auto" /></p>
<blockquote>
<p>Reasons: No Salt, Weak and Fast algorithm and Public rainbow tables available</p>
<p>Tools that attacker use: <code>hashcat</code>, <code>john the ripper</code>, <code>crackstation</code> and so on</p>
</blockquote>
<h2 id="heading-chooseing-the-right-hash-for-the-job">Chooseing The Right Hash For The Job</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Task</strong></td><td><strong>Recommended Hash</strong></td></tr>
</thead>
<tbody>
<tr>
<td>Password storage</td><td>Argon2 &gt; bcrypt &gt; scrypt</td></tr>
<tr>
<td>File integrity</td><td>SHA-256 / Blake3</td></tr>
<tr>
<td>API request signing</td><td>HMAC with SHA-256</td></tr>
<tr>
<td>Key derivation</td><td>scrypt, Argon2, PBKDF2</td></tr>
<tr>
<td>Blockchain applications</td><td>SHA-256 or SHA-3</td></tr>
</tbody>
</table>
</div><blockquote>
<p>Golden Rule: If its fast then its bad for passwords.</p>
</blockquote>
<h2 id="heading-bonus-tools-and-playgrounds">Bonus Tools And Playgrounds</h2>
<p>Play with hash functions using these tools:</p>
<ul>
<li><p><a target="_blank" href="https://gchq.github.io/CyberChef/">CyberChef</a>: Web-based hash and encoding toolkit</p>
</li>
<li><p><a target="_blank" href="https://crackstation.net/">CrackStation</a>: Online hash cracker</p>
</li>
<li><p><code>bcrypt-cli</code>, <code>argon2-cli</code>: Hash passwords in your terminal</p>
</li>
<li><p>Built-in libraries:</p>
<ul>
<li><p>Node.js: <code>crypto</code>, <code>bcryptjs</code>, <code>argon2</code></p>
</li>
<li><p>Python: <code>hashlib</code>, <code>bcrypt</code>, <code>argon2-cffi</code></p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-final-thoughts">Final Thoughts</h2>
<p>Hashing is a tool; When used well, it powers secure applciations. When misused, it opens door to attackers. If you want to develop a secure application you should try to understand the tools that you use.</p>
]]></content:encoded></item></channel></rss>