<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ encryption - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ encryption - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sun, 24 May 2026 16:30:40 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/encryption/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ A Developer's Guide to Protecting Personal Data: Best Practices and Tools ]]>
                </title>
                <description>
                    <![CDATA[ Think about it: you're sitting there enjoying your morning coffee, reading the headlines when again another data breach is making headlines. Millions of users' personal information – gone. You can't help but cringe as a developer at the prospect. Cou... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/developers-guide-to-protecting-personal-data/</link>
                <guid isPermaLink="false">680102ccf67e471495d5a624</guid>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Node.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ APIs ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Personal data protection ]]>
                    </category>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ authentication ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Databases ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Alex Tray ]]>
                </dc:creator>
                <pubDate>Thu, 17 Apr 2025 13:31:56 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1744839185611/b3e49efc-6eee-4a0b-9522-20407b1782e3.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Think about it: you're sitting there enjoying your morning coffee, reading the headlines when again another data breach is making headlines. Millions of users' personal information – gone. You can't help but cringe as a developer at the prospect. Could it happen on your watch?</p>
<p>The reality is, keeping personal data safe isn't something you should be doing because it's good practice – it's something you have to do. Users are trusting developers to care for their data day in and day out, and power must be wielded wisely. If you're writing code that involves getting, processing, or storing someone's personal data, then you should be being proactive about keeping it safe.</p>
<p>So the question is: how do you safely keep personal data?</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<p></p><dl><p></p>
<p></p><ul><p></p>
<p></p><li><a href="heading-know-what-youre-protecting">Know What You</a></li><p></p>
<h2 id="heading-know-what-youre-protecting">Know What You're Protecting</h2>
<p>If you must protect information, first determine what information must be protected. It is crucial to <a target="_blank" href="https://blog.incogni.com/opt-out-guides/">protect sensitive information</a> from unauthorized access to ensure data security. Below is a list of some common types of sensitive data:</p>
<ul>
<li><p>Personally Identifiable Information (PII): name, address, phone number, email, Social Security number.</p>
</li>
<li><p>Financial Data: bank details, payment history, credit card number.</p>
</li>
<li><p>Authentication Data: password, auth tokens, API keys, security question responses.</p>
</li>
<li><p>Health Info: any kind of <a target="_blank" href="https://www.jotform.com/what-is-hipaa-compliance/">HIPAA</a>-protected information about the health and medical history of the user.</p>
</li>
</ul>
<p>Once you know what information has to be rendered secure, then you can go ahead and render it secure.</p>
<h2 id="heading-best-practices-in-data-security">Best Practices in Data Security</h2>
<h3 id="heading-1-encrypt-everything">1. Encrypt Everything</h3>
<p>Your best protection against hacking is encryption. When data is encrypted, even if hackers have access to it, they cannot do anything with it in the absence of the decryption key.</p>
<p>For stored sensitive information, use <strong>hashing with a salt</strong>, a process that turns a password into an irreversible value. This way, even if someone gains access to the stored data, the actual password isn't exposed.</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> hashlib
<span class="hljs-keyword">import</span> os

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hash_password</span>(<span class="hljs-params">password</span>):</span>
    salt = os.urandom(<span class="hljs-number">32</span>)  <span class="hljs-comment"># Generate a new salt</span>
    hashed_password = hashlib.pbkdf2_hmac(<span class="hljs-string">'sha256'</span>, password.encode(<span class="hljs-string">'utf-8'</span>), salt, <span class="hljs-number">100000</span>)
    <span class="hljs-keyword">return</span> salt + hashed_password
</code></pre>
<p>For data in transit, always use HTTPS:</p>
<pre><code class="lang-bash">sudo certbot --nginx -d yourdomain.com
</code></pre>
<p>This ensures data is encrypted between your server and the user. You can also reduce how often data is in transit by using <a target="_blank" href="https://www.suse.com/c/what-is-edge-computing/">edge computing</a>. Rather than sending sensitive data to external servers, increasing risk, it allows data to be stored and processed locally.</p>
<h3 id="heading-2-perform-secure-authentication">2. Perform Secure Authentication</h3>
<p>Weak authentication is an extremely critical security vulnerability.</p>
<p><strong>Authentication</strong> is the process of verifying who a user is (for example, logging in), while <strong>authorization</strong> is verifying what they're allowed to do (for example, access admin features).</p>
<p>Make sure that you:</p>
<ul>
<li><p>Perform strong password habits.</p>
</li>
<li><p>Perform multi-factor authentication (MFA). MFA requires users to present two or more verification factors (for example password and one-time code from a mobile device), making it much harder for attackers to gain access.</p>
</li>
<li><p>Perform OAuth 2.0 or OpenID Connect third-party authentication. These are secure industry-standard protocols that allow users to authenticate via trusted platforms like Google or Facebook, reducing the need to store credentials yourself.</p>
</li>
</ul>
<p>Example: Here’s an authentication setup using JWT (JSON Web Tokens) in Python:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> jwt
<span class="hljs-keyword">import</span> datetime

SECRET_KEY = <span class="hljs-string">"your_secret_key"</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">generate_token</span>(<span class="hljs-params">user_id</span>):</span>
    payload = {
        <span class="hljs-string">"user_id"</span>: user_id,
        <span class="hljs-string">"exp"</span>: datetime.datetime.utcnow() + datetime.timedelta(hours=<span class="hljs-number">1</span>)
    }
    <span class="hljs-keyword">return</span> jwt.encode(payload, SECRET_KEY, algorithm=<span class="hljs-string">'HS256'</span>)
</code></pre>
<p>This function generates a secure token for a user. The token contains the user ID and an expiration time, and it's signed using a secret key. Clients send this token with each request, and servers verify it to ensure the request comes from an authenticated user.</p>
<h3 id="heading-3-minimize-the-data-you-need-to-store">3. Minimize the Data You Need to Store</h3>
<p>One of the simplest things you can do to protect personal data? Store less than you have to. Consider the following questions:</p>
<ul>
<li><p>Do I really need to store this data?</p>
</li>
<li><p>How long do I really need to keep it for?</p>
</li>
<li><p>Can I anonymise it?</p>
</li>
</ul>
<p>For example, if you are going to need analytics, consider deleting personal identifiers prior to storing the data:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> anonymizeData = <span class="hljs-function">(<span class="hljs-params">user</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> {
        <span class="hljs-attr">sessionId</span>: generateRandomId(),
        <span class="hljs-attr">event</span>: user.event,
        <span class="hljs-attr">timestamp</span>: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().toISOString()
    };
};
</code></pre>
<p>This JavaScript function removes identifying information (like name or email) and replaces it with a random session ID, keeping only the data necessary for analytics.</p>
<p>For instance, if you manage email lists, avoid storing unnecessary subscriber data beyond what is required for communication.</p>
<p>Regularly clean and scrub email lists to remove outdated or inactive addresses. Sending emails to outdated/inactive addresses can damage your domain reputation, leading to blacklisting and email deliverability issues. If you only need email addresses for temporary campaigns, consider <a target="_blank" href="https://support.google.com/a/answer/151128?hl=en">automated deletion policies</a> to remove old data.</p>
<h3 id="heading-4-secure-your-apis">4. Secure Your APIs</h3>
<p>If your application is consuming other services, protect your API endpoints. You can do this by:</p>
<ul>
<li><p><strong>Require tokens or API keys</strong>: These act as credentials to access the API and prevent unauthorized use.</p>
</li>
<li><p><strong>Implement rate limiting to deter abuse</strong>: This prevents attackers from flooding your server with too many requests.</p>
</li>
<li><p><strong>Validate and sanitize all input data</strong>: This protects against injection attacks and malformed inputs.</p>
</li>
</ul>
<p>Here's how you can validate API input in Node.js:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">'express'</span>);
<span class="hljs-keyword">const</span> app = express();

app.post(<span class="hljs-string">'/api/data'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> { name, email } = req.body;
    <span class="hljs-keyword">if</span> (!name || !email.includes(<span class="hljs-string">'@'</span>)) {
        <span class="hljs-keyword">return</span> res.status(<span class="hljs-number">400</span>).send(<span class="hljs-string">'Invalid input'</span>);
    }
    res.send(<span class="hljs-string">'Data received'</span>);
});
</code></pre>
<p>This ensures the API receives valid data and returns an error for incorrect input, which is a basic form of input sanitization.</p>
<h3 id="heading-5-lock-down-your-database">5. Lock Down Your Database</h3>
<p>Your database is an attack treasure trove, so lock it down:</p>
<ul>
<li><p><strong>Use parameterized queries</strong> to prevent SQL injection. These queries separate data from code.</p>
</li>
<li><p><strong>Limit database access using role-based permissions</strong>: Only give each user or service the access it needs—no more.</p>
</li>
<li><p><strong>Back up and test restoration procedures</strong>: Regular backups ensure you can recover data in the event of a breach or corruption.</p>
</li>
</ul>
<p>Here's a safe way to query a database in Python:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> sqlite3

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_user</span>(<span class="hljs-params">email</span>):</span>
    conn = sqlite3.connect(<span class="hljs-string">'database.db'</span>)
    cursor = conn.cursor()
    cursor.execute(<span class="hljs-string">"SELECT * FROM users WHERE email = ?"</span>, (email,))
    <span class="hljs-keyword">return</span> cursor.fetchone()
</code></pre>
<p>This example uses a parameterized query (the ? placeholder) to safely insert the email into the SQL command, protecting against injection.</p>
<p>Also, never overlook how databases and internal systems might be accessed remotely. Remote access, whether for IT admins, support teams, or mobile workers, often involves logging in from unfamiliar devices—which introduces new security challenges. Tools that allow for secure, contactless logins without typing passwords or installing software on the remote machine reduce the risk of credential theft.</p>
<p>You can also ensure that remote database connections, SSH access, and admin panels are protected with strong authentication, IP restrictions, and, ideally, VPN access to avoid exposing sensitive entry points to the internet.</p>
<p>And remember, you don’t have to reinvent the wheel—there are <a target="_blank" href="http://blog.scalefusion.com/best-data-protection-software/">powerful data protection tools</a> available to keep your data safe from breaches and downtime. Want to know which ones stand out? Check out this guide for a breakdown of some of the best solutions.</p>
<h3 id="heading-6-periodically-audit-and-update-your-code">6. Periodically Audit and Update Your Code</h3>
<p>Unpatched software and outdated dependencies are essentially an open invitation to the attackers. Update your software and conduct security audits regularly.</p>
<p>Perform security scans for your project:</p>
<pre><code class="lang-javascript">npm audit fix --force  # For Node.js projects
</code></pre>
<pre><code class="lang-python">pip install --upgrade package_name  <span class="hljs-comment"># For Python projects</span>
</code></pre>
<p>These commands help find and fix known vulnerabilities in your project dependencies.</p>
<h3 id="heading-7-train-your-employees">7. Train Your Employees</h3>
<p>Your security is just as strong as your weakest link. If one employee handles sensitive data irresponsibly, everything else may have been for naught.</p>
<ul>
<li><p><strong>Standard security training</strong>: Regular sessions on topics like phishing, password security, and data handling.</p>
</li>
<li><p><strong>Implement solid policies on user data handling</strong>: For instance, never download sensitive data to personal devices.</p>
</li>
<li><p><strong>Establish a security-oriented culture</strong>: Encourage reporting of suspicious activity, regular internal audits, and open communication about threats.</p>
</li>
</ul>
<h3 id="heading-8-give-users-control-over-their-data">8. Give Users Control Over Their Data</h3>
<p>Transparency breeds trust. Give users control to:</p>
<ul>
<li><p>View and download their data.</p>
</li>
<li><p>Terminate their account easily.</p>
</li>
<li><p>Make adjustments in privacy settings.</p>
</li>
</ul>
<p>If you are collecting data, provide an opt-out. Users must be able to protect sensitive data and be in control of what becomes of their information. This is why it is important to have a privacy policy: users need to know what data you are collecting and for what purpose. Check out this <a target="_blank" href="https://www.iubenda.com/en/help/36387-privacy-policy-template">privacy policy template</a> if you need to create one for your site.</p>
<h2 id="heading-final-thoughts">Final Thoughts</h2>
<p>Data protection isn't just about coding well—it's about attitude. Get in the head of an attacker for a day, minimize vulnerabilities, and put user privacy at the top of your mind.</p>
<p>So the next time you're scanning the headlines for news of the latest ginormous data breach, you can be confident that your apps are bulletproof. Be smart, continue to learn, and let's make the internet safe—one line of secure code at a time.</p>
</ul></dl> ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How SSH Authentication with GitHub Works Under the Hood ]]>
                </title>
                <description>
                    <![CDATA[ SSH (Secure Shell) is a client-server protocol for connecting and authenticating to a remote server. Authentication means that the remote server can verify that it’s actually you and not somebody else talking on your behalf. You may already be using ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/ssh-authentication-with-github-under-the-hood/</link>
                <guid isPermaLink="false">67ace33e18a2c0de81d7ffc3</guid>
                
                    <category>
                        <![CDATA[ ssh ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ public-key cryptgraphy ]]>
                    </category>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Vivek Agrawal ]]>
                </dc:creator>
                <pubDate>Wed, 12 Feb 2025 18:06:54 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1739082652213/aba38efa-117c-4ef7-a844-91599c0a4d62.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>SSH (Secure Shell) is a client-server protocol for connecting and authenticating to a remote server.</p>
<p>Authentication means that the remote server can verify that it’s actually you and not somebody else talking on your behalf.</p>
<p>You may already be using GitHub’s SSH authentication, but do you know how it actually works? In this article, you’ll learn what happens under the hood and how SSH authentication actually works.</p>
<p>Along the way, you’ll understand the fundamental concepts of cryptography that every developer should know about: symmetric key encryption, asymmetric key encryption, cryptographic hash functions, and digital signatures.</p>
<p>Some developers usually don’t get the chance to learn and understand these cryptography fundamentals, but these concepts will help you in the long run. Also, they’ll help you be in a much better position to take informed security decisions for your production web applications.</p>
<p>So come on, fasten your seat belts, and let’s start!</p>
<h3 id="heading-heres-what-well-cover">Here’s what we’ll cover:</h3>
<ol>
<li><p><a class="post-section-overview" href="#heading-first-why-is-authentication-so-important">First, Why is Authentication So Important?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-symmetric-key-encryption">Symmetric Key Encryption</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-asymmetric-key-encryption">Asymmetric Key Encryption</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-cryptographic-hash-functions">Cryptographic Hash Functions</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-digital-signatures">Digital Signatures</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-ssh-authentication-works">How SSH Authentication Works</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-wrapping-it-all-up">Wrapping it All Up</a></p>
</li>
</ol>
<h2 id="heading-first-why-is-authentication-so-important">First, Why is Authentication So Important?</h2>
<p>When we run <code>git push</code>, GitHub needs to verify that the right person is interacting with GitHub. Imagine if an attacker could manage to do <code>git push</code> on your behalf.</p>
<p>Then all your repositories would be under that attacker's control. They could delete all your code along with all the commit history.</p>
<p>This sounds quite dangerous, doesn’t it? So to verify that it’s actually you who’s talking to GitHub, and not an attacker, GitHub has several ways to authenticate you.</p>
<p>The most widely used method to authenticate with GitHub is SSH authentication.</p>
<p>Before we understand how SSH authentication works under the hood, we will need to understand the fundamental cryptography concepts, namely — symmetric key encryption, asymmetric key encryption, cryptographic hash functions, and digital signatures.</p>
<p>Let’s begin!</p>
<h2 id="heading-symmetric-key-encryption">Symmetric Key Encryption</h2>
<p>In the ancient days, rulers devised various methods of communicating secret military messages to their army commanders.</p>
<p>One of the earliest methods, likely used by ancient Greek rulers and possibly later the Romans, involved using a cylindrical wooden rod called a <a target="_blank" href="https://en.wikipedia.org/wiki/Scytale"><strong>Scytale</strong></a>.</p>
<p>Before a military invasion, the ruler would have two exact same cylindrical wooden rods made called scytales. Then he would give one scytale to the army commander and keep one for himself.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1734514827027/b4945c3a-64d4-458b-a410-f23b1a08d9ef.png" alt="A scytale with leather strip wounded and a message written on it." class="image--center mx-auto" width="2012" height="1176" loading="lazy"></p>
<p>The device worked by winding a strip of leather around the scytale. After doing this, the ruler would write the message on top of the wound-up leather strip so that it could only be read when properly wound again.</p>
<p>Suppose the scytale allowed him to write three letters around in a circle and five letters straight across/along its length. The wound leather strip with the message <code>attackfromright</code> written on it would look like this:</p>
<pre><code class="lang-plaintext">       |   |   |   |   |   |
       | a | t | t | a | c |  |
     __| k | f | r | o | m |__|
    |  | r | i | g | h | t |
    |  |   |   |   |   |   |
</code></pre>
<p>After writing the message on the scytale, the ruler would unwind the leather strip and send it to the army commander. When it was unwound, the leather strip would have the following jumbled message:</p>
<pre><code class="lang-plaintext">----------------
akrtfitrgaohcmt
----------------
</code></pre>
<p>So now you see, even if the leather strip got intercepted by an enemy spy, the message would not make sense. Isn't this fascinating? The smart use of a wooden rod and a leather strip might have helped some ancient rulers win battles!</p>
<p>When the leather strip reached the army commander, he would wind it around his own scytale (which would be exactly the same as ruler’s), and then the commander would be able to understand the message properly.</p>
<p>This scytale technique is actually an example of symmetric key encryption in practice.</p>
<p>Encryption is a process in which the original message is modified (or encoded) in such a way that only the intended recipient can decode and see the actual message.</p>
<p>The original message is called plaintext, while the encoded message is called ciphertext. Encryption converts <code>plaintext to ciphertext</code> with the help of a key.</p>
<p>To decrypt the message, that is to convert <code>ciphertext to plaintext</code>, a person must have access to that same key.</p>
<p>If we compare it to the scytale technique, the scytale is the key. The ruler only shares the key (scytale) with the army commander who needs to know what the message says.</p>
<p>Here's what the encryption process looks like:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1734519516607/75c926a3-faec-402a-8bcd-122039f47a01.png" alt="Encryption with scytale as key." class="image--center mx-auto" width="2023" height="526" loading="lazy"></p>
<p>The decryption process will look like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1734519525487/de096889-332c-4482-b2df-b28ce609a8a6.png" alt="Decryption with scytale as key." class="image--center mx-auto" width="1979" height="526" loading="lazy"></p>
<p>We call this symmetric key encryption because the same key is used to both encrypt and decrypt the message.</p>
<p>This key (the scytale) must be kept protected from enemy access. If the enemy get’s access to this key, then they’ll be able to decrypt the messages.</p>
<p>But there’s another type of encryption called asymmetric key encryption. Now that you understand symmetric key encryption, let’s move on to asymmetric key encryption.</p>
<h2 id="heading-asymmetric-key-encryption">Asymmetric Key Encryption</h2>
<p>In symmetric key encryption, like we saw above, the same key was used by both the ruler and the army commander to encrypt and decrypt the message.</p>
<p>But in an asymmetric key encryption, there are two keys (called a key pair). Out of the two keys, one is a private key and the other is a public key.</p>
<p>The public key can be shared with everyone (which is why it’s called public). But the private key is meant to be kept secret! It must never ever be revealed to anybody.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1735200860039/7aca8ffa-c33a-44e5-ab1a-181492ebefd8.png" alt="Public key can be shared with everyone. But the private key must be kept secret." class="image--center mx-auto" width="2714" height="1428" loading="lazy"></p>
<p>The interesting thing about asymmetric key encryption is that, if a message is encrypted with the public key, then it can only be decrypted with the corresponding private key. No other key can decrypt it.</p>
<p>And it works the other way too. If a message is encrypted with the private key then it can only be decrypted using the corresponding public key.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1735120077350/b90901c8-b55c-428a-8eb4-1b8ffa65fa06.png" alt="Illustration of public and private key mathematically linked with each other." class="image--center mx-auto" width="948" height="835" loading="lazy"></p>
<p>The two keys – public and private – are mathematically linked with each other. While one encrypts, the other decrypts.</p>
<p>Just a small note that asymmetric key encryption is also called public key encryption. These two terms are used interchangeably but they mean the same thing.</p>
<h2 id="heading-cryptographic-hash-functions">Cryptographic Hash Functions</h2>
<p>A cryptographic hash function is designed to take in an input of any length and produce a fixed-length output. The fixed-length output is called as hash value.</p>
<p>A popular example of a cryptographic hash function is SHA-256.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1735030835833/201640c6-13b4-4b2b-9be3-88e245269bd1.png" alt="SHA-256 calculation of &quot;freeCodeCamp.org&quot;" class="image--center mx-auto" width="2283" height="285" loading="lazy"></p>
<p>The above image shows the SHA-256 hash value of the input “freeCodeCamp.org“. Cryptographic hash function has three properties that make it very useful (we’ll see how in the coming sections).</p>
<p>First<strong>,</strong> it’s practically impossible to take the hash value and figure out the input from the hash value.</p>
<p>For example, if we are given the hash value <code>c9c31315ef2257e4b7698</code>, there’s no way for us to figure out that the input to the hash function was “freeCodeCamp.org“.</p>
<p>Second<strong>,</strong> if we pass the same input to the hash function, we get the same hash value as output.</p>
<p>If we pass “freeCodeCamp.org“ again to the SHA-256 hash function, we will get the same hash output as our previous call.</p>
<p>Third<strong>,</strong> two different inputs never share the same hash value. Even the slightest change in input produces an entirely different output.</p>
<p>Suppose if we provide “freeCodeCamp“ as input instead of “freeCodeCamp.org“ – we would get a totally different output.</p>
<h2 id="heading-digital-signatures">Digital Signatures</h2>
<p>In your daily lives, you might have to sign various documents. These might be legal documents, or your kids’ school report card, or maybe something else.</p>
<p>When your signature is present on the document, it conveys to the other party that it is you who agrees with whatever is written on that document.</p>
<p>Later on, you cannot walk back from doing what’s written on the document. Correct?</p>
<p>Similarly, in the digital world, we have digital signatures – or we can simply call them signatures.</p>
<p>Let’s understand how signatures works using an example. We have two users named “Alice“ and “Bob“.</p>
<p>Bob wants to transfer some money to Alice’s bank account. So Bob asks Alice about her bank account information.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1735042150046/034d26c5-b33d-4b82-aeb8-173e47cd8e8e.png" alt="An illustration showing alice and bob's computers far away from each other and alice's bank account number." class="image--center mx-auto" width="1972" height="1410" loading="lazy"></p>
<p>Alice knows about digital signatures and decided to use one. At the end, you will understand why Alice opted for a digital signature.</p>
<p>Before Alice can create a digital signature. Alice provides Bob with her public key (and keeps the private key to herself).</p>
<p>Then Alice creates a digital signature and places it at the end of the document.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1735041977880/35313148-8820-42d7-b122-3ddf0cbaa723.png" alt="Process of digital signature generation." class="image--center mx-auto" width="1065" height="471" loading="lazy"></p>
<p>A digital signature is created by first passing the document contents to a cryptographic hash function like SHA-256. In Alice’s case, the document’s content is her bank account number.</p>
<p>Once we get the hash value, it gets encrypted with Alice’s <strong>private key</strong>. The output of this encryption is the signature which gets placed at the end of the document.</p>
<p>This is then sent to Bob over the Internet.</p>
<p>When Bob receives this document, he verifies whether the <strong>signature is valid or not</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1735043216695/256f7707-3f40-433f-9b00-c11b27ef01e8.png" alt="Process of signature verification." class="image--center mx-auto" width="2905" height="1636" loading="lazy"></p>
<p>To verify the signature, Bob first decrypts the signature with Alice’s public key. If you remember, Alice generated the signature by encrypting the hash value.</p>
<pre><code class="lang-plaintext"> plaintext                         ciphertext  
     |                                 |
     |                                 |
     |                                 |
hash value --------encrypt--------&gt; signature
</code></pre>
<p>So, when Bob decrypts the signature, he will get the hash value that Alice calculated. Let’s call this Alice’s hash value.</p>
<pre><code class="lang-plaintext"> ciphertext                         plaintext  
     |                                 |
     |                                 |
     |                                 |
signature --------decrypt--------&gt; hash value
</code></pre>
<p>Then Bob takes the bank account number that’s present on the document and passes it to the hash function.</p>
<p>Finally, Bob matches the Alice’s hash value (the decrypted signature) and the hash value that he just calculated. If both the hash values match then that means the signature is valid.</p>
<p>OK — but why did we need to do all this? What does it mean if the signature is valid?</p>
<p>When the signature verification is successful, it proves two things.</p>
<p>First<strong>,</strong> it proves that the document has been sent by Alice only. Nobody else could have sent this document.</p>
<p>The assurance that only Alice has sent this document comes from the fact that we were able to decrypt the signature using Alice’s public key.</p>
<p>We have learned that if something is encrypted using a private key then it can only be decrypted using its linked public key.</p>
<p>So, if Bob was successfully able to decrypt the signature using Alice’s public key, it means that it was encrypted using Alice’s private key, correct?</p>
<p>And only Alice has access to her private key. This means that Alice is the only person who could have sent this document!</p>
<p>Second<strong>,</strong> it proves that the content of the message has not been modified by an attacker during network transmission.</p>
<p>We did two things to verify the signature. We decrypted the signature, and it gave us the hash value that Alice calculated. And we also hashed the received bank account number.</p>
<p>If the hash value that Alice calculated and the hash value that Bob calculated are the same, this means that Alice and Bob gave exactly the same input to the hash function.</p>
<p>And this means that the bank account number that Alice sent and that Bob received are exactly same.</p>
<p>If an attacker would have changed the bank account number before the document reached Bob, then Bob would’ve received a modified bank account number.</p>
<p>When Bob went to calculate the hash value of this modified bank account number, the hash value would’ve come out to be different than what Alice had calculated.</p>
<p>So while matching Alice’s hash value (decrypted signature) and the hash value that Bob calculated, the matching would fail. And it would prevent Bob from transferring money to the wrong bank account number.</p>
<p>To conclude, when the signature is successfully verified, it means that:</p>
<ol>
<li><p>The document is only from Alice.</p>
</li>
<li><p>The document’s contents were not modified by any third party.</p>
</li>
</ol>
<p>Now you’ve learned about symmetric key encryption, asymmetric key encryption, cryptographic hash functions, and digital signatures. That’s awesome!</p>
<p>We have built a really solid foundation. Now understanding SSH authentication is going to be much easier for you.</p>
<h2 id="heading-how-ssh-authentication-works">How SSH Authentication Works</h2>
<p>If you have not setup SSH authentication with GitHub, then after completing this article you can follow <a target="_blank" href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account">GitHub’s detailed documentation on how to do it</a>. For now, please stay here till the end.</p>
<p>The crux of the setup process is that you create a public and private key pair on your local computer. Then you upload your public key to your GitHub profile – and that’s it!</p>
<p>After we have created our public-private key pair, in Ubuntu, public-private key pair are stored inside the <code>~/.ssh</code> directory.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1735035539565/1f837d9b-9717-44fa-a5e0-5801276113df.png" alt="Showing my public key from my terminal." class="image--center mx-auto" width="4380" height="243" loading="lazy"></p>
<p>The above image shows my public key. I have this public key uploaded to my GitHub profile:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1735035898284/1ef9133a-895b-4847-a7ac-6157fdcc3143.png" alt="Showing my GitHub profile settings where my public key is uploaded for SSH authentication with GitHub." class="image--center mx-auto" width="4287" height="1398" loading="lazy"></p>
<p>Now, when I run <code>git push</code> or any other command that wants to communicate with GitHub, I will be authenticated using SSH authentication.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1735053545173/6fb293f1-f90a-4b64-b026-082d8676afae.png" alt="The illustration of SSH authentication process between client and GitHub server." class="image--center mx-auto" width="4082" height="2574" loading="lazy"></p>
<p>SSH is a client-server protocol. Our computer that runs <code>git push</code> is the SSH client. GitHub is the SSH server.</p>
<p>The client starts off the authentication process by first fetching our public key that we have inside <code>~/.ssh</code>.</p>
<p>The client then prepares a message which has our public key. And then the client generates the signature using the corresponding private key.</p>
<p>The public key and signature are sent to GitHub. Upon receiving this message, GitHub does two things:</p>
<p>First, it verifies whether the public key mentioned in the message is connected to a GitHub profile or not. Since we upload our public key to GitHub, this step checks out successfully.</p>
<p>Second, GitHub verifies the signature using the public key that we have uploaded.</p>
<p>We have learned that if the signature verification turns out to be successful this means that only the person who is in the possession of the corresponding private key could have sent the message.</p>
<p>Since only we have the private key linked to the uploaded public key, this proves to GitHub that it is indeed us attempting to communicate with GitHub and not an attacker.</p>
<p>Now, GitHub is 100% sure that we are the correct person, we are successfully authenticated, and our <code>git push</code> is allowed to proceed further.</p>
<p>See, it became so easy to understand SSH authentication as you already learned the fundamentals.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1735120630613/e9a8bbba-3cc4-43e7-8369-865ab377fb87.png" alt="A xkcd comic depicting Cueball thinking to share his private key. A dangerous move!" class="image--center mx-auto" width="733" height="282" loading="lazy"></p>
<p>The above image is from the popular <a target="_blank" href="https://xkcd.com/1553/">xkcd comic</a>. The character there (named Cueball) is thinking about revealing his private key. I hope now you know why it’s bad to reveal your private key.</p>
<p>If you reveal your private key then someone else can authenticate to GitHub on your behalf. You don’t want that to happen, right? ;)</p>
<p>So, always make sure to keep your private key just to yourself.</p>
<h2 id="heading-wrapping-it-all-up">Wrapping it All Up</h2>
<p>If you have read this far, then Congratulations 🥳.</p>
<p>You’ve learned how SSH authentication actually works — when the signature was successfully verified by GitHub, it confirms to GitHub that it is we who are talking to it not an attacker.</p>
<p>Along the way you built a foundational understanding of symmetric key encryption, asymmetric key encryption, cryptographic hash functions and digital signatures.</p>
<p>Thanks for being with me on this one, I hope you are going away with some new and valuable learnings.</p>
<p>I put useful ideas and resources on my Twitter. <a target="_blank" href="https://twitter.com/vkwebdev"><strong>You should follow me there.</strong></a> I will respect your time.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How Homomorphic Encryption Works – Explained in Plain English ]]>
                </title>
                <description>
                    <![CDATA[ As the fields of cryptography and cybersecurity advance, homomorphic encryption stands out as a groundbreaking technology.  It has the potential to reshape everything in data privacy and security. What really is homomorphic encryption? Why is it gett... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/homomorphic-encryption-in-plain-english/</link>
                <guid isPermaLink="false">66ba5320ba2ef92905bfa81d</guid>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Tiago Capelo Monteiro ]]>
                </dc:creator>
                <pubDate>Mon, 29 Jan 2024 18:33:48 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/07/vanna-phon-hRXIKdxoaPo-unsplash--1-.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>As the fields of cryptography and cybersecurity advance, <a target="_blank" href="https://www.freecodecamp.org/news/introduction-to-homomorphic-encryption/">homomorphic encryption</a> stands out as a groundbreaking technology. </p>
<p>It has the potential to reshape everything in data privacy and security.</p>
<p>What really is homomorphic encryption? Why is it getting so much attention? How can it increase data privacy?</p>
<p>Essentially, with homomorphic encryption, we can process encrypted data without ever needing to decrypt it for computation.</p>
<p>This results in complete privacy everywhere the data is processed and stored.</p>
<p>In this article, you'll learn why this type of encryption will revolutionize the field of security. We'll tackle questions such as:</p>
<ul>
<li>What is homomorphic encryption?</li>
<li>How does homomorphic encryption work?</li>
<li>Homomorphic encryption vs traditional encryption – what's the difference?</li>
<li>What are the applications of homomorphic encryption?</li>
</ul>
<h2 id="heading-what-is-homomorphic-encryption">What is Homomorphic Encryption?</h2>
<p>Let's use an analogy to understand homomorphic encryption.</p>
<p>Imagine a locked treasure chest that has many valuable items inside.</p>
<p>To add or remove items, you need to unlock the chest. This could make it easier for thieves to steal the items when you open it.</p>
<p>In this analogy, this is what traditional encryption is.</p>
<p>Homomorphic encryption is like having a magical glove that allows you to add or remove items from the chest without ever unlocking it.</p>
<p>This way, you remove the risk of thieves ever getting the items inside the treasure chest.</p>
<p>This is essentially what Homomorphic encryption does with data: it allows us to perform operations on encrypted data without ever needing to decrypt it.</p>
<p>This is not possible with traditional encryption. In that case, we must process the data we need to decrypt, do whatever computations are necessary, and then encrypt the data again.</p>
<p>With homomorphic encryption, security is never compromised.</p>
<h2 id="heading-how-does-homomorphic-encryption-work">How Does Homomorphic Encryption Work?</h2>
<p>Homomorphic encryption allows computations to act on encrypted data – also called ciphertext.</p>
<p>This means the data is processed while encrypted.</p>
<p>Homomorphic encryption does computations on encrypted data (ciphertext). But computations done in ciphertext give encrypted results.</p>
<p>When these results are decrypted, they are similar to those that would've been obtained if the operations had been performed on the original, unencrypted data.</p>
<p>So basically, homomorphic encryption allows operations on encrypted data to give the same results as if performed on the original, decrypted data.</p>
<h3 id="heading-how-is-this-done">How is this done?</h3>
<p>Homomorphic encryption uses complex mathematical algorithms that:</p>
<ul>
<li>transform the numbers to obscure the original data, and </li>
<li>perform the same operations whether on the original or on this obscured data.</li>
</ul>
<p>Essentially, you're always working on the same data in the same way, but from different points of view.</p>
<p>So you can work with the data and get exactly the same results as if it were not encrypted. But since it actually is encrypted, the data is always protected!</p>
<p>This way, no one can see it and maybe steal it, which allows data privacy even in environments where trust is minimal.</p>
<h3 id="heading-python-code-example">Python code example</h3>
<p>We are going to use the Pyfhel library for this example, which you can read more about <a target="_blank" href="https://pypi.org/project/Pyfhel/3.1.1/">here</a>.</p>
<p>In this code, we are going to add two numbers in their encrypted form and see the results.</p>
<p>Here is the full code so you can truly understand how homomorphic encryption works:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">from</span> Pyfhel <span class="hljs-keyword">import</span> Pyfhel

HE = Pyfhel()
HE.contextGen(scheme=<span class="hljs-string">'bfv'</span>, n=<span class="hljs-number">2</span>**<span class="hljs-number">14</span>, t_bits=<span class="hljs-number">20</span>)
HE.keyGen()

integer1 = np.array([<span class="hljs-number">127</span>], dtype=np.int64)
integer2 = np.array([<span class="hljs-number">-57</span>], dtype=np.int64)

ctxt1 = HE.encryptInt(integer1)
ctxt2 = HE.encryptInt(integer2)

ctxtSum = ctxt1 + ctxt2
ctxtSub = ctxt1 - ctxt2
ctxtMul = ctxt1 * ctxt2

resSum = HE.decryptInt(ctxtSum) 
resSub = HE.decryptInt(ctxtSub)
resMul = HE.decryptInt(ctxtMul)
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/ray-so-export.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now we are going to break it down line by line:</p>
<p>First, we need to import the necessary modules:</p>
<pre><code><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">from</span> Pyfhel <span class="hljs-keyword">import</span> Pyfhel
</code></pre><p>Here, we are just importing the necessary modules to make our calculations.</p>
<p>Next, we need to create a Pyfhel object and generate keys:</p>
<pre><code>HE = Pyfhel()
HE.contextGen(scheme=<span class="hljs-string">'bfv'</span>, n=<span class="hljs-number">2</span>**<span class="hljs-number">14</span>, t_bits=<span class="hljs-number">20</span>)
HE.keyGen()
</code></pre><p>In the first line we initialize a <code>Pyfhel</code> python object. In the second line we set encryption with certain parameters:</p>
<ul>
<li><code>scheme='bfv'</code>: We use the <a target="_blank" href="https://link.springer.com/chapter/10.1007/978-3-030-92078-4_21">BFV (Brakerski/Fan-Vercauteren)</a> homomorphic encryption scheme.</li>
<li><code>n=2**14</code>: Defines the degree of the polynomial modulus degree. The polynomial modulus degree balances the encryption security level with the computational efficiency. A bigger number gives better encryption but at the cost of more computational resources</li>
<li><code>t_bits=20</code>: Sets the bit size of the plaintext modulus. Bigger bit size values let you use larger numbers but make the encryption less clean</li>
<li>In the third line, we <a target="_blank" href="https://www.freecodecamp.org/news/encryption-explained-in-plain-english/">generate a public and private key</a></li>
</ul>
<p>Then, we get two numbers and encrypt them:</p>
<pre><code>integer1 = np.array([<span class="hljs-number">127</span>], dtype=np.int64)
integer2 = np.array([<span class="hljs-number">-57</span>], dtype=np.int64)

ctxt1 = HE.encryptInt(integer1)
ctxt2 = HE.encryptInt(integer2)
</code></pre><p>We represent the numbers in a array with just one number and encrypt them.</p>
<p>We represent these numbers in an array and not as if we are declaring variables.</p>
<p>We do this because the function <code>encryptInt()</code> only takes an array of integers with 64 bits as an argument. From the <a target="_blank" href="https://pyfhel.readthedocs.io/en/latest/_autosummary/Pyfhel.Pyfhel.html">documentation</a>:</p>
<pre><code class="lang-python">encryptInt(self, int64_t[:] arr, PyCtxt ctxt=<span class="hljs-literal">None</span>)
</code></pre>
<p>Now we'll perform the operations on the two numbers while encrypted:</p>
<pre><code>ctxtSum = ctxt1 + ctxt2
ctxtSub = ctxt1 - ctxt2
ctxtMul = ctxt1 * ctxt2
</code></pre><p>And then decrypt the numbers after the operation when they where encrypted:</p>
<pre><code>resSum = HE.decryptInt(ctxtSum) 
resSub = HE.decryptInt(ctxtSub)
resMul = HE.decryptInt(ctxtMul)
</code></pre><p>Which will output the following:</p>
<pre><code>&gt;&gt;&gt; [<span class="hljs-number">70</span>  <span class="hljs-number">0</span>  <span class="hljs-number">0</span> ...  <span class="hljs-number">0</span>  <span class="hljs-number">0</span>  <span class="hljs-number">0</span>]
&gt;&gt;&gt; [<span class="hljs-number">184</span>   <span class="hljs-number">0</span>   <span class="hljs-number">0</span> ...   <span class="hljs-number">0</span>   <span class="hljs-number">0</span>   <span class="hljs-number">0</span>]
&gt;&gt;&gt; [<span class="hljs-number">-7239</span>     <span class="hljs-number">0</span>     <span class="hljs-number">0</span> ...     <span class="hljs-number">0</span>     <span class="hljs-number">0</span>     <span class="hljs-number">0</span>]
</code></pre><p>And if we do the normal calculations without being encrypted, we see that the values match:</p>
<pre><code>integer1 = <span class="hljs-number">127</span>
integer2 = <span class="hljs-number">-57</span>

print(integer1+integer2)

print(integer1-integer2)

print(integer1*integer2)
</code></pre><p>Which gives the following:</p>
<pre><code>&gt;&gt;&gt; <span class="hljs-number">70</span>

&gt;&gt;&gt; <span class="hljs-number">184</span>

&gt;&gt;&gt; <span class="hljs-number">-7239</span>
</code></pre><p>As you can see, we get the same results if we perform the operations on the data while it's encrypted as we do when it's not encrypted.</p>
<h2 id="heading-homomorphic-encryption-vs-traditional-encryption-whats-the-difference">Homomorphic Encryption vs Traditional Encryption – What's the Difference?</h2>
<p>In traditional encryption methods, data needs to be decrypted before any kind of processing. </p>
<p>In homomorphic encryption, data is always used in its encrypted state.</p>
<p>Traditional encryption is like a secure envelope: contents must be taken out to be read or modified. </p>
<p>Homomorphic encryption is like a special envelope that allows content manipulation without ever needing to open it to be read or modified.</p>
<h2 id="heading-applications-of-homomorphic-encryption">Applications of Homomorphic Encryption</h2>
<p>There are many practical applications of homomorphic encryption.</p>
<p>In cloud computing, it allows users to process data in the cloud without ever exposing it to cloud service providers. This way, sensitive information always remains confidential.</p>
<p>In healthcare, it allows the analysis of encrypted medical records without compromising patient privacy. Patient health data always remains protected.</p>
<p>Another promising application of homomorphic encryption is in secure voting systems. Using this type of encryption, votes are counted in such a way that no one can see for whom each person voted. This would make the voting process safer and more private.</p>
<p>These examples represent just the tip of the iceberg. </p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Homomorphic encryption is a paradigm shift in how we handle and process sensitive data. </p>
<p>This technology and its development are important as more and more data breaches are happening all the time.</p>
<p>Homomorphic encryption offers a path toward the simplification of data privacy regulations. </p>
<p>It also allows more innovation by making the protection of private data simpler, encouraging new security developments.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build a Photo Encryption App using Steganography ]]>
                </title>
                <description>
                    <![CDATA[ In this digital age, data flows freely across networks and devices. So protecting sensitive information from unauthorized access is crucial. That's where encryption comes in.  Encryption involves converting plain, readable data into an incomprehensib... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/build-a-photo-encryption-app/</link>
                <guid isPermaLink="false">66c5a25d3d77fae9eb82a46c</guid>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Houssein Badra ]]>
                </dc:creator>
                <pubDate>Wed, 23 Aug 2023 21:06:02 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/08/Screenshot--122-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this digital age, data flows freely across networks and devices. So protecting sensitive information from unauthorized access is crucial. That's where encryption comes in. </p>
<p>Encryption involves converting plain, readable data into an incomprehensible form. It's also essential to have a way to convert the data back into a readable form – otherwise the whole process makes no sense and isn't useful.</p>
<p>There are various popular encryption algorithms, each with its strengths and weaknesses. Understanding how these algorithms work is essential for programmers, as they need to choose the most appropriate one for their applications. </p>
<p>In this article, we will be build an application where users can encrypt images, and also revert the process using HTML, CSS, and JavaScript. </p>
<p>You will learn about working with images and how to encrypt them. The approach we will be using involves hiding one image inside another one, which is called <strong>Steganography.</strong> You will also practice some basic web development skills. It will be fun for sure!</p>
<h3 id="heading-heres-what-well-cover">Here's what we'll cover:</h3>
<ul>
<li>How images are represented on your computer</li>
<li>How to create the encryption algorithm </li>
<li>How to create the decryption algorithm</li>
<li>Photo encryption app code</li>
</ul>
<h2 id="heading-how-images-are-represented-on-your-computer">How Images Are Represented on Your Computer</h2>
<p>Understanding the way images are stored is critical before diving into encrypting them. </p>
<p>Images are represented on computers using a combination of pixels. A pixel is the smallest unit of an image and serves as the building block for displaying visuals on digital screens. </p>
<p>In memory, an image is an array of pixels. But now you're probably wondering, what is a pixel?</p>
<p>A pixel is assigned a specific color value which determines its appearance. The color values are typically represented using a combination of three primary colors: red, green, and blue – commonly known as RGB. </p>
<p>Each color channel is represented by a number value, ranging from 0 to 255, which determines the intensity of that color in the pixel. </p>
<p>For example:</p>
<ul>
<li>(0, 0, 0) represents black (absence of all colors)</li>
<li>(255, 255, 255) represents white (maximum intensity of all colors)</li>
<li>(255, 0, 0) represents pure red (maximum intensity of red, absence of green and blue)</li>
<li>(0, 255, 0) represents pure green (maximum intensity of green, absence of red and blue)</li>
<li>(0, 0, 255) represents pure blue (maximum intensity of blue, absence of red and green)</li>
</ul>
<p>By combining different intensities of red, green, and blue, we can represent a wide range of colors. This color information for each pixel is stored in memory, forming a digital image. For example to get yellow, we can combine red and green – (255, 255, 0) represents a yellow pixel.</p>
<h2 id="heading-how-to-use-the-encryption-algorithm">How to Use the Encryption Algorithm</h2>
<p>The key idea behind the algorithm we're going to use is that it uses 2 images: the image we want to encrypt and an image that will play the role of mask used to hide the image we want to encrypt. So we're going to combine these two images in a way that hides our main image and allows its extraction.</p>
<p>Since an image is made of pixels, what works for a single pixel works for an entire image. We will discuss how we will be combining 2 pixels in a way that hides one and allows reverting the process.</p>
<p>Now for the interesting part: if we look at numbers from 0 to 255, they all can be written as follows: a <em> 16 + b. For example 241 can be written as 15 </em> 16 + 1. But why we are doing this? </p>
<p>We will be using this to divide each pixel into two parts: first the a * 16 part and second b. The first part holds way more information than the second, since when a color degree goes up its intensity goes up. For example a (245, 137, 200) pixel can be split into (240, 128, 192) and (5, 9, 8). </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/Screenshot--114-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Image splitting</em></p>
<p>Now by comparing the high value pixel and the original one, you can see clearly that using the higher value pixel instead of the original one isn't going to change much of the information the original pixel holds.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/Screenshot--115-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Comparing a higher value pixel and an original pixel's values</em></p>
<p>Now we will be using two pixels – one we're going to encrypt (the target pixel), and one we're going to hide the target pixel within (the encryption pixel), which can be random as we will see later. </p>
<p>First we will get the high value pixel from our target and encryption pixels. Then for the pixel we're trying to encrypt, we'll divide each number degree by 16. </p>
<p>For example if the original target pixel was (245, 137, 200) then the high value pixel will be (240, 128, 192) which will become (15, 8, 12) after applying a division by 16. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/Screenshot--121-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Getting initial values and applying division</em></p>
<p>Now we have two new pixels: the high value pixel of the encryption pixel, and our target pixel high value pixel that got divided by 16. </p>
<p>Finally, to get an encrypted pixel, we'll sum up the values of these two pixels to get what we're looking for. </p>
<p>Take, for example, (26, 98, 234) and (245, 137, 200) as our encryption and target pixels, respectively. Let's first get the high value pixels. We will have (16, 96, 224) and (240, 128, 192), respectively. </p>
<p>Now divide the target pixel high value pixel by 16 and you'll have (15, 8, 12). Now add these two up and you'll be left with (31, 104, 236). And that's our encrypted pixel. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/Screenshot--118-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Encrypted image</em></p>
<p>Now you know how to encrypt a pixel. By applying this to all the pixels of an image we will get an encrypted image. </p>
<p>To make this clearer, we will be hiding an image of Quincy Larson playing guitar within the freeCodeCamp logo 😂.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/Screenshot--126-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Image showing how we were able to hide Quincy Larson image in the freeCodeCamp logo</em></p>
<p>So to make this work we need two images: the one we need to encrypt and a random image to use as the encryption image. Also the two images should have the same dimensions to get the same number of pixels. </p>
<p>The reason we're using a random image to hide our image is to make it look like a very random image that will make no one suspicious.</p>
<h2 id="heading-how-to-use-the-decryption-algorithm">How to Use the Decryption Algorithm</h2>
<p>Now we need a way to revert the process, so to extract the target pixel from an encrypted pixel. Then we will have accomplished our goal.</p>
<p>Like we did earlier by combining 2 pixels to get an encrypted pixel, we will split back the encrypted pixel to get our target.</p>
<p>Every pixel can be split into two parts – the high value part (a * 16) and the low value part (b). Now we care about the b part since it comes from our target pixel. So we need to extract the b part from an encrypted pixel.</p>
<p>We can do this easily by mapping each number with its corresponding remainder of division by 16. We can do this using the modulo operator <strong>%</strong> which is a mathematical operator to get the remainder of the division of a number by another. For example 241 % 16 is 1 since since 241 is equal to 15 * 16 + 1.</p>
<p>By taking (31, 104, 236) and applying the modulo, we will be left with (15, 8, 12). As discussed earlier an encrypted pixel is the sum of the high value pixel of our encryption pixel or the mask pixel and the high value pixel of our target divided by 16. After the modulo is applied, the left value is the high value pixel of our target divided by 16.</p>
<p>Now multiply each number by 16 and you'll get exactly (240, 128, 192) which is the high value pixel of our target pixel.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/Screenshot--117-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Decryption</em></p>
<p>Now as you can see, <strong>Steganography</strong> involves a small loss of each target pixel's information – but it's ok as you can see that it doesn't matter much in how the final image looks.</p>
<h2 id="heading-photo-encryption-app-code">Photo Encryption App Code</h2>
<p>And now since our toolkit is ready, let's code this image encryption application. All the code is available in this <a target="_blank" href="https://github.com/HousseinBadra/image-Encryption.git">GitHub repo</a>. The code itself is very straightforward. </p>
<p>First, create three files: an HTML file, a CSS file, and a JavaScript file. </p>
<p>For the HTML file we just need a canvas where we can see the resulting image. We also need two inputs of type file so we can upload our target and encryption images. And finally we need a button to save our encrypted image. </p>
<p>Also we will be using a small library to manage images created by Duke University, so we will have to include a script tag in the end of the body for this.</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Image encryption app<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"index.css"</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">canvas</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">canvas</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"input-container"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"Target"</span>&gt;</span>Upload target image<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"file"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"target"</span> <span class="hljs-attr">mltiple</span>=<span class="hljs-string">'false'</span> <span class="hljs-attr">accept</span>=<span class="hljs-string">'image/*'</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"input-container"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"Encryption"</span>&gt;</span>Upload encryption image<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"file"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"encryption"</span> <span class="hljs-attr">multiple</span>=<span class="hljs-string">'false'</span> <span class="hljs-attr">accept</span>=<span class="hljs-string">'image/*'</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Save image<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">'https://www.dukelearntoprogram.com/course1/common/js/image/SimpleImage.js'</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"index.js"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/javascript"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>The CSS is simple too. We will give the div wrapping the canvas a width and height of 300px, the canvas a width and height of 100%, and it'll have a black border. Now the div tags wrapping our inputs will get a slight margin of 10px on the top, and that's it.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
  <span class="hljs-attribute">width</span>:<span class="hljs-number">300px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
}

<span class="hljs-selector-tag">canvas</span>{
  <span class="hljs-attribute">width</span>:<span class="hljs-number">100%</span>;
  <span class="hljs-attribute">height</span>:<span class="hljs-number">100%</span>;
  <span class="hljs-attribute">border</span>:<span class="hljs-number">1px</span> solid black;
}

<span class="hljs-selector-class">.input-container</span>{
    <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p>Now for the JavaScript file. We will first select the two inputs, the canvas and the save button, and store them in four different variables. Then we will set the canvas width and height to 300px with JavaScript to avoid any future problems. And finally we'll set two variables, target and encryption, to store our encryption and target images.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> canvas = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"canvas"</span>);
<span class="hljs-keyword">const</span> targetInput = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#target"</span>);
<span class="hljs-keyword">const</span> encryptionInput = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#encryption"</span>);
<span class="hljs-keyword">const</span> saveButton = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"button"</span>);
<span class="hljs-keyword">let</span> target;
<span class="hljs-keyword">let</span> encryption;

canvas.width = <span class="hljs-number">300</span>;
canvas.height = <span class="hljs-number">300</span>;
</code></pre>
<p>Now we need to store the encryption and target images on user upload in the two variables we created earlier. Also set the <strong>onClick</strong> event of our save button to a function called <strong>save</strong> that we will create next. Finally, we'll create a function that takes a number as an argument and returns its high value as discussed in the encryption algorithm section.  </p>
<pre><code class="lang-js">targetInput.onchange = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> img = <span class="hljs-keyword">new</span> SimpleImage(targetInput);
  img.setSize(<span class="hljs-number">300</span>, <span class="hljs-number">300</span>);
  target = img;
};

encryptionInput.onchange = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> img = <span class="hljs-keyword">new</span> SimpleImage(encryptionInput);
  img.setSize(<span class="hljs-number">300</span>, <span class="hljs-number">300</span>);
  encryption = img;
};

saveButton.onclick = save;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getValue</span>(<span class="hljs-params">x</span>) </span>{
  <span class="hljs-keyword">return</span> x - (x % <span class="hljs-number">16</span>);
}
</code></pre>
<p>All that's left is to create the save function. First we will create a new image object with dimensions of 300 * 300. An image with these dimensions will have 90000 pixels. All of them have x and y coordinates from 0-299, since indexing starts from 0 in arrays. Looping from 0 to 300 twice will allow us to get all possible coordinates which means all pixels.</p>
<p>Now for each coordinate we will use the corresponding pixel of our encryption, target, and newly created image. Now we can set each pixel of our newly created image to the sum of the high value pixel of the encryption pixel and the high value pixel of our target divided by 16.</p>
<p>Now we will draw the newly created pixel on the canvas. And we'll need to get the URL of the image drawn into the canvas. We will be applying a small modification to the URL otherwise it will not work because we will get blocked by the browser for security reasons.</p>
<p>Finally, navigate to this URL by setting the window location to that URL. Then the encrypted image will be downloaded.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">save</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> img = <span class="hljs-keyword">new</span> SimpleImage(<span class="hljs-number">300</span>, <span class="hljs-number">300</span>);
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">300</span>; i++) {
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = <span class="hljs-number">0</span>; j &lt; <span class="hljs-number">300</span>; j++) {
      <span class="hljs-keyword">const</span> targetPixel = target.getPixel(i, j);
      <span class="hljs-keyword">const</span> encryptionPixel = encryption.getPixel(i, j);
      <span class="hljs-keyword">const</span> pixel = img.getPixel(i, j);
      pixel.setRed(
        getValue(targetPixel.getRed()) / <span class="hljs-number">16</span> + getValue(encryptionPixel.getRed())
      );
      pixel.setGreen(
        getValue(targetPixel.getGreen()) / <span class="hljs-number">16</span> +
          getValue(encryptionPixel.getGreen())
      );
      pixel.setBlue(
        getValue(targetPixel.getBlue()) / <span class="hljs-number">16</span> +
          getValue(encryptionPixel.getBlue())
      );
    }
  }
  img.drawTo(canvas);
  <span class="hljs-keyword">let</span> url = canvas
    .toDataURL(<span class="hljs-string">"image/png"</span>)
    .replace(<span class="hljs-string">"image/png"</span>, <span class="hljs-string">"image/octet-stream"</span>);
  <span class="hljs-built_in">window</span>.location.href = url;
}
</code></pre>
<p>And that's it for the code 😇.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, we've learned a simple algorithm for image encryption. Modern algorithms are way more robust, as they use techniques like matrix multiplication to get solid hashing algorithms but they are very complex and require way more time and math knowledge than this one. </p>
<p>If you find this content enjoyable, <a target="_blank" href="https://www.linkedin.com/in/houssein-badra-943879214/">follow me on LinkedIn</a> as I post great content there 😉.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Symmetric and Asymmetric Key Encryption – Explained in Plain English ]]>
                </title>
                <description>
                    <![CDATA[ Encryption is a way of scrambling data so that it can only be read by the intended recipient. Encryption is an integral part of our daily lives – whether you are sending messages to friends on WhatsApp, visiting a website and your browser is making s... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/encryption-explained-in-plain-english/</link>
                <guid isPermaLink="false">66d45e0e3dce891ac3a967dc</guid>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Daniel Adetunji ]]>
                </dc:creator>
                <pubDate>Wed, 05 Apr 2023 20:09:48 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/04/cover.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Encryption is a way of scrambling data so that it can only be read by the intended recipient.</p>
<p>Encryption is an integral part of our daily lives – whether you are sending messages to friends on WhatsApp, visiting a website and your browser is making sure it's legitimate, or entering your bank details when buying something online. Encryption protects your data from potentially malicious and prying eyes.</p>
<p>This article will cover:</p>
<ul>
<li><p>Encryption algorithms and keys</p>
</li>
<li><p>Symmetric and asymmetric key encryption</p>
</li>
<li><p>How TLS/SSL uses both symmetric and asymmetric encryption</p>
</li>
</ul>
<h2 id="heading-encryption-algorithms-and-keys">Encryption Algorithms and Keys</h2>
<p>At the start of this article, I described encryption as a way of scrambling data so that it can only be read by the intended recipient. Let’s break down what this means.</p>
<p>Let's say you want to write a letter to your friend and want to ensure that only the friend can read its contents. How would you prevent the prying eyes of all the intermediaries the letter could pass through before it gets to your friend? That is, how do you prevent the postman, the concierge in their building, or one of their friends from reading the letter?</p>
<p>You start with an unscrambled letter that anyone can read. This is called <strong>plaintext</strong>. To scramble the contents of the message, you need an <strong>encryption algorithm</strong> and a <strong>key</strong>. The encryption algorithm uses the key to scramble the contents of the message. This encrypted message is called <strong>ciphertext</strong>.</p>
<p>The process of encryption is shown in the image below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-9.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>When your friend gets the message, they will need to descramble it using the <strong>algorithm</strong> and the <strong>key</strong>. This is illustrated below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-10.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The two key ingredients needed to send a message to your friend that only they can read is an <strong>encryption algorithm</strong> and a <strong>key</strong>.</p>
<p>The encryption algorithm is simply a mathematical formula designed to scramble data, while the key is used as part of the formula. The encryption algorithm is generic, but the key, used as an input to the algorithm, is what ensures the uniqueness of the scrambled data.</p>
<p>Let’s look at one of the simplest encryption algorithms, called the Caesar Cipher. In its simplest form, this algorithm simply replaces each letter by the next letter in the alphabet. So A becomes B, and B becomes C and so on.</p>
<p>With this algorithm, the text ‘Birthday Surprise’ becomes ‘Cjsuiebz Tvsqsjtf’, indistinguishable from gibberish to the untrained eye.</p>
<p>With the Caesar Cipher example, the <strong>algorithm</strong> is the formula used to replace each letter of the alphabet with another. The <strong>key</strong> is the number of shifts made between each letter. With a key of 0, A is A, an obviously poor choice of key as the data is unscrambled. With a key of 1, A becomes B. With a key of 10, A becomes K.</p>
<p>The Caesar Cipher is a relatively poor encryption algorithm. Why? Since there are only 26 letters in the English language, you can only produce a maximum of 25 possible ciphertexts. If you don’t have the key, you only need to shift each letter up to 25 times until you see coherent words and sentences, at which point you know that you have successfully decrypted the message.</p>
<p>A bad encryption algorithm is one that is easily decrypted by using a small amount of brute force (that is, trying every possible permutation) – and 25 possible ciphertexts is an objectively small number of possible options to go through.</p>
<p>Modern encryption algorithms like AES-256 used by AWS, GCP, and Azure for encrypting data are considerably more complicated and secure than the Caesar Cipher. Based on current computing capability, it would take trillions and trillions of years for the most advanced supercomputer to use brute force to decrypt data encrypted using AES-256 [<a target="_blank" href="https://scrambox.com/article/brute-force-aes/">1</a>]. Even the universe is not that old.</p>
<h2 id="heading-symmetric-and-asymmetric-key-encryption">Symmetric and Asymmetric Key Encryption</h2>
<p>The core of any encryption process is the encryption algorithm and the key. There are many types of encryption algorithms. But there are, broadly speaking, two types of keys – symmetric and asymmetric keys.</p>
<p>In symmetric key encryption, the same key used to encrypt the data is used to decrypt the data. In asymmetric key encryption, one key is used to only encrypt the data (the public key) and another key is used to decrypt (the private key).</p>
<h3 id="heading-asymmetric-key-encryption">Asymmetric key encryption</h3>
<p>First, let’s look at asymmetric key encryption with a simple analogy.</p>
<p>Imagine you wanted to send something to your friend, but it was absolutely essential that nobody else, except your friend, could have access to that object. So, your friend buys an indestructible box, fabricated from the strongest metal on the planet, and sends it to you so that you can place the object in it. Your friend also sends you the key that can only be used to lock the box.</p>
<p>Now, this box has one more special property. It has two keyholes. One keyhole to open the box, another to lock the box.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-11.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Naturally, this box will also need two keys – one to open and another to lock it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-12.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Both keys are similar, but not identical. As you can see in the image above, for example, the key used to open the box has two prongs while the key used to lock the box has three prongs.</p>
<p>As the sender of the object, all you have is the box to place the object in and a key to lock the box. Only your friend has the key that can unlock the box.</p>
<p>The key used to lock the box is called the public key, and cannot be used to open it, as that requires the private key. If anyone intercepted the package and made a copy of the public key, it could not be used to open the box, only to lock it. Only the person who holds the private key can open the box.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-13.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Asymmetric key encryption is used when there are two or more parties involved in the transfer of data. This type of encryption is used for encrypting data in transit, that is encrypting data being sent between two or more systems. The most popular example of asymmetric key encryption is <a target="_blank" href="https://nordvpn.com/blog/rsa-encryption/">RSA</a>.</p>
<h3 id="heading-symmetric-key-encryption">Symmetric key encryption</h3>
<p>Symmetric key encryption uses the same key for encryption and decryption. This makes sharing the key difficult, as anyone who intercepts the message and sees the key can then decrypt your data.</p>
<p>This is why symmetric key encryption is generally used for encrypting data at rest. AES-256 is the most popular symmetric key encryption algorithm. It is used by AWS for encrypting data stored in hard disks (EBS volumes) and S3 buckets. GCP and Azure also use it for encrypting data at rest.</p>
<h2 id="heading-how-tlsssl-uses-both-symmetric-and-asymmetric-encryption">How TLS/SSL Uses Both Symmetric and Asymmetric Encryption</h2>
<p>The main strength of symmetric key encryption is that it is computationally easier and faster to encrypt and decrypt data using a single key, just as it is easier to build a box with a single lock and key.</p>
<p>The weakness of symmetric key encryption is that if the key is exposed, your data is no longer securely encrypted. So, if you needed to share the key with an external party, there is a risk that the key could be exposed, leaving your data at risk of being decrypted.</p>
<p>Symmetric key encryption is ideal for encrypting data at rest, where you do not need to share the key with another system.</p>
<p>With asymmetric encryption, this is not a problem since two separate keys are used – the public key to encrypt data and the private key to decrypt data.</p>
<p>The public key can be easily shared with anyone and poses no risk to your data being decrypted, since the private key is needed for decryption.</p>
<p>The drawback of asymmetric key encryption is that the encryption and decryption process is slower and more complicated. Asymmetric key encryption is ideal for encrypting data in transit, where you need to share the key with another system.</p>
<p>What if there was a way of getting the speed and computational simplicity of symmetric encryption without increasing the risk of exposing your keys?</p>
<p>TLS/SSL encryption use both symmetric and asymmetric keys to encrypt data in transit, and is used with the HTTP protocol for secure communications over a computer network.</p>
<h3 id="heading-tlsssl-encryption-explained">TLS/SSL Encryption Explained</h3>
<p>TSL (Transport Layer Security) and SSL (Secure Sockets Layer) are often used interchangeably to mean the same thing. But when people say SSL, they often mean TLS.</p>
<p>TLS is generally considered more secure than SSL due to several improvements made to the protocol, such as stronger cryptographic algorithms. Due to security concerns with SSL, most modern web browsers and applications have dropped support for SSL and only support TLS. As a result, TLS has become the standard for secure communication over the internet.</p>
<h3 id="heading-how-to-use-symmetric-and-asymmetric-encryption-at-the-same-time">How to Use Symmetric and Asymmetric Encryption at the Same Time</h3>
<p>Let's say you want to securely send a parcel to your friend. But you don’t want to keep using the special indestructible box that has two keyholes and two locks. It is expensive, heavy and impractical to use for frequent communications. You still want to use an indestructible box, but one that is simpler, with a single lock and key.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-14.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>However, if you are using a box with only a single lock and key, you now need to figure out how to securely share the key for that simpler box with your friend.</p>
<p>Since the same key is used to both open and lock it, you cant just send the key to your friend without somehow protecting it first. If the key is intercepted and a copy is taken by someone, they can now open your box and take what is inside.</p>
<p>How can you securely share this key with your friend so that you can use this simpler box for future communication?</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-15.png" alt="Image" width="600" height="400" loading="lazy"></p>
<ol>
<li><p>First, your friend sends the box with the two locks plus the public key used to lock it. But you don’t want to keep using this box. You will only use this box once – to transfer the key for another simpler box that you will use for future exchanges.</p>
</li>
<li><p>You place the master key that will be used in future exchanges inside this box and lock it with the public key sent by your friend.</p>
</li>
<li><p>You send the locked box which contains a copy of the master key inside back to your friend.</p>
</li>
<li><p>Your friend uses his private key to open the box. Now you both have the master key and can be sure no one else has it since it was sent in a secure box</p>
</li>
<li><p>All future items are then placed in this simpler box with a single lock and key which can be opened and locked using the master key you just sent to your friend.</p>
</li>
</ol>
<h3 id="heading-tlsssl-encryption-sequence">TLS/SSL Encryption Sequence</h3>
<p>The analogy in the previous section neatly maps to how TLS/SSL encryption actually works. But there are some prerequisite steps which I ignored in this analogy, like creating a TCP connection and the server sending its certificate (Steps 1 and 2 below).</p>
<p>Also, Step 6 is a simplification of the process. In reality, the master key is used to generate a further set of keys that the client and server will use to encrypt and decrypt messages and also to authenticate that the messages were indeed sent by the client and server.</p>
<p>To read more about the low level detail, I’d recommend Chapter 8 of "<a target="_blank" href="https://www.amazon.co.uk/Computer-Networking-Global-James-Kurose/dp/1292405465/ref=sr_1_1?keywords=computer+networking+a+top-down+approach&amp;qid=1680219419&amp;sprefix=computer+netw%2Caps%2C168&amp;sr=8-1">Computer Networking</a>" by Kurose &amp; Ross.</p>
<p>But, at a high level, the sequence is as follows:</p>
<ol>
<li><p>Client establishes TCP connection with the server</p>
</li>
<li><p>Client verifies that the server is who it says it is – server sends certificate which has the public key. The accompanying private key remains with the server.</p>
</li>
<li><p>Client creates a master secret key and uses the server's public key to encrypt it. This master secret key is a symmetric key so the same key is used for encryption and decryption.</p>
</li>
<li><p>Client sends the encrypted master secret key to the server.</p>
</li>
<li><p>Server decrypts the encrypted master key using its private key.</p>
</li>
<li><p>All future messages between client and server now use the symmetric master key to encrypt and decrypt messages.</p>
</li>
</ol>
<h2 id="heading-best-of-both-worlds">Best of Both Worlds</h2>
<p>Using both symmetric and asymmetric key encryption gives you the speed of symmetric key encryption without compromising on the extra security provided by asymmetric key encryption.</p>
<p>But nothing comes for free, of course. With TLS, there is an added layer of complexity since you need to first use asymmetric keys to establish a secure connection before exchanging the symmetric key for future communication.</p>
<p>So by using both symmetric and asymmetric encryption, TLS/SSL gets the best of both worlds with limited downsides.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is Encryption at Rest? Explained for Security Beginners ]]>
                </title>
                <description>
                    <![CDATA[ Encryption is a technique for secure communication that converts plain text into a coded form that can only be deciphered with a secret key. Let's explore some of encryption's fun bits. Encryption works by using an algorithm to convert plaintext into... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/encryption-at-rest/</link>
                <guid isPermaLink="false">66b995d8a3099de4654e61b0</guid>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ David Clinton ]]>
                </dc:creator>
                <pubDate>Tue, 04 Apr 2023 15:49:01 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/04/pexels-cottonbro-studio-7319078.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Encryption is a technique for secure communication that converts plain text into a coded form that can only be deciphered with a secret key. Let's explore some of encryption's fun bits.</p>
<p>Encryption works by using an algorithm to convert plaintext into ciphertext, which is unreadable without a corresponding decryption key. </p>
<p>This article comes from <a target="_blank" href="https://www.udemy.com/course/complete-lpi-security-essentials-exam-study-guide/?referralCode=C2B6802EDB99578238B5">The Complete LPI Security Essentials Exam Study Guide</a>. You can also follow along with this video:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/kWBLfhf8eto" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p>The encryption process takes the original data, and transforms it in a way that only someone with the correct decryption key can reverse the process and read the original data. This helps ensure that sensitive information is protected from unauthorized access or interception during transmission or storage.</p>
<h2 id="heading-understanding-encryption-tools">Understanding Encryption Tools</h2>
<p>Encryption at rest refers to the practice of protecting data that is stored on a device, such as a hard drive or a smartphone, by encoding it using encryption algorithms. The encrypted data can only be decrypted with the appropriate key, and this helps ensure that sensitive information remains confidential even if the device is lost or stolen. </p>
<p>This is a common security measure used to protect sensitive information such as credit card numbers, personal data, and confidential business information.</p>
<p>Password hashing is a technique for storing passwords in a secure manner by converting them into a cryptographic representation called a hash. The hash is created using a one-way function that transforms the password into a fixed-length string of characters that cannot be easily reversed to reveal the original password.</p>
<pre><code>$ echo -n mySecretPassword | sha256sum
<span class="hljs-number">2250e74</span>c6f823de9d70c2222802cd059dc970f56ed8d41d5d22d1a6d4a2ab66f  -
</code></pre><p>Salting is a security measure added to password hashing to increase its resilience against attacks. A salt is a random value that is generated for each password and combined with the password before it is hashed. </p>
<pre><code>$ openssl passwd -salt <span class="hljs-number">29</span> mytext
$<span class="hljs-number">1</span>$<span class="hljs-number">29</span>$WKQPJOxDf2nJLoPwT6cnz1
</code></pre><p>This results in a unique hash for each password, even if multiple users have the same password, making it much more difficult for an attacker to use pre-computed tables of hashes (such as rainbow tables) to crack the passwords. </p>
<p>When verifying a password, the salt is used to regenerate the hash, which is then compared to the stored hash to determine if the password is correct.</p>
<h2 id="heading-password-attack-tools">Password Attack Tools</h2>
<p>A rainbow table is a pre-computed table of hashes used to crack passwords by searching for a matching hash value. It is an optimization of a brute force attack that reduces the number of hashes that need to be calculated by reusing hashes computed for previous password guesses.</p>
<p>A Directory attack is a method of cracking passwords by using a large dictionary of words, phrases, and commonly used passwords to generate hashes and compare them to the target hashes. This type of attack is effective against weak passwords that are easily guessable.</p>
<p>A brute force attack is a way of cracking passwords by trying all possible combinations of characters until a match is found. It is a slow and resource-intensive method of cracking passwords, but it is effective against strong passwords that cannot be easily guessed. </p>
<p>Brute force attacks can be mitigated by using strong passwords, rate-limiting login attempts, and using encryption and hashing to store passwords securely.</p>
<h2 id="heading-symmetric-and-asymmetric-encryption">Symmetric and Asymmetric Encryption</h2>
<p>Symmetric cryptography, also known as shared-secret cryptography, is a type of encryption where the same key is used for both encryption and decryption of data. This means that both the sender and receiver of the data must have the same key and must keep it confidential. </p>
<p>Symmetric cryptography is fast and efficient but can be vulnerable if the key is compromised.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/slide-09.png" alt="Image" width="600" height="400" loading="lazy">
<em>Diagram showing how symmetric encryption works</em></p>
<p>Asymmetric cryptography, also known as public-key cryptography, uses a pair of keys, one for encryption and another for decryption. The encryption key, known as the public key, can be widely distributed, while the decryption key, known as the private key, is kept confidential. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/slide-10.png" alt="Image" width="600" height="400" loading="lazy">
<em>Diagram showing how asymmetric encryption works</em></p>
<p>Asymmetric cryptography is used for tasks such as digital signatures, key exchange, and data encryption, and is considered more secure than symmetric cryptography because the private key never needs to be transmitted or shared.</p>
<p>Hybrid cryptography is a combination of both symmetric and asymmetric cryptography. </p>
<p>In a typical hybrid encryption scheme, the data is encrypted using a symmetric algorithm, and the symmetric key is then encrypted using an asymmetric algorithm and sent to the recipient along with the encrypted data. The recipient uses their private key to decrypt the symmetric key, and then uses the symmetric key to decrypt the data. </p>
<p>Hybrid cryptography provides the security benefits of both symmetric and asymmetric cryptography, making it a commonly used encryption method.</p>
<h2 id="heading-public-key-infrastructure-pki">Public Key Infrastructure (PKI)</h2>
<p>PKI is a system for secure communication that uses a combination of public key cryptography, digital certificates, and certificate authorities (CAs) to authenticate the identity of parties involved in a communication and secure their communications.</p>
<p>Certificate Authorities (CAs) are organizations or entities that issue digital certificates, which are used to validate the identity of parties involved in a communication. </p>
<p>CAs act as trusted third parties that verify the identity of parties and issue certificates attesting to that identity. The certificate includes information such as the identity of the owner, the public key of the owner, and the digital signature of the CA.</p>
<p>Trusted Root-CAs are the highest level CAs in the PKI hierarchy. They are responsible for issuing certificates for intermediate CAs, who in turn issue certificates for end entities, such as individuals or organizations. </p>
<p>The trustworthiness of the entire PKI system is based on the trust in the root CAs. A trusted root CA is one that is widely recognized and trusted by users, systems, and applications. </p>
<p>The trusted root CA's certificate is usually pre-installed in software and devices, such as web browsers, to facilitate secure communication and verify the authenticity of digital certificates issued by other CAs.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>With what you've learned here, you're now ready to use encryption tools like <a target="_blank" href="https://www.veracrypt.fr/en/Home.html">VeraCrypt</a> and <a target="_blank" href="https://gnupg.org/">GnuPG</a> to protect the data you store on your local machines. You'll be able to properly assess the safety and integrity of the online and cloud storage platforms where you store data remotely.</p>
<p>This article and the accompanying video are excerpted from <a target="_blank" href="https://www.udemy.com/course/complete-lpi-security-essentials-exam-study-guide/?referralCode=C2B6802EDB99578238B5">my Complete LPI Security Essentials Exam Study Guide course</a>. And there's much more technology goodness available at <a target="_blank" href="https://bootstrap-it.com/">bootstrap-it.com</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How Website Encryption Works ]]>
                </title>
                <description>
                    <![CDATA[ It's one thing to protect your data when it's sitting quietly on your own local machine and not bothering anyone. But moving data between locations – as you do whenever you open a website on a remote server or send an email attachment across the inte... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/understanding-website-encryption/</link>
                <guid isPermaLink="false">66b9965f94b336889c600442</guid>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ David Clinton ]]>
                </dc:creator>
                <pubDate>Tue, 28 Mar 2023 17:35:27 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/03/pexels-markus-spiske-225769.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>It's one thing to protect your data when it's sitting quietly on your own local machine and not bothering anyone. But moving data between locations – as you do whenever you open a website on a remote server or send an email attachment across the internet – introduces a whole new set of vulnerabilities.</p>
<p>Plain text protocols transmit data in its unencrypted form, which makes it vulnerable to eavesdropping and tampering by third-party actors. Data transmitted over plain text protocols can be easily intercepted and read by anyone with access to the network. </p>
<p>If you're thinking of transmitting, say, credit card information or entering online banking passwords this way, then I would beg you to stop right now. You definitely want to add some encryption to your mix.</p>
<p>This article comes from <a target="_blank" href="https://www.udemy.com/course/complete-lpi-security-essentials-exam-study-guide/?referralCode=C2B6802EDB99578238B5">The Complete LPI Security Essentials Exam Study Guide</a>. You can also follow along using this video:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/v3Z0IRzTEcY" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-some-key-encryption-protocols">Some Key Encryption Protocols</h2>
<p>Transport encryption protocols, as it turns out, use encryption techniques to protect the data during transit. The data is encrypted before it is transmitted and decrypted after it is received. This provides protection against eavesdropping and tampering by third-party actors. </p>
<p>The most common transport encryption protocols are Secure Sockets Layer (SSL) and its successor, Transport Layer Security (TLS).</p>
<p>Beyond transport encryption, end-to-end encryption refers to a method of encrypting data from the sender's device to the recipient's device, such that only the sender and the recipient have access to the data. </p>
<p>E2EE provides protection for the entire transmission, including protection from intermediaries such as network administrators, service providers, and hackers. E2EE is typically used in applications such as instant messaging, email, and file sharing.</p>
<p><a target="_blank" href="https://www.freecodecamp.org/news/what-is-https-http-vs-https-meaning-and-how-it-works/">HTTPS (the Hypertext Transfer Protocol Secure)</a> is a protocol that is commonly used to secure web pages. It uses SSL or TLS encryption to secure the connection between a web browser and a server, ensuring that sensitive information, such as login credentials and credit card numbers, cannot be intercepted by third-party actors.</p>
<p><a target="_blank" href="https://www.freecodecamp.org/news/what-is-tls-transport-layer-security-encryption-explained-in-plain-english/">TLS (Transport Layer Security)</a> is a security protocol that provides encryption and integrity for data transmission over the internet. It is the successor to SSL and is currently widely used to secure web connections, email, and other internet protocols. TLS uses public-key cryptography to negotiate a shared secret key, which is then used to encrypt the data.</p>
<h2 id="heading-how-to-identify-website-encryption">How to Identify Website Encryption</h2>
<p>You can identify if a website is encrypted by looking for the padlock icon and the "https" prefix in the URL of the website. The padlock icon is usually located in the address bar of your web browser and indicates that the connection between your browser and the website is secure. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/Screenshot-2023-03-28-at-10.11.06-AM.png" alt="Image" width="600" height="400" loading="lazy">
<em>The padlock showing that freecodecamp.org/news is secure</em></p>
<p>The padlock icon can also show the level of security, such as the type of encryption used, the identity of the website, and the validity of the SSL/TLS certificate.</p>
<p>The "https" prefix in the URL of the website indicates that the connection is encrypted and secure. The "s" in "https" stands for "secure". In contrast, unencrypted websites use the "http" prefix in their URL.</p>
<p>It's important to note that while the padlock icon and the "https" prefix indicate that a website is encrypted, they don't guarantee the authenticity or security of the website. Always be cautious when entering sensitive information, such as login credentials or credit card numbers, into any website and make sure to verify the identity of the website before entering any sensitive information.</p>
<p>TLS-encrypted websites can acquire padlocks and "HTTPS" as a URL prefix by requesting a certificate from a certificate authority. Once upon a time, CAs would charge good money for issuing certificates, and they would take their time about it, too. However, that was before Let's Encrypt.</p>
<p><a target="_blank" href="https://letsencrypt.org/">Let's Encrypt</a> is a non-profit certificate authority that provides free, automated, and open-source SSL/TLS certificates. These certificates are used to encrypt and secure web communications, providing privacy and data integrity to internet users. </p>
<p>The main value of Let's Encrypt is its ability to make encryption more accessible and affordable. By offering free SSL/TLS certificates, Let's Encrypt makes it easier and more cost-effective for website owners to secure their websites and protect the privacy of their users.</p>
<p>In addition to being free, Let's Encrypt certificates are also easy to obtain and install. The certificates are issued through <a target="_blank" href="https://certbot.eff.org/">an automated process</a>, making it possible for website owners to obtain a certificate in minutes, rather than waiting for days or weeks for manual processing.</p>
<h2 id="heading-understanding-x509-certificates">Understanding X.509 Certificates</h2>
<p>Let's understand those certificates a bit better. X.509 is a standard for digital certificates that is widely used on the internet to establish trust between parties. </p>
<p>An X.509 certificate is a digital document that contains information about the identity of an entity and is signed by a trusted third-party known as a certificate authority (CA).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/slide-31-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Diagram of how X.509 certificates work</em></p>
<p>The process of obtaining an X.509 certificate involves jumping through some hoops:</p>
<ul>
<li>The entity seeking the certificate (a website owner, for instance) generates a certificate signing request (CSR) which includes information about their identity and public key.</li>
<li>The CA verifies the identity of the entity and issues the X.509 certificate. The certificate includes the public key of the entity, information about the identity, and the signature of the CA.</li>
<li>The entity installs the certificate on their web server and configures their website to use HTTPS, which enables encrypted communication between the server and the client.</li>
</ul>
<p>The process of revoking an X.509 certificate involves the following steps:</p>
<ul>
<li>The entity or the CA detects that the certificate needs to be revoked. For example, the entity may have lost control of their private key, or the identity information in the certificate may have changed.</li>
<li>The entity or the CA requests the revocation of the certificate.</li>
<li>The CA updates its certificate revocation list to indicate that the certificate has been revoked. The CRL is a list of all the revoked certificates that the CA has issued.</li>
<li>When a client connects to a website, it checks the certificate against the CRL to make sure it has not been revoked. If the certificate has been revoked, the client will not trust the website and will not establish a secure connection.</li>
</ul>
<p>An X.509 certificate contains several key fields that provide information about the identity of the entity and the certificate itself. Some of the key fields are:</p>
<ul>
<li>The version number of the X.509 certificate format.</li>
<li>A unique identifier assigned to the certificate by the certificate authority (CA).</li>
<li>Information about the entity that the certificate represents, such as its name, address, and public key.</li>
<li>Information about the CA that issued the certificate, such as its name and address.</li>
<li>The start and end dates of the certificate's validity period, during which the certificate can be trusted.</li>
<li>The public key of the entity that the certificate represents.</li>
<li>The algorithm used by the CA to sign the certificate and verify its authenticity.</li>
<li>The signature of the CA, which is used to verify the authenticity of the certificate.</li>
</ul>
<h2 id="heading-perfect-forward-secrecy-pfs">Perfect Forward Secrecy (PFS)</h2>
<p>There's one more thing we should touch on before leaving the world of encrypted web sessions. Perfect Forward Secrecy (PFS) is a security property in cryptography that ensures that the confidentiality of past sessions cannot be compromised even if the encryption keys used in those sessions are later disclosed. </p>
<p>This is achieved by using ephemeral keys, which are generated for each session and discarded after the session is completed. The ephemeral keys are used to establish a secure key exchange, and are never stored, so they cannot be used to decrypt past sessions even if they are later disclosed. </p>
<p>PFS is an important property in secure communication protocols, as it ensures that even if an attacker is able to obtain the encryption keys for a single session, they will not be able to use those keys to compromise past or future sessions.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>With this knowledge of encryption's inner workings, you'll be better able to assess the safety of your internet browsing activities. You'll also know what you need to do to encrypt the websites you yourself might manage.</p>
<p>This article and the accompanying video are excerpted from <a target="_blank" href="https://www.udemy.com/course/complete-lpi-security-essentials-exam-study-guide/?referralCode=C2B6802EDB99578238B5">my Complete LPI Security Essentials Exam Study Guide course</a>. And there's much more technology goodness available at <a target="_blank" href="https://bootstrap-it.com/">bootstrap-it.com</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How Does a VPN Work? Tutorial for Beginners ]]>
                </title>
                <description>
                    <![CDATA[ Do you worry about online security while using public Wi-Fi? Or has someone told you that you might get hacked when using an insecure connection and someone will steal all your details? Well, you might have also heard that you should use a VPN to pro... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-does-a-vpn-work/</link>
                <guid isPermaLink="false">66ba2a44c346e93df556afea</guid>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ privacy ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ vpn ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Tejan Singh ]]>
                </dc:creator>
                <pubDate>Tue, 24 Jan 2023 00:08:44 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/privecstasy-CXlqHmQy3MY-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Do you worry about online security while using public Wi-Fi? Or has someone told you that you might get hacked when using an insecure connection and someone will steal all your details?</p>
<p>Well, you might have also heard that you should use a VPN to protect your online privacy. But do you have any idea what it is and how it works?</p>
<p>Don’t worry – in this article, we will go through everything that you need to know to about what and when to use a VPN and when to avoid using it. So, without any further delay, let’s get started.</p>
<h2 id="heading-what-is-a-vpn">What is a VPN?</h2>
<p>VPN stands for Virtual Private Network. It is a type of network you can connect to which will help you protect your online security and privacy.</p>
<p>A VPN acts as a tunnel through which all your data goes from your location to your destination. It's all properly encrypted and secure so that any outside party can’t see what data you are transferring.</p>
<p>There are many advantages to using VPNs, such as:</p>
<ul>
<li>Privacy</li>
<li>Anonymity</li>
<li>Security</li>
<li>Encryption</li>
<li>Masking or changing your original IP address, so others can’t track you</li>
</ul>
<p>We'll discuss these advantages and more further down in this article, but first you need to understand how a VPN works so you can use it properly.</p>
<h2 id="heading-how-does-a-vpn-work">How Does a VPN Work?</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-223.png" alt="Image" width="600" height="400" loading="lazy">
<em><a target="_blank" href="https://www.cactusvpn.com/beginners-guide-to-vpn/vpn-encryption/">Image source</a></em></p>
<p>A VPN works by routing / forwarding all your data from your laptop or phone through your VPN to the internet, rather than directly through your ISP. </p>
<p>When you use a VPN, it encrypts all your data on the client side. Then after the data is encrypted, it's passed through a VPN tunnel which others can’t access, and then it reaches the internet.</p>
<p>But before going through the VPN tunnel, the request is first sent to your ISP, but as it's encrypted, ISP can’t figure out what you are trying to access. So it forwards your request to your VPN server. Then the VPN sends the request to your desired IP address or website.</p>
<h2 id="heading-advantages-of-using-a-vpn">Advantages of Using a VPN</h2>
<p>Now let's discuss some of the advantages in more detail.</p>
<h3 id="heading-unblock-websites-amp-bypass-filters">Unblock websites &amp; bypass filters</h3>
<p>There might be scenarios where you won’t be able to access certain websites which are blocked by your office or school or college department, but you still want or need to access them. </p>
<p>These websites may include social networking sites, movie downloading websites, or any kind of media streaming websites. </p>
<p>In these cases, a VPN will help you bypass all the blocking filters and let you access the websites that you wish to access without anyone’s help and others will have no idea what you're accessing.</p>
<h3 id="heading-bypass-regional-restrictions">Bypass regional restrictions</h3>
<p>People in certain countries cannot access any websites outside their country like YouTube or Google because their government doesn't want them to use any other websites. </p>
<p>If you're in one of these places and still want to access these blocked websites, then a VPN can help by bypassing all the regional restrictions. You'll be able to access all the restricted or blocked content without letting the government know about your activity.</p>
<h3 id="heading-access-geo-blocked-websites">Access geo-blocked websites</h3>
<p>There are several websites, special offers, and services which are available for specific countries or regions. But what if you also want to take advantage of that opportunity, but it’s not accessible in your region?</p>
<p>A VPN can help you by changing your IP address which will change your location on the internet. Then you will seem to be a user from that country and you can also have all the benefits that people in that particular region are enjoying.</p>
<h3 id="heading-change-your-ip-address">Change your IP address</h3>
<p>Your ISP is tracking your every move on the internet – which websites you are visiting, the amount of time you are spending there, and when you log in and log out from a website. </p>
<p>But sometimes you may need to hide your browsing history/activity from your local network/ISP. In that case, using a VPN can help you keep all your records encrypted, and your ISP will have no idea what you are doing with your internet. All your internet browsing activity will be masked by the VPN.</p>
<h3 id="heading-online-anonymity-and-privacy">Online anonymity and privacy</h3>
<p>Everything on the internet is tracking you. Website and web servers that you use or visit know your IP and location. That can be used to their advantage and every time you visit the same website, they will know that it’s you, and they will track your usage and your behavior. This isn't necessarily a good thing since you are giving them a lot of information without knowing what. </p>
<p>A VPN can help keep your identity anonymous so you don't need to worry about identity leakage or any kind of tracking activity.</p>
<h3 id="heading-enhanced-security">Enhanced security</h3>
<p>As discussed above, using VPN can keep your identity safe and also keeps your data encrypted while you browse the internet. As a result, it enhances security and the chances that someone might hack you will be lower. </p>
<p>So, using VPN will keep you safe when you are using any public Wi-Fi or browsing websites which are not secure.</p>
<h2 id="heading-disadvantages-of-vpn">Disadvantages of VPN</h2>
<p>There are some downsides to using a VPN as well:</p>
<h3 id="heading-slows-your-connections">Slows your connections</h3>
<p>VPNs tend to slow your internet connection. As the VPN servers might be located far away from you (might be in some other geographic location or country), your data will need to travel farther across the internet and will slow your connection speed.</p>
<h3 id="heading-vpns-log-your-activities">VPNs log your activities</h3>
<p>VPNs keep logs of your activities. You heard right. Regardless of what policies they have, even if they say that they don’t keep any logs, they do. Governments have taken action against VPNs, and the VPN companies tend to deliver all the activity logs of a user in cases of international crime, terrorist activity, or hacking. </p>
<p>So – it goes without saying – make sure you don’t use VPNs for any illegal activities. Use it instead to protect yourself and your identity from malicious hackers.</p>
<h3 id="heading-specific-blockades-of-vpn-services">Specific blockades of VPN services</h3>
<p>There are many websites and streaming services like Netflix which will not allow any unusual VPN users to access their content. So, there might be many cases where your VPN will help, but there are many websites and servers which won't allow you to access them using a VPN.</p>
<h3 id="heading-cost">Cost</h3>
<p>Although there are many free VPN services which you can use, if you are planning to use VPN on regular basis then you might need to purchase a paid version. Free VPNs don’t provide good speed and the amount of data usage is also limited on a daily basis. VPNs cost around $10 to $15 per month for the premium services.</p>
<h2 id="heading-how-a-vpn-can-help-you-protect-your-online-identity">How a VPN Can Help You Protect Your Online Identity</h2>
<p>When you use the internet, the data you send or request through a web browser to any server (for example, when Google searching), along with your request, IP address (for example, your laptop or mobile) and destination IP address (like Google) first reaches your ISP. </p>
<p>The ISP monitors all your activity and then forwards your request to the destination IP address and also gets back the information in the same way.</p>
<p>All your information travels through a middle station, your ISP. They have all your history of using the internet and how you are using the internet. But when you are using a VPN, that's not the case.</p>
<p>Whenever you send any request to any website or server, instead of connecting directly to the server, it first reaches the VPN server. There, all your requests and information are encrypted and then sent forward to your desired website.</p>
<p>Your ISP is still there to monitor things. But if you're using VPN, it will automatically change the IP address of your destination to a different IP address and encrypt the destination IP address. This way, your ISP won’t be able to read it and will assume that all your requests were going to the IP address of the VPN. So it will forward all your requests to the VPN.</p>
<p>When your request or information reaches your VPN, it will be decrypted, and it will forward your request to the website you wish to access. The website or server will get the VPN request and will assume that the request is coming from that VPN server. It will allow the VPN to access the website and you'll be able to visit the website without letting your ISP know.</p>
<p>Similarly, when you download a file, all the traffic or information flows from a web server to the VPN. The VNP encrypts all the information and then forwards it to your ISP – which will still have no idea what’s going on, as the information is encrypted.</p>
<p>Finally, the info gets forwarded to your laptop or mobile. When it reaches your device, it will be decrypted, and you will be able to view the website as it's available to others.</p>
<h2 id="heading-frequently-asked-vpn-questions">Frequently Asked VPN Questions</h2>
<h3 id="heading-is-vpn-traffic-encrypted">Is VPN traffic encrypted?</h3>
<p>YES! As explained above, all the traffic passed through VPN is encrypted through various encryption algorithms like the RSA (Rivest–Shamir–Adleman) algorithm, AES (Advanced Encryption Standard), and others.</p>
<h3 id="heading-what-is-an-always-on-vpn-what-is-a-kill-switch">What is an always-on VPN? What is a kill switch?</h3>
<p>I will try to explain this concept in approachable terms. Always on VPN is a service which allows you to automatically connect to a VPN whenever you are connected to the internet. These kinds of services are used by companies which don’t want outside users to access their data and only want their employees to access their data from an outside, remote location.</p>
<p>Whenever an employee, company, or user who has access to the resources tries to access, then they need to enter valid credentials to automatically connect to the VPN. This also allows them to access all their work and resources present inside the company from an outside or remote location.</p>
<p>A VPN kill switch is another major feature offered by VPN service providers. Whenever there is a sudden or accidental loss of a VPN connection, in that case, your information might get exposed.</p>
<p>To deal with that, a VPN kill switch is used to terminate your internet connection when there is no VPN connection. This is a very useful feature for protecting your data from outside users.</p>
<p>So, when the kill switch is ON, internet connections will be terminated. But when the kill switch is OFF, then the internet will not be terminated when there is a loss of VPN connection.</p>
<h3 id="heading-is-a-vpn-necessary">Is a VPN necessary?</h3>
<p>A VPN is not strictly necessary depending on your needs and activities, but it's useful. </p>
<p>Using VPN helps protect your online security, privacy, and anonymity. It will also protect you from malicious threats and trackers when you are using an unsecured website or using any unknown wi-fi connection which might be public.</p>
<h3 id="heading-is-a-vpn-100-safe">Is a VPN 100% safe?</h3>
<p>Nothing on the internet is 100% secure. There are and will always be ways to expose services like VPNs. But using a VPN will typically help you more than it'll harm you.</p>
<h3 id="heading-is-vpn-legal-in-india">Is VPN legal in India?</h3>
<p>Yes! VPNs are legal in India and can be used freely to access any content on the internet without any restrictions. Just remember that you should not use it for any illegal activity, as there are always ways to track you regardless of what VPN service you use.</p>
<h3 id="heading-do-vpns-log-or-store-my-data">Do VPNs log or store my data?</h3>
<p>VPNs log all your data and store all information, and it might be able to share your data with government authorities. There have been many cases where VPNs say they have a no logs policy but still keep logs of users and shared them with authorities.</p>
<h3 id="heading-what-is-the-main-difference-between-a-firewall-and-a-vpn">What is the main difference between a firewall and a VPN?</h3>
<table>
 <tbody><tr>
  <td>
  <p><span>&nbsp;&nbsp;Firewall</span></p>
  </td>
  <td>
  <p><span>VPN</span></p>
  </td>
 </tr>
 <tr>
  <td>
  <ul>
   <li><span>&nbsp;&nbsp;Software or hardware
       device&nbsp;</span></li>
  </ul>
  <p><span>&nbsp;</span></p>
  </td>
  <td>
  <ul>
   <li><span>Service or Server</span></li>
  </ul>
  <p><span>&nbsp;</span></p>
  </td>
 </tr>
 <tr>
  <td>
  <ul>
   <li><span>&nbsp;&nbsp;acts as a filter to allow
       and block websites and users to access a particular website</span></li>
  </ul>
  </td>
  <td>
  <ul>
   <li><span>it encrypts the IP address and
       information from both source and destination and allows users to access
       all blocked or restricted websites and even private network information.</span></li>
  </ul>
  </td>
 </tr>
</tbody></table>

<h2 id="heading-conclusion">Conclusion</h2>
<p>VPNs definitely have their advantages and disadvantages. Organizations use them to protect their private networks and information. You can also use one to access blocked content, and to protect your privacy, anonymity and security. Using a VPN for legal activities is beneficial and adds extra security.</p>
<p>When you are not sure about using or accessing any unknown (public/private) wi-fi or unsecured untrusted website, then you should always use a VPN (free/paid). Although paid VPNs have their advantages, occasionally using free VPNs won’t harm you and will still serve the purpose.</p>
<p>And just remember – don't ever try to use a VPN to perform any illegal activities.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is Homomorphic Encryption? ]]>
                </title>
                <description>
                    <![CDATA[ By Aris Zagakos In this article we will discuss Homomorphic Encryption, the problem that it solves, and the different types that exist.  Then we will write code in Python to show some of its capabilities in action. Here's what we'll cover: What is H... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/introduction-to-homomorphic-encryption/</link>
                <guid isPermaLink="false">66d461c5787a2a3b05af4423</guid>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 26 Apr 2022 23:01:28 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/04/Homomorphic-Encryption-3--1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Aris Zagakos</p>
<p>In this article we will discuss Homomorphic Encryption, the problem that it solves, and the different types that exist. </p>
<p>Then we will write code in Python to show some of its capabilities in action.</p>
<h2 id="heading-heres-what-well-cover">Here's what we'll cover:</h2>
<ol>
<li>What is Homomorphic Encryption?</li>
<li>Advantages of Homomorphic Encryption</li>
<li>Types of Homomorphic Encryption</li>
<li>Paillier Cryptosystem</li>
<li>Conclusion and resources to learn more</li>
</ol>
<h2 id="heading-what-is-homomorphic-encryption">What is Homomorphic Encryption?</h2>
<p>The name Homomorphic comes from the algebra term Homomorphism.</p>
<blockquote>
<p>"Homomorphism is a structure-preserving map between two algebraic structures of the same type (such as two groups, two rings, or two vector spaces)." (Source: Wikipedia)</p>
</blockquote>
<p><code>Homomorphic Encryption</code> is a form of encryption that allows users to perform binary operations on encrypted data without ever decrypting the data. </p>
<p>This form of encryption allows information to be encrypted and outsourced to cloud services/environments for processing, without accessing the raw data.</p>
<h2 id="heading-advantages-of-homomorphic-encryption">Advantages of Homomorphic Encryption</h2>
<p>In today's world, if we want to perform computations on encrypted data such as mathematical operations, we have to decrypt them first. Then we have to make our computations, and finally encrypt the data again in order to send them back.</p>
<p>But what happens when the encrypted data is very sensitive and we don't want other services to have access to them? Here is where <code>Homomorphic encryption</code> comes into play.</p>
<p>A more practical example would be a system/service that processes medical information in order to diagnose if a patient has a condition or not.</p>
<p>The data we'd be sharing probably includes very sensitive information about the patient's medical history. So this is something we want to ensure won't be accessible to anyone else.</p>
<p>Using <code>Homomorphic Encryption</code>, the system/service can process the required computations on the encrypted data, returning the result of the diagnosis without knowing which information is being proceeded.</p>
<p>Sharing sensitive information through different platforms gives away our privacy. On the other hand, being able to modify and perform operations on data while they are encrypted ensures the privacy of the data.</p>
<h2 id="heading-types-of-homomorphic-encryption">Types of Homomorphic Encryption</h2>
<p>The goal of Homomorphic Encryption is the following: given any input such as<br><code>input := Enc(x1),...,Enc(xn)</code>, for any arbitrary function <code>f</code> that applies an infinite number of additions or multiplications such as <code>value := f(Enc(x1),...,Enc(xn))</code>, the value can be computed while the input is encrypted.</p>
<p>The arithmetic operations, at the end of the day, are implemented at the hardware level (as anything else) under arithmetic or boolean circuits. </p>
<p>The operations that we want to perform are Homomorphic Addition and Homomorphic Multiplication. The names Addition and Multiplication are given due to the similar behavior of binary addition and binary multiplication that logic gates XOR and AND have correspondingly. The combination of these two gates can represent any boolean function.</p>
<p>The factors make the complexity to be varied based on the number and the kind of operations.</p>
<p>Because of these restrictions and the problem of constructing a fully Homomorphic Encryption algorithm (supporting both Homomorphic Addition and Homomorphic Multiplication), over time there have been different schemes implemented.</p>
<p>The most common types of Homomorphic encryption are:</p>
<ul>
<li>Partially Homomorphic Encryption (PHE)</li>
<li>Somewhat Homomorphic Encryption (SHE)</li>
<li>Fully Homomorphic Encryption (FHE)</li>
</ul>
<p>Partial Homomorphic Encryption (PHE) allows only one operation to be performed on the ciphertext an infinite number of times. This operation can be only addition or only multiplication. </p>
<p>Partially Homomorphic Encryption algorithms are easier to design and are very useful in applications that use one arithmetic operation.</p>
<p>Somewhat Homomorphic Encryption (SHE) allows both addition and multiplication to be performed, but for a limited number of times. This limitation is evaluated to a certain depth in the circuit logic. This is a very important milestone to reach Fully Homomorphic Encryption.</p>
<p>Fully Homomorphic Encryption (FHE) allows both addition and multiplication to be performed on the ciphertext an infinite number of times, supporting arbitrary computations on encrypted data. </p>
<p>The major problem with Fully Homomorphic Encryption is the cost efficiency both in terms of speed and storage requirements compared to plaintext operations.</p>
<h2 id="heading-paillier-cryptosystem">Paillier Cryptosystem</h2>
<p>The Paillier Cryptosystem was invented by Pascal Paillier in 1999. It is a Partial Homomorphic Encryption (PHE) scheme and Additively Homomorphic. </p>
<p>It supports only the addition of two ciphertexts and not the multiplication between them. Also, a plaintext number can be added or multiplied to the ciphertext.</p>
<p>In this example we use <code>python-paillier</code>, a Python library for Partially Homomorphic Encryption using the Paillier cryptosystem.</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> phe <span class="hljs-keyword">import</span> paillier

num1 = <span class="hljs-number">10</span>
num2 = <span class="hljs-number">20</span>

pub_key, priv_key = paillier.generate_paillier_keypair()
cipher_num1, cipher_num2 = pub_key.encrypt(num1), pub_key.encrypt(num2)

<span class="hljs-comment"># add two encrypted numbers together</span>
result = cipher_num1 + cipher_num2
result = priv_key.decrypt(result)
print(<span class="hljs-string">"add two encrypted numbers together:"</span>,result)

<span class="hljs-comment"># add an encrypted number to a plaintext number</span>
result = cipher_num1 + <span class="hljs-number">5</span>
result = priv_key.decrypt(result)
print(<span class="hljs-string">"add an encrypted number to a number:"</span>,result)

<span class="hljs-comment"># multiply an encrypted number by a plaintext number</span>
result = cipher_num1 * <span class="hljs-number">10</span>
result = priv_key.decrypt(result)
print(<span class="hljs-string">"multiply an encrypted number to a number:"</span>,result)
</code></pre>
<p>In the example above we generated a key pair of a public and a private key. Next, we encrypted both <code>num1</code> and <code>num2</code> with the public key and performed operations on their ciphertexts.</p>
<p>First, we added the two ciphers. After that, we took the <code>cipher_num1</code> and added to it a plaintext number. Last, we did the same process as before, but instead of addition, we multiplied the <code>cipher_num1</code> with a plaintext number this time. </p>
<p>The calculation of these operations takes place while the data is encrypted. Also, we can verify the integrity of the result each time by decrypting it using the private key.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Homomorphic Encryption (HE) looks like a dream when it comes to data privacy and protection. But its poor performance and high costs still keep it out of commercial/production applications. </p>
<p>But there have been many improvements in terms of speed lately. With the current pace, I believe that it will be adapted worldwide during the next years.</p>
<h3 id="heading-resources">Resources</h3>
<ul>
<li><a target="_blank" href="https://en.wikipedia.org/wiki/Homomorphism">Homomorphism</a></li>
<li><a target="_blank" href="https://en.wikipedia.org/wiki/Homomorphic_encryption">Homomorphic encryption</a></li>
<li><a target="_blank" href="https://en.wikipedia.org/wiki/Paillier_cryptosystem">Paillier cryptosystem</a></li>
<li><a target="_blank" href="https://python-paillier.readthedocs.io/en/develop/">python-paillier</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Manage Encryption at Scale with Envelope Encryption & Key Management Systems ]]>
                </title>
                <description>
                    <![CDATA[ Recently at work, I came across an interesting method to handle encryption at scale called envelope encryption.  First of all, it increases security and helps you ease out the management of encryption keys. But it's also a highly recommended pattern ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/envelope-encryption/</link>
                <guid isPermaLink="false">66bb457cce106b2510feda0d</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Rohit Jacob Mathew ]]>
                </dc:creator>
                <pubDate>Wed, 27 Oct 2021 22:52:59 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/10/1400-x-600.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Recently at work, I came across an interesting method to handle encryption at scale called envelope encryption. </p>
<p>First of all, it increases security and helps you ease out the management of encryption keys. But it's also a highly recommended pattern by PCI-DSS (Security Standard for Credit Card Processing) and results in much stronger data privacy and data protection of Personally Identifiable Information (PII). </p>
<p>When we think of data, there are 3 places we can think of encrypting it:</p>
<ul>
<li>At Rest – on hardware storage devices like a disk or in your devices</li>
<li>In Transit – while moving data between different locations like server to server through API calls</li>
<li>In Use – while it's being used by a server (this is a new concept and is still being researched)</li>
</ul>
<p>We will be dealing primarily with encryption at rest, and envelope encryption is a popular pattern for this use case.</p>
<h2 id="heading-so-what-is-envelope-encryption">So What is Envelope Encryption? 🤔</h2>
<p>Envelope encryption involves encrypting your data with a Data Encryption Key, then encrypting the Data Encryption Key (DEK) with a Customer Master Key (CMK). </p>
<p>You then store both the encrypted data and the encrypted DEK alongside each other in the database. This practice of using a wrapping key to encrypt data keys is known as envelope encryption.</p>
<p>You need to understand these two keys before we see how the encryption process takes place:</p>
<ol>
<li>Customer Master Key (CMK)</li>
<li>Data Encryption Key (DEK)</li>
</ol>
<h3 id="heading-customer-master-keysroot-keyskey-encryption-keys-cmk">Customer Master Keys/Root Keys/Key Encryption Keys (CMK)</h3>
<p>These are symmetric keys used to encrypt, decrypt, and re-encrypt data. They can also generate Data Encryption Keys that you can use outside of the KMS system. They follow the below rules:</p>
<ul>
<li>Access to these keys must be restricted to the least endpoints</li>
<li>Access to these keys should be secured through ACL</li>
<li>These keys must be stored in a location that is secure like a KMS of a Hardware Security Module (to comply with <a target="_blank" href="https://en.wikipedia.org/wiki/FIPS_140-2">FIPS 140-2</a>)</li>
</ul>
<p>In systems like Google Cloud Key Management Service, you have a hierarchy of keys as seen below (you can find more information <a target="_blank" href="https://cloud.google.com/security/encryption/default-encryption#encryption_key_hierarchy_and_root_of_trust">here</a>):</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635198625726/DgTfDZpGk.png" alt="Encryption Key Hierarchy at Google" width="1281" height="1625" loading="lazy"></p>
<h3 id="heading-data-encryption-keys-dek">Data Encryption Keys (DEK)</h3>
<p>Data keys are encryption keys you can use to encrypt data, including large amounts of data and other data encryption keys. </p>
<p>Unlike CMK's, which can't be downloaded, data keys are returned to you for use outside of the KMS. Some of the best practices for DEKs are as follows:</p>
<ul>
<li>You should generate DEKs locally</li>
<li>When stored, always ensure DEKs are encrypted at rest</li>
<li>For easy access, store the DEK near the data that it encrypts</li>
<li>Generate a new DEK every time you write the data. This means you don't need to rotate the DEKs.</li>
<li>Do not use the same DEK to encrypt data from two different users</li>
<li>Use a strong algorithm such as 256-bit Advanced Encryption Standard (AES)</li>
</ul>
<h2 id="heading-envelope-encryption-process">Envelope Encryption Process</h2>
<p>First, an API request is sent to KMS to generate Data key using CMK.</p>
<p>Then the KMS returns a response with Plain Data key and Encrypted Data key (using CMK).</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635198711784/Bm05yko4g.png" alt="Generate Data Keys" width="426" height="531" loading="lazy"></p>
<p>Data is encrypted using the Plain Data key, and then the Plain Data key is removed from memory.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635198735343/vjqUrCTa1.png" alt="Encryption Process" width="479" height="289" loading="lazy"></p>
<p>The Encrypted Data and Encrypted Data Key are packaged together as an envelope and stored.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635198756845/mXf8rwGhU.png" alt="Encryption Process With Data Stored at Rest" width="654" height="238" loading="lazy"></p>
<h2 id="heading-decryption-process">Decryption Process</h2>
<p>First, the Encrypted Data key is extracted from the envelope.</p>
<p>Then an API request is sent to KMS using Encrypted Data key which has information about CMK to be used in KMS for decryption.</p>
<p>The KMS returns a response with the Plain Data Key.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635198816460/dl8Q5RoPKew.png" alt="Getting Plaintext Data Key" width="564" height="366" loading="lazy"></p>
<p>Then the Encrypted Data is decrypted using the Plain Data key, and the Plain Data Key is removed from memory.</p>
<h2 id="heading-how-is-envelope-encryption-different-from-other-encryption-patterns"><strong>How is Envelope Encryption Different From Other Encryption Patterns</strong>? 🤔</h2>
<p>Every service you build requires encryption at some point. This could be passwords or PII in a database, credentials for an external service, or even files in a filesystem.</p>
<h3 id="heading-configuration-files">Configuration Files</h3>
<p>You can easily handle some of these situations with a configuration file but they pose their own security risks like:</p>
<ul>
<li>Proper planning is needed to keep the data secure</li>
<li>Multiple formats are present, like YAML, JSON and XML to name a few</li>
<li>Exact storage locations may be hard-coded in the app, making deployment potentially problematic</li>
<li>Parsing of the config files can be problematic.</li>
</ul>
<h3 id="heading-symmetric-encryption">Symmetric Encryption</h3>
<p>You can encrypt data using a symmetric key but they suffer from a major issue which is Key Management.</p>
<p>You need to find a way to get the key to the party with whom you are sharing data. But if someone gets their hands on a symmetric key, they can decrypt everything encrypted with that key.</p>
<h3 id="heading-asymmetric-encryption">Asymmetric Encryption</h3>
<p>You can encrypt data using Asymmetric Encryption which is considered a standard now a days. However, some of its cons are:</p>
<ul>
<li>It is a slow process which makes its not suitable for decrypting bulk messages</li>
<li>When you lose your private key, your received messages will not be decrypted</li>
<li>If your private key is identified by an attacker, they can read all of your messages </li>
</ul>
<h3 id="heading-envelope-encryption">Envelope Encryption</h3>
<p>Some of the benefits offered by envelope encryption are:</p>
<ul>
<li><strong>A combination of benefits from symmetric and asymmetric encryption</strong> – The data is encrypted using a DEK which follows symmetric encryption. The DEK is encrypted by a CMK which follows asymmetric encryption. By using asymmetric encryption, encrypted DEKs can be shared and unencrypted only by those with access to the CMK, mitigating the key exchange problem of symmetric algorithms.</li>
<li><strong>Easier key management</strong> – Multiple DEKs can be encrypted under a singular root key and ease the management of keys in a KMS. You can also do more secure key maintenance by rotating your root keys, instead of rotating and re-encrypting all of your DEKs.</li>
<li><strong>Data key protection</strong> – Because we encrypt the data key with the CMK, we don't have to worry about storing the encrypted data key. Thus, we can safely store the encrypted data key alongside the encrypted data.</li>
</ul>
<h2 id="heading-why-key-management-systems-work-well-at-scale">Why Key Management Systems Work Well at Scale</h2>
<p>Envelope Encryption and KMSs working so well at scale because of <strong>Performance.</strong> Like we mentioned before, Asymmetric Encryptions are typically slow and Symmetric Encryptions are very fast but managing keys can be an issue. </p>
<p>So in Envelope Encryption, for a large quantity of data, you quickly encrypt it using symmetric encryption with a random key. Then just the key is encrypted using asymmetric encryption. This gives the benefits of asymmetric encryption, with the performance of symmetric encryption.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635198563732/1E9VcEqZ-.png" alt="KMS Used at Scale in Google" width="2158" height="742" loading="lazy"></p>
<p>Key Management Systems like AWS KMS, Azure Key Vault, and Google Cloud Key Management Service gives you a fully managed service to store and manage encryption keys. These use envelope encryption internally, and they’re used by default in a lot of services that support encryption in cloud infrastructure providers like AWS, GCP, Azure, and others.</p>
<p>An ideal key management system should be highly available, it should control access to the master key(s), it should audit the key(s) usage, and finally, it should manage key(s) lifecycle.</p>
<p>Thus by having the above characteristics and by using envelope encryption internally, Key Management Systems are ideal to handle encryption at scale.</p>
<h2 id="heading-summary">Summary</h2>
<p>Envelope Encryption is one of the most trusted application security design patterns used at scale. It is the default encryption method used in services like AWS S3, GCP, and others. </p>
<p>Hopefully, this helps you understand how you can encrypt/decrypt a large amount of data using the envelope encryption method at scale in a more trusted setup.</p>
<p>Thanks for reading! I really hope that you find this article useful. I'm always interested to know your thoughts and am happy to answer any questions you might have. If you think this post was useful, please share it so others can read it, too.</p>
<p>P.S. – Do feel free to connect with me on <a target="_blank" href="https://www.linkedin.com/in/rohitjmathew">LinkedIn</a> or <a target="_blank" href="https://twitter.com/iamrohitjmathew">Twitter</a>.</p>
<h2 id="heading-resources">Resources</h2>
<p>This article leans heavily on the following material:</p>
<ul>
<li><a target="_blank" href="https://jayendrapatil.com/tag/envelope-encryption/">Google Cloud Data Encryption - Jayendra's Cloud Certification Blog -</a></li>
<li><a target="_blank" href="https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html">AWS KMS concepts - AWS</a></li>
<li><a target="_blank" href="https://lobster1234.github.io/2017/09/29/aws-kms-envelope-encryption/">AWS KMS and Envelope Encryption - Manish Pandit</a></li>
<li><a target="_blank" href="https://blog.nilayparikh.com/security/application/cloud-architecture-patterns-envelope-encryption-or-digital-envelope-with-public-cloud-providers-part-1/">Cloud Architecture Pattern: Envelope Encryption (or Digital Envelope) with Public Cloud Providers Part 1 - Nilay Parikh</a></li>
<li><a target="_blank" href="https://dev.to/chiragdm/aws-kms-envelope-encryption-3689">AWS KMS Envelope Encryption - Chirag Modi</a></li>
<li><a target="_blank" href="https://cloud.ibm.com/docs/key-protect?topic=key-protect-envelope-encryption">Protecting data with envelope encryption - IBM</a></li>
<li><a target="_blank" href="https://cloud.google.com/kms/docs/envelope-encryption">Envelope encryption - GCP</a></li>
<li><a target="_blank" href="https://cloud.google.com/security/encryption/default-encryption">Encryption at rest in Google Cloud - GCP</a></li>
</ul>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/StJ1NOQjAjo" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ End-to-End Encryption – Is Your Data Safe from Big Tech? ]]>
                </title>
                <description>
                    <![CDATA[ By Yehuda Clinton Every now and then we hear buzzing in the news about some egregious Big Tech privacy infringement. We are also frequently notified about all the new steps our apps are taking to further protect our privacy.  Most of us then weigh th... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/end-to-end-encryption-is-your-data-safe/</link>
                <guid isPermaLink="false">66d461703dce891ac3a96836</guid>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ privacy ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 14 Jan 2021 00:28:41 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/01/cyber-security-3400657__340.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Yehuda Clinton</p>
<p>Every now and then we hear buzzing in the news about some egregious Big Tech privacy infringement. We are also frequently notified about all the new steps our apps are taking to further protect our privacy. </p>
<p>Most of us then weigh the concerns and concede to the status quo without actually understanding the problem. As long as no one but us can see this message:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/e2ee.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Recently, WhatsApp announced that users must consent to sharing your data, including phone numbers and locations with Facebook. </p>
<p>Let's start with the basic question:</p>
<h2 id="heading-what-information-can-apps-websites-and-operating-systems-have-access-to">What information can apps, websites and operating systems have access to?</h2>
<p>Let's try delving into WhatsApp as they have recently been under attack.</p>
<p>Every WhatsApp user encounters a statement like "this personal message has end-to-end encryption." Which means that WhatsApp or anyone else shouldn't be able to decipher this message once it leaves your phone. </p>
<p>We should be able to trust that Facebook cannot read our WhatsApp messages on its server even if they store them until the recipient is connected. You can read WhatsApp's <a target="_blank" href="https://www.whatsapp.com/legal/privacy-policy">privacy policy here</a>.</p>
<p><strong>So far, no con game.</strong></p>
<p>What they don't mention in their privacy policy, however, is the in-app permissions about media and sensors. I'm referring to permission dialogs which pop up on first use.</p>
<p>I'm also referring to the data your OS shares with Facebook outside the app's ecosystem.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://android.stackexchange.com/questions/71802/help-understanding-whatsapps-permissions">https://android.stackexchange.com/questions/71802/help-understanding-whatsapps-permissions</a></div>
<p>While installing a new phone you could read this list of permissions accessed by the app including: Storage, location, Camera, Microphone, Accounts, Profile, Contacts and view apps running. </p>
<p>The above <em>StackExchange</em> article is over five years old and the list has changed since then. However you see a pattern of frequent changes to permissions and how difficult it can be to pin down when and how the app accesses media or device sensors.</p>
<h3 id="heading-how-does-big-tech-use-your-data">How does BIG-Tech use your data?</h3>
<p>Let's go through some of the permissions listed for WhatsApp:</p>
<ul>
<li><strong>your social media profile</strong> - details like 'phone number' and 'about'</li>
<li><strong>location and time</strong> - when you were at a given place</li>
<li><strong>Photos/Media/Files</strong> - hopefully they only use it for what they say</li>
<li><strong>contacts</strong> - they might share this within their ad algorithms </li>
<li><strong>camera</strong> - hopefully it's only in use when in an encrypted video call</li>
<li><strong>microphone</strong> - hopefully... but see <a target="_blank" href="https://www.quora.com/Can-Whatsapp-use-microphone-access-to-listen-to-converstations-even-when-not-being-used-for-audio-video-call-And-can-Facebook-use-that-data-to-shows-ads?share=1">this</a> and <a target="_blank" href="https://www.quora.com/Is-Facebook-listening-to-me-through-my-phones-microphone">this</a>. Sounds unclear</li>
<li><strong>gyroscope/accelerometer</strong> - determines when you're walking, sitting or driving</li>
<li><strong>light sensor</strong> - helps determine if your phone is in your pocket or against your head and so on</li>
</ul>
<h3 id="heading-so-do-they-directly-or-indirectly-use-these-sensors-when-you-dont-expect">So do they directly or indirectly use these sensors when you don't expect?</h3>
<p>Facebook may not have to admit the answer to this, as google-play-services collects much of this information and shares it with them in different ways. Our best answer is that we can't really prove it one way or the other. </p>
<p>It is all fine for most people if Big-Tech just uses our data to market relevant ads to us, but how can we know? Also if they aren't doing so today there's nothing stopping them from doing so one day.</p>
<h3 id="heading-how-they-get-away-with-it">How they get away with it</h3>
<p>We can see from other cases that large tech companies usually have each others' backs on these issues. Big-Tech has an established data-centric way of powering the online world. They don't seem to like competition. </p>
<p>Note how the Parler app was booted from AWS and at the same time as being banned from the different app stores. There is plenty of other incitement happening on AWS hosted apps or Google. Even if there was ongoing pressure to dump Parler, being a growing social media app likely sealed their fate. </p>
<h2 id="heading-so-what-are-the-alternatives">So what are the alternatives?</h2>
<h3 id="heading-telegramhttpstelegramorg-amp-signal"><a target="_blank" href="https://telegram.org">Telegram</a> &amp; Signal</h3>
<p><strong>Telegram</strong> is a privacy focused instant messaging platform with some 500 million users. Although the app feels like top social networking its CEO <a target="_blank" href="https://techcrunch.com/2020/12/23/telegram-to-launch-an-ad-platform-as-it-approaches-500-million-users/">does not intend to monetize by utilizing user data</a>. </p>
<p>Its mobile apps are open source so we can know exactly how it uses your phone data. This also allows us to assess the strength of the end-to-end encryption.</p>
<p><strong>Signal</strong> is a completely open source messaging and calling service. Its non profit nature assures you that there's no ads or fees, but it's a bit more complicated to use and a lower quality service.</p>
<h3 id="heading-how-to-keep-your-telegram-private-and-secure">How to keep your telegram private and secure</h3>
<p>Use the settings to control who can see your photo, groups/channels or phone number. You can make your account name an alias and have your real name within your profile which can only be seen by your friends.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/telegram.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-what-you-are-trading-for-privacy">What you are trading for Privacy?</h2>
<p>When using WhatsApp and similar social media, you're forced to adhere to the political and moral standards of Silicon Valley. As much as you may hate it, they do fairly well at protecting you from scams, harassment, and other criminal activities. </p>
<p>If you decide to use an alternative, like Telegram, you should be ready to be your own filter. The Telegram or Signal apps may not be safe for children without careful supervision. There are <a target="_blank" href="https://www.mspy.com/telegram.html">versions of the app available</a> which allow parents to monitor their children's messages and contacts. </p>
<p>If you wish to learn more about underlying technologies we encounter daily, read <a target="_blank" href="https://bootstrap-it.com/davidclinton/keeping-up/">this book by David Clinton</a>.</p>
<p>If you are looking for encryption with your devices consider taking my <a target="_blank" href="https://www.manning.com/liveproject/secure-business-infrastructure-with-a-custom-vpn?a_aid=bootstrap-it&amp;a_bid=b9d7d398&amp;chan=VPN">VPN course from Manning Publications</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Encryption Algorithms Explained with Examples ]]>
                </title>
                <description>
                    <![CDATA[ By Megan Kaczanowski Cryptography, at its most basic, is the science of using codes and ciphers to protect messages.  Encryption is encoding messages with the intent of only allowing the intended recipient to understand the meaning of the message. It... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/understanding-encryption-algorithms/</link>
                <guid isPermaLink="false">66d46074b3016bf139028d7b</guid>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethical Hacking ]]>
                    </category>
                
                    <category>
                        <![CDATA[ hacking ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 01 May 2020 00:16:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9b58740569d1a4ca2b3f.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Megan Kaczanowski</p>
<p>Cryptography, at its most basic, is the science of using codes and ciphers to protect messages. </p>
<p>Encryption is encoding messages with the intent of only allowing the intended recipient to understand the meaning of the message. It is a two way function (you need to be able to undo whatever scrambling you’ve done to the message). This is designed to protect data in transit. </p>
<p>If you're looking for a general background on the difference between symmetric and asymmetric algorithms and a general overview of what encryption is, start <a target="_blank" href="https://medium.com/swlh/how-to-send-secret-messages-1c106250b884">here</a>. This article will primarily cover two of the most commonly used encryption algorithms. </p>
<p>As a general overview, there was a major problem with symmetric algorithms when they were first created - they only functioned effectively if both parties already knew the shared secret. If they didn't, securely exchanging a key without a third party eves-dropping was extremely difficult. </p>
<p>And if a third party obtained the key, it was very easy for them to then break the encryption, defeating the purpose of secure communication. </p>
<p>Diffie-Hellman solved this problem by allowing strangers to exchange information over public channels which can be used to form a shared key. A shared key is difficult to crack, even if all communications are monitored.</p>
<h2 id="heading-how-does-diffie-hellman-work">How does Diffie-Hellman work?</h2>
<p>Diffie-Hellman is what's called a key exchange protocol. This is the primary use for Diffie-Hellman, though it could be used for encryption as well (it typically isn't, because it's more efficient to use D-H to exchange keys, then switch to a (significantly faster) symmetric encryption for data transmission). </p>
<p>The way this works is as follows:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/10/Screen-Shot-2019-10-04-at-5.45.13-PM.png" alt="Image" width="600" height="400" loading="lazy">
_<a target="_blank" href="https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange#/media/File:Diffie-Hellman_Key_Exchange.svg">https://en.wikipedia.org/wiki/Diffie–Hellman_key_exchange#/media/File:Diffie-Hellman_Key_Exchange.svg</a>_</p>
<p>Basically, there are two parties, Alice and Bob, which agree on a starting color (arbitrary but has to be different every time). They also have a secret color they keep to themselves. They then mix this color with the shared color, resulting in two different colors. They then pass this color to the other party, who mixes it with their secret color, resulting in the same ending secret color. </p>
<p>This relies upon the idea that it's relatively easy to mix two colors together, but it is very difficult to separate them in order to find the secret color. In practice, this is done with mathematics.</p>
<p>For example:</p>
<ol>
<li>Bob and Alice agree on two numbers, a large prime, p = 29, and base g = 5</li>
<li>Now Bob picks a secret number, x (x = 4) and does the following: X = g^x % p (in this case % indicates the remainder. For example 3%2 is 3/2, where the remainder is 1). X = 5 ^4 % 29 = 625 % 29 = 16</li>
<li>Alice also picks a secret number, y (y = 8) and does the following: Y = g^y % p.  Y = 5 ^ 8 % 29 = 390,625 % 29 = 24</li>
<li>Bob sends X to Alice and Alice sends Y to Bob.</li>
<li>Then Bob does the following: K = Y^x % p, K = 24 ^ 4 % 29 = 331,776 % 29 = 16</li>
<li>Alice then does the following: K = X^y % p, K = 16 ^ 8 % 29 = 4,294,967,296 % 29 = 16</li>
</ol>
<p>The great (<em>possibly magic</em>) thing about this, is that both Bob and Alice have the same number, K, and can now use this to talk secretly, because no one else knows K.</p>
<p>The security of this protocol is predicated on a few things:</p>
<ol>
<li>(Fact) It's relatively easy to generate prime numbers, even large prime numbers (like p).</li>
<li>(Fact) Modular exponentiation is easy. In other words, it's relatively easy to compute X = g ^ x % p.</li>
<li>(Assumption based on current computing power and mathematics) Modular root extraction without the prime factors is very hard. Essentially, it's very hard to find K without knowing x and y, even if you've snooped on the traffic and can see p, g, X, and Y.</li>
</ol>
<p>Thus, assuming this was implemented correctly, it's relatively easy to do the math required to create the key, but is extremely difficult and time consuming to do the math required to try to break the key by brute forcing it. </p>
<p>Even if an attacker could compromise this key, Diffie-Hellman allows for perfect forward secrecy.</p>
<h3 id="heading-what-is-perfect-forward-secrecy">What is perfect forward secrecy?</h3>
<p>This is the idea that if you crack the encryption that the server is using to communicate now, it doesn’t mean that all communications that the server has ever carried out are able to be read. </p>
<p>In other words, it only allows you to see the communications that are being used now (ie with this secret key). Since each set of communications has a different secret key, you would have to crack them all separately. </p>
<p>This is possible if each session has a different, ephemeral key for each session. Because Diffie-Hellman always uses new random values for each session, (therefore generating new keys for each session) it is called Ephemeral Diffie Hellman (EDH or DHE). Many cipher suites use this to achieve perfect forward secrecy.</p>
<p>As Diffie-Hellman allows you to exchange key material in plaintext without worrying about compromising the shared secret, and the math is too complicated for an attacker to brute force, the attacker can't derive the session key (and even if they could, using different, ephemeral, keys for each session means that they could only snoop on this session - not any in the past or future). </p>
<p>Forward secrecy is enabled with any Diffie-Hellman key exchange, but only ephemeral key exchange (a different key for every session) provides perfect forward secrecy. </p>
<p><a target="_blank" href="https://scotthelme.co.uk/perfect-forward-secrecy/">Here's a post</a> from Scott Helme talking about this in more depth and explaining how to enable this on your servers.</p>
<h3 id="heading-what-are-diffie-hellmans-limitations">What are Diffie-Hellman's limitations?</h3>
<p>The biggest limitation of D-H is that is doesn't verify identity. In other words, anyone can claim to be Alice or Bob and there is no built-in mechanism for verifying that their statement is true. </p>
<p>In addition, if the implementation is not carried out in a secure manner, the algorithm could be cracked with enough dedicated resources (unlikely, but possible for academic teams or nation-state actors). </p>
<p>For example, this could occur if the random number generator is not provided with adequate entropy to support the desired strength - in other words, because computer generated numbers are never truly random, the degree to which you've artificially injected uncertainness matters to the strength of your implementation.</p>
<p>Additionally, there was an attack demonstrated in 2015 which showed that when the same prime numbers were used by many servers as the beginning of the key exchange, the overall security of Diffie-Hellman was lower than expected. </p>
<p>Essentially an attacker could simply precompute the attack against that prime, making it easier to compromise sessions for any server which has used that prime number. </p>
<p>This occurred because millions of servers were using the same prime numbers for key exchanges. Precomputing this type of attack still requires either academic or nation-state level resources and is unlikely to impact the vast majority of people. </p>
<p>However, luckily for those who have to worry about nation-state attackers, there is a different way to achieve the DH key exchange using elliptic curve cryptography (ECDHE). This is out of the scope of this article, but if you're interested in learning more about the math behind this exchange, check out <a target="_blank" href="https://vincent.bernat.ch/en/blog/2011-ssl-perfect-forward-secrecy">this article</a>.</p>
<p>For a more detailed look at the weaknesses of DH, check out <a target="_blank" href="https://cert.europa.eu/static/WhitePapers/CERT-EU-SWP_16-002_Weaknesses%20in%20Diffie-Hellman%20Key%20v1_0.pdf">this whitepaper</a> and <a target="_blank" href="https://weakdh.org/">this website.</a></p>
<h2 id="heading-rsa">RSA</h2>
<p>RSA is named for the creators  –  Rivest, Shamir, Adleman – and it is a manner of generating public and private keys. </p>
<p>Technically there are two RSA algorithms (one used for digital signatures, and one used for asymmetric encryption.) - this article covers the asymmetric encryption algorithm. </p>
<p>This allows for key exchange - you first assign each party to the transaction public/private keys, then you generate a symmetric key, and finally, you use the public/private key pairs to securely communicate the shared symmetric key. </p>
<p>Because asymmetric encryption is generally slower than symmetric encryption, and doesn't scale as well, using asymmetric encryption to securely exchange symmetric keys is very common.</p>
<p>So, how does it work?</p>
<ol>
<li>Pick 2 very large prime numbers (at least 512 bits, or 155 decimal digits each), x and y (these numbers need to be secret and randomly chosen)</li>
<li>Find the product, ie z = x*y</li>
<li>Select an odd public integer, e, between 3 and n - 1, and has no common factors (other than 1) with (x-1)(y-1) (so it is relatively prime to x - 1 and y - 1).</li>
<li>Find the least common multiple of x - 1 and y - 1, and call it L.</li>
<li>Calculate the private exponent, d, from x, y, and e. de = 1 % L. d is the inverse of e % L (you know that an inverse exists because e is relatively prime to z - 1 and y - 1). This system works because p = (p ^ e) ^d % z.</li>
<li>Output (z, e) as the public key and (z, d) as the private key.</li>
</ol>
<p>Now, if Bob would like to send a message to Alice, he generates the ciphertext(C) from the plain text(P) using this formula:</p>
<p>C = P^e % z</p>
<p>In order to decrypt this message, Alice computes the following:</p>
<p>P = C^d % z</p>
<p>The relationship between d and e ensures that encryption and decryption functions are inverses. That means that the decryption function is able to successfully recover the original message, and that it's quite hard to recover the original message without the private key (z, d) (or prime factors x and y). </p>
<p>This also means that you can make z and e public without compromising the security of the system, making it easy to communicate with others with whom you don't already have a shared secret key.</p>
<p>You can also use the operations in reverse to get a digital signature of the message. First, you use the decryption operation on the plaintext. For example, s = SIGNATURE(p) = p ^ d % z.</p>
<p>Then, the recipient can verify the digital signature by applying the encryption function and comparing the result with the message. For example, m = VERIFY(s) = S ^ e % z.</p>
<p>Often when this is done, the plaintext is a hash of the message, meaning you can sign the message (regardless of length) with only one exponentiation.</p>
<p>The security of system is based on a few things: </p>
<ol>
<li>(Fact) It's relatively easy to generate prime numbers, even large prime numbers (like x and y).</li>
<li>(Fact) Multiplication is easy. It's very easy to find z.</li>
<li>(Assumption based on current mathematics) Factoring is hard. Given z, it's relatively hard to recover x and y. It is do-able, but it takes a while, and it is expensive.   </li>
</ol>
<p><a target="_blank" href="http://mathaware.org/mam/06/Kaliski.pdf">One estimate</a> says that recovering the prime factors of a 1024-bit number would take a year on a machine which cost $10 million. Doubling the size would exponentially increase the amount of work needed (several billion times more work).   </p>
<p>As technology continues to advance, these costs (and the work required) will decrease, but at this point, this type of encryption, properly implemented, is an unlikely source of compromise.   </p>
<p>Generally the only hackers with this type of money and dedication to a single target are nation-states. Plus, if there's an easier way to compromise a system (see below), that's probably a better option.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/10/Screen-Shot-2019-10-05-at-11.18.45-AM.png" alt="Image" width="600" height="400" loading="lazy">
<em><a target="_blank" href="https://xkcd.com/538/">https://xkcd.com/538/</a></em></p>
<ol start="4">
<li><p>(Fact) Modular exponentiation is easy. In other words, it's relatively easy to compute c = p ^ e % z.</p>
</li>
<li><p>(Fact) Modular root extraction - reversing the process above - is easy if you have the prime factors (if you have z, c, e, and the prime factors x and y, it's easy to find p such that c = p ^ e % z).</p>
</li>
<li><p>(Assumption based on current computing power and mathematics) Modular root extraction without the prime factors is very hard (if you have z, c, e, but not x and y, it's relatively hard to find p such that c = p ^ e % z, particularly if a is sufficiently large).</p>
</li>
</ol>
<p>Want to learn more about the math from much smarter people? Check out <a target="_blank" href="http://mathaware.org/mam/06/Kaliski.pdf">this article.</a></p>
<h2 id="heading-great-which-is-better">Great, which is better?</h2>
<p>It depends on your use case. There are a few differences between the two algorithms - first, perfect forward secrecy (PFS), which we talked about earlier in context of Diffie-Hellman. While technically you <em>could</em> generate ephemeral RSA key pairs, and provide perfect forward secrecy with RSA, the computational cost is much higher than for Diffie-Hellman - meaning that Diffie-Hellman is a better choice for SSL/TLS implementations where you want perfect forward secrecy.  </p>
<p>While there are some performance differences between the two algorithms (in terms of work required from the server), the performance differences generally aren't large enough to make a difference when choosing one over the other. </p>
<p>Instead, in general, the primary consideration when determining which is better depends on which one is more supported for your use case (for example, when implementing SSL you'll want Diffie Hellman due to perfect forward secrecy) or which is more popular or accepted as the standard in the industry. </p>
<p>For example, while Diffie-Hellman was US government approved, and supported by an institutional body, the standard wasn't released - whereas RSA (standardized by a private organization) provided a free standard, meaning that RSA became very popular among private organizations. </p>
<p>If you're interested in reading more, there's a great thread <a target="_blank" href="https://security.stackexchange.com/questions/35471/is-there-any-particular-reason-to-use-diffie-hellman-over-rsa-for-key-exchange/35472#35472">here</a> on the differences.</p>
<p>Interested in learning how to hackers use cryptographic attacks? Try <a target="_blank" href="https://cryptopals.com/">this</a> set of challenges from Cryptopals.</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/preinheimer/status/841273046317060105?lang=en"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Healthy habits for good cybersecurity ]]>
                </title>
                <description>
                    <![CDATA[ In a similar fashion to everyone getting the flu now and again, the risk of catching a cyberattack is a common one.  Both a sophisticated social engineering attack or grammatically-lacking email phishing scam can cause real damage. No one who communi... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/healthy-habits-for-good-cybersecurity/</link>
                <guid isPermaLink="false">66bd8f2927629f4c5e1893a4</guid>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ New Years Resolutions ]]>
                    </category>
                
                    <category>
                        <![CDATA[ phishing ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Victoria Drake ]]>
                </dc:creator>
                <pubDate>Fri, 27 Dec 2019 15:10:10 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/12/cover-4.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In a similar fashion to everyone getting the flu now and again, the risk of catching a cyberattack is a common one.  Both a sophisticated social engineering attack or grammatically-lacking email phishing scam can cause real damage. No one who communicates over the Internet is immune.</p>
<p>Like proper hand washing and getting a flu shot, good habits can lower your risk of inadvertently allowing cybergerms to spread. Since the new year is an inspiring time for beginning new habits, I offer a few suggestions for ways to help protect yourself and those around you.</p>
<h2 id="heading-1-get-a-follow-up">1. Get a follow-up</h2>
<p>Recognizing a delivery method for cyberattack is getting more difficult. Messages with malicious links do not always come from strangers. They may appear to be routine communications, or seem to originate from someone you know or work with. Attacks use subtle but deeply-ingrained cognitive biases to override your common sense. Your natural response ensures you click.</p>
<p>Thankfully, there’s a simple low-tech habit you can use to deter these attacks: before you act, follow-up.</p>
<p>You may get an email from a friend that needs help, or from your boss who’s about to get on a plane. It could be as enticing and mysterious as a direct message from an acquaintance who sends a link asking, “Lol. Is this you?” It takes presence of mind to override the panic these attacks prey on, but the deterrent itself is quick and straightforward. Send a text message, pick up the phone and call, or walk down the hall and ask, “Did you send me this?”</p>
<p>If the message is genuine, there’s no harm in a few extra minutes to double check. If it’s not, you’ll immediately alert the originating party that they may be compromised, and you may have deterred a cyberattack!</p>
<h2 id="heading-2-use-and-encourage-others-to-use-end-to-end-encrypted-messaging">2. Use, and encourage others to use, end-to-end encrypted messaging</h2>
<p>When individuals in a neighborhood get the flu shot, others in that neighborhood are safer for it. Encryption is similarly beneficial. Encourage your friends, coworkers, and Aunt Matilda to switch to an app like Signal. By doing so, you’ll reduce everyone’s exposure to more exploitable messaging systems.</p>
<p>This doesn’t mean that you must stop using other methods of communication entirely. Instead, think of it  as a hierarchy. Use Signal for important messages that should be trusted, like requests for money or making travel arrangements. Use all other methods of messaging, like SMS or social sites, only for “unimportant” communications. Now, if requests or links that seem  important come to you through your unimportant methods, you’ll be all the more likely to second-guess them.</p>
<h2 id="heading-3-dont-put-that-dirty-usb-plug-into-your">3. Don’t put that dirty USB plug into your <em>*</em></h2>
<p>You wouldn’t brush your teeth with a toothbrush you found on the sidewalk. Why would you plug in a USB device if you don’t know where it’s been?! While we might ascribe <a target="_blank" href="https://en.wikipedia.org/wiki/2008_cyberattack_on_United_States">putting a random found USB drive in your computer</a> to a clever exploitation of natural human curiosity, we’re no sooner likely to suspect using <a target="_blank" href="https://www.howtogeek.com/444267/how-safe-are-public-charging-stations/">a public phone-charging station</a> or <a target="_blank" href="https://www.theverge.com/2019/8/15/20807854/apple-mac-lightning-cable-hack-mike-grover-mg-omg-cables-defcon-cybersecurity">a USB cable</a> we bought ourselves. Even seemingly-innocuous USB <a target="_blank" href="https://www.cbsnews.com/news/why-your-usb-device-is-a-security-risk/">peripherals</a> or <a target="_blank" href="https://www.us-cert.gov/ncas/current-activity/2010/03/08/Energizer-DUO-USB-Battery-Charger-Software-Allows-Remote-System">rechargeable</a> devices can be a risk.</p>
<p>Unlike email and some file-sharing services that scan and filter files before they reach your computer, plugging in via USB is as direct and <a target="_blank" href="https://www.wired.com/2014/07/usb-security/">unprotected</a> as connection gets. Once this connection is made, the user doesn’t need to do anything else for a whole host of bad things to happen. Through USB connections, problems like malware and ransomware can easily infect your computer or phone.</p>
<p>There’s no need to swear off the convenience of USB connectivity, or to avoid these devices altogether. Instead of engaging in questionable USB behavior, don’t cheap out on USB  devices and cables. If it’s going to get plugged into your computer, ensure you’re being extra cautious. Buy it from the manufacturer (like the Apple Store) or from a reputable company or reseller with supply chain control. When juicing up USB-rechargeables, don’t plug them into your computer. Use <a target="_blank" href="https://heronebag.com/blog/40-hours-drive-time-my-road-trip-charging-essentials/">a wall charger with a USB port</a> instead.</p>
<h2 id="heading-practice-healthy-cybersecurity-habits">Practice healthy cybersecurity habits</h2>
<p>Keeping  your devices healthy and happy is a matter of practicing good habits. Like battling the flu, good habits can help protect yourself and those around you. Incorporate some conscientious cybersecurity practices in your new year resolutions - or start them right away.</p>
<p>Have a safe and happy holiday!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ An Introduction to Cryptography and Linear Feedback Shift Registers ]]>
                </title>
                <description>
                    <![CDATA[ By Magdalena Stenius All around us data is transferred faster than ever. Sensitive data is also part of our everyday life. To protect that data, we use encryption. When we encrypt data, it changes in some way that renders it useless to the possible v... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/cryptography-and-lfsr/</link>
                <guid isPermaLink="false">66d4601251f567b42d9f848d</guid>
                
                    <category>
                        <![CDATA[ ciphers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Mathematics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 22 Jun 2019 12:02:44 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/06/tommy-lee-walker-409690-unsplash-1.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Magdalena Stenius</p>
<p>All around us data is transferred faster than ever. Sensitive data is also part of our everyday life. To protect that data, we use encryption. When we encrypt data, it changes in some way that renders it useless to the possible viewer, but that can be changed back to its original state when it arrives safely to the meant receiver. These transformations rely heavily on math, and particularly on a field of math called number theory. This text takes us through the basics of cryptography both from a mathematical perspective and as a programming matter.</p>
<h4 id="heading-ciphers-yesterday-and-today">Ciphers Yesterday and Today</h4>
<p>For as long as writing has existed, the concept of encryption has lived and developed alongside the plain text writing. The idea of rendering text seemingly incomprehensible for purposes of guarding a secret has been central especially in military use and politics. The word cipher originates from the medieval times, from words such as the latin <em>cifra</em> and Arabic <em>صفر</em> (sifr), which means “zero”. There are numerous theories on why zero would have been used to describe encryption, including that the concept of zero was not part of the roman number system and seen as a mystery among numbers. One of the oldest and most widely known ciphers used in military context is Caesars cipher, also known as Caesars shift.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*IehC7dyPV4f4mFcAUwQtfA.png" alt="Image" width="800" height="263" loading="lazy">
<em>Caesars Shift in Python3.</em></p>
<p>Caesars shift takes one key, which is used to shift each character in the plaintext. This single key is the weakness of the cipher: once the correct shift is figured out, the whole message is revealed. Mathematically, this type of cipher can be written as a problem in modular arithmetic, which works with values wrapped up in a specific range. We’ll discuss this in more depth later.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/1_Mt2X5MKczLf0WpslKCUvkA.png" alt="Image" width="600" height="400" loading="lazy">
<em>Shift encryption and decryption as modular arithmetic using a 26-letter alphabet.</em></p>
<p>The way we can solve the plaintext from the encrypted text is by finding the key. In the case of a Caesars cipher of value 3, finding out the key (3) lets us decrypt the whole text in one chunk. The key specifies the output of the encryption algorithm.</p>
<h4 id="heading-factors-and-primes">Factors and Primes</h4>
<p>Perhaps surprisingly, one of the foundational concepts that lays the ground for encryption is that of divisibility. To define what it means, let’s lay down some rules. Firstly, if we have <em>a</em> and <em>b</em> that are integers and <em>a</em> is not 0, a divides <em>b</em> if there is such an integer <em>k</em> that satisfies the following statement.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*bBWKJzCZ7cSSXjV3Mdk6Og.png" alt="Image" width="155" height="79" loading="lazy">
<em>A is a factor of b.</em></p>
<p>In case we find an integer which is larger than 1 and that does not have other positive factors than 1 and itself, we call it a <em>prime</em>. Integers larger than one which are not primes are known as <em>composite numbers</em>, due to their composed nature. For example, 4 is larger than 1 and it has a factor 2. Hence, it is a composite. On the other hand, 3 is an integer larger than one, but it does not have any other positive factors than 1 and itself. It is a prime. Other small primes are 2, 5, 7, 11 and 13.</p>
<p>According to the fundamental theorem of arithmetic, every integer larger than 1 can be written as an unique product of primes. This is good news for cryptographers, since they love working with primes. Why would that be? Well, one of the most straightforward reasons is that prime factorisation of large numbers takes up a lot of time. Many well known encryption systems such as RSA is fully based on this fact. The principal it works on is that there exists a public key (a product of two large primes) which is used to encrypt the message, and a secret key (containing those primes) which is used to decrypt the message. These primes are usually around 300 digits long.</p>
<h4 id="heading-a-matter-of-congruence">A Matter of Congruence</h4>
<p>Modularity is one of the foundational pillars of cryptography. Let’s approach this concept first from a perspective of division. What happens if we have 5 small candies and three students? Each student gets a candy, and 2 remain. This can be described as the following.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/rremainder.png" alt="Image" width="600" height="400" loading="lazy">
<em>R is the remainder of a when divided by n.</em></p>
<p>Can you find the other amounts of candies which leave 2 as a remainder when divided to the 3 students? The next amount would be 8, since each student would get two candies and again 2 would be left over. This can be described using congruence. 8 and 5 are congruent is modulo 3, meaning that they leave the same remainder when divided by 3.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*F0-jvG8EMA5hPMNJAgchxA.png" alt="Image" width="249" height="91" loading="lazy">
<em>5 is congruent to 8 in modulo 3.</em></p>
<p>In the example of Caesars shift, we use an alphabet that consists of 26 letters. We only work with those 26 values. After ‘Z’, we go back to ‘A’. This is modularity in practice. ‘A’ will always be at position 1 in our 26-letter list, so any count of position we get, if we divide it by 26 and the remainder is 1, we know to use ‘A’. This wraps up our numbers into a finite field, in which the largest value is 26. In practice, if my secret message would be ‘ABC’, I would first convert this to the numbers 123. After that, I would apply the shift. In case the key would be 3, the shift would produce 456. After this, I would point the numbers back to their letter representations, which are in the class of modulo 26. The encrypted message becomes ‘DEF’.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/again.png" alt="Image" width="600" height="400" loading="lazy">
<em>Again, encryption and decryption as modular arithmetic using a 26-letter alphabet.</em></p>
<p>You can think of this like a clock. When the arrow has gone around the clock, it ends up where it started. In modular arithmetics, the last integer is followed by the first. Another way to understand this is that the world of a specific modulo, only that amount of values exist. For example in modulo 2, only 2 values exist. In our alphabet, 26 values exist, and so on.</p>
<h4 id="heading-types-of-ciphers">Types of Ciphers</h4>
<p>What kind of keys a cipher uses can be used to categorise the cipher into asymmetric and symmetric keys. They differ in the question of which key is used for encryption and decryption. Symmetric ciphers are encrypted and decrypted using the same key (such as Caesars Cipher). Asymmetric key ciphers are decrypted with a different key than they are created with, such as the RSA encryption system which we briefly discussed earlier. This results in a longer time for creating the encryption, but the result is also much more secure.</p>
<p>Another way to categorise ciphers is by their way of operating in streams or blocks. Stream ciphers are symmetric key ciphers that operate on continuous streams of symbols. For example the encryptions used in Bluetooth is a stream cipher. Needless to say, in the age of wireless communication with a need for encryption, stream ciphers have become a vital part of mobile technology.</p>
<h4 id="heading-a-look-at-stream-ciphers">A Look at Stream Ciphers</h4>
<p>Remember that we discussed the concept of modular arithmetic earlier? In short, modular arithmetics are arithmetics in a finite field. Now, let’s take a look at another cipher that works with a finite field of values (also known as a Galois field). This cipher, however, does not always produce the same values given the same input, like shifting does. Its purpose is to produce a stream of keys used to encrypt another stream. Like a snake eating its own tail (a symbol often used for eternity), linear feedback shift registers work by feeding on their own output. They are constructed in a way that makes them endlessly cycle through a pattern of values while outputting that seemingly random pattern. The seed and all the outputted values are binary, meaning they get values 0 or 1. The way new values are created is by using a logical operator, usually exclusive or (XOR).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/logical.png" alt="Image" width="600" height="400" loading="lazy">
<em>Logical Gate XOR.</em></p>
<p>To describe this in a practical way, lets start looking at what we need to create a LFSR. We need a seed, which is a list of ones and zeros. The seed will be what we start shifting. In addition to our seed (or shift register) we have a collection of taps. The taps tell us which parts of the register we use when feeding back into it. Say that we have a seed 001 and two taps, 1 and 3. This means that when we start shifting, the new value will be a combination of the first and third numbers of the seed, 0 and 1. We use an operation called exclusive or to combine the two. 0 xor 1 gives 1. Since we are working with binary values, the feedback from our taps can be expressed as a polynomial in modulo 2.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*o9K4JH2YxEzjieQco9pTxA.png" alt="Image" width="165" height="83" loading="lazy">
<em>The feedback polynomial from taps 3 and 1.</em></p>
<p>So, if our shift register is 001 and we get a new value, 1, we insert it in the beginning and drop the last number out. Our new shift register state is now 100. We continue this shifting until we notice that our shift register has returned to it’s initial state, 001. Depending on the seed and taps we select, we can get loops of different lengths. A loop is called <em>maximal length</em> if it passes through all possible different combinations before reaching its original state. Since we’re using the binary system, the maximal length of a loop will be 2^n-1. The loop can also end up leaving its original state and getting stuck in a shorter loop within, never returning to its original state. Finding the seeds and taps that lead to a maximal-length cycle is essential. Some of the criterions for finding these taps is that the number of taps must be even and that the taps are setwise co-primes, meaning that they have no common divisor except 1.</p>
<p>Wait, that doesn’t seem so random! Wouldn’t a cycle like that be pretty easy to crack? The thing about shift registers is that they get pretty long, pretty quickly. Say we choose a seed of 20 bits and a tap of two values, 2 and 19. The length of the loop produced is 1 048 575, meaning we would get quite a large amount of seemingly random binary values.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/lfsrpy.png" alt="Image" width="600" height="400" loading="lazy">
<em>Linear Feedback Shift Register in Python3.</em></p>
<p>The flavour of LFSR we have briefly gone through is called Fibonacci LFSR. There are also other variations, in which the way the register is shifted differs. They all work to produce a pseudorandom stream of bits used to encrypt streams. The range of applications for this type of encryption ranges from bluetooth to GSM (cellphone communication) standards.</p>
<h4 id="heading-in-conclusion">In Conclusion</h4>
<p>As a programmer, learning about the concept of modular arithmetics and division opens new ways in thinking about everyday coding problems. However, in security-critical projects using ready-made systems and standards for encryption is always recommended, since specialists in the field of cryptography probably find a safer and more effective solution than an enthusiastic hobbyist.</p>
<p>Sources:</p>
<p><a target="_blank" href="http://delta.utu.fi/about/monistemyynti/">Algebraic Structures in Cryptography by V. Niemi</a></p>
<p><a target="_blank" href="https://www.eetimes.com/document.asp?doc_id=1274550">Tutorial on Linear Feedback Shift Registers by EETimes</a></p>
<p><a target="_blank" href="https://www.rocq.inria.fr/secret/Anne.Canteaut/MPRI/chapter3.pdf">Encyclopedia of Cryptography and Security by Anne Canteout</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ A top-down introduction to SSH and how it enables secure data-sharing ]]>
                </title>
                <description>
                    <![CDATA[ By Sam Ollason This article will take a high-level and top-down approach to explain how SSH works and how it is used for securely communicating with remote computers. We will look at how an SSH session is actually ‘secure’ and how computers establish... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/a-top-down-introduction-to-ssh-965f4fadd32e/</link>
                <guid isPermaLink="false">66c343600bafa8455505c66b</guid>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ software development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ssh ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 06 Mar 2019 12:18:02 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*TiltvM4ydji8sXcvbsEL_Q.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Sam Ollason</p>
<p><strong>This article will take a high-level and top-down approach to explain how SSH works and how it is used for securely communicating with remote computers.</strong></p>
<p>We will look at how an SSH session is actually ‘secure’ and how computers establish and set-up an SSH session in the first place. We will also look at the benefits of using SSH.</p>
<p><em>Note:</em> This is intended as future notes to myself, but I hope you learn something from it too!</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/F0xSx0bm1cKylEjl0uyrNv0IUDmaXv2DE3mb" alt="Image" width="800" height="559" loading="lazy">
_Photo by [Unsplash](https://unsplash.com/photos/pY_AZJfdbHQ?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText" rel="noopener" target="_blank" title=""&gt;Matt Artz on &lt;a href="https://unsplash.com/search/photos/key?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText" rel="noopener" target="<em>blank" title=")</em></p>
<h3 id="heading-what-is-ssh">What is SSH?</h3>
<p>SSH is short for ‘secure shell’. It is a protocol for sharing data between two computers over the internet.</p>
<p>A protocol is essentially a set of rules that define the language that computers can use to communicate.</p>
<p>Typically, the two computers involved are your computer (the ‘client’) and a remote server (the ‘host’).</p>
<h3 id="heading-why-do-we-care">Why do we care?</h3>
<h4 id="heading-secure-communications-between-computers">Secure communications between computers</h4>
<p>Whenever two computers communicate over the internet we want to be sure that our messages can’t be intercepted and understood by anyone listening to the messages.</p>
<p>Imagine sending your bank details over the internet to buy something online. If your messages weren’t encrypted, then any computer that was listening or any computer that received the messages to pass onwards may be able to see your account number and your password. That isn’t good!</p>
<p>I believe this is an important concept to understand for anyone who aspires to work with web technologies.</p>
<h4 id="heading-secure-access-to-remote-computers">Secure access to remote computers</h4>
<p>Using SSH to check authentication is a more secure way of authentication than using a password. We will explore how this works below.</p>
<h3 id="heading-how-is-ssh-secure">How is SSH secure?</h3>
<p>SSH is a secure way of sending communications between two computers.</p>
<p>By ‘secure’, I mean a way of encoding the messages on a client computer such that the only other computer that can decode the messages and understand them is the host. This encoding/decoding is called <strong>encryption,</strong> so what we really mean here is SSH is secure because it uses an <strong>encrypted communication channel.</strong></p>
<h3 id="heading-how-is-a-ssh-session-established">How is a SSH session established?</h3>
<p>There are several processes that need to happen between two computers in order for an SSH session to begin.</p>
<ol>
<li>First we need a way of setting up a secure method of exchanging messages between the computers. We need to set up an <strong>encrypted channel.</strong></li>
<li>We need a way of checking that the data received by the host hasn’t been tampered with. This called <strong>verification</strong> and here we are verifying the integrity of the data that is sent by the client.</li>
<li>Verification (again). We need a way of checking that the computer we are communicating with isn’t an imposter. This is another form of verification but here we are verifying the identity of the computer.</li>
</ol>
<p>After these three steps, we can now communicate securely with a remote computer.</p>
<p>After these steps, we can share ‘secret’ data securely and we can also check if a client has permission to access a host in a more secure way than using a password. This process is called <strong>authentication using asymmetric encryption.</strong></p>
<p>Each of these sections below will go into more detail on these steps.</p>
<h3 id="heading-setting-up-an-encrypted-channel"><strong>Setting up an encrypted channel</strong></h3>
<p>A core part of the SSH protocol is that is it secure (it is in even in the name!), meaning all information that is sent using SSH is encrypted.</p>
<h4 id="heading-how-does-this-information-get-encrypted">How does this information get encrypted?</h4>
<p>Encrypting essentially just means ‘jumbling up the letters’ using some clever maths. Both computers need to have a way of encrypting the information so that only the other computer can decrypt the information and understand it.</p>
<h4 id="heading-how-does-this-work">How does this work?</h4>
<p>Both computers have an identical version of a <strong>symmetric key.</strong> The symmetric key is just a string of letters stored somewhere on the computers. The computers can use the symmetric keys to encrypt and also decrypt messages sent to them.</p>
<p>Using this symmetric key approach is called <strong>symmetric encryption.</strong> The ‘symmetric’ part comes from the fact the symmetric key on each computer is identical. This approach works really well … but it only works as long as no other computers have access to the symmetric key.</p>
<h4 id="heading-a-problem">A problem</h4>
<p>How do both computers know what the symmetric key is?</p>
<p>One computer could create it and send it in a message over the internet. But the messages wouldn’t be encrypted yet, so anyone intercepting the messages would instantly have the symmetric key … and can decrypt all future communications. That’s bad!</p>
<p>This is sometimes called the ‘key-exchange’ problem. It is clear that we need to add another step in the process before we can use symmetric keys.</p>
<h4 id="heading-a-solution">A solution</h4>
<p>A solution to the ‘key-exchange’ problem above is that both computers share some public information with each other (it is ‘public’ meaning they don’t mind if anyone intercepts it) and combine this with some information on their own computer to <strong>independently</strong> create <strong>identical</strong> symmetric keys.</p>
<p>These symmetric keys can then be used in symmetric encryption in the way outlined above.</p>
<h4 id="heading-how-this-works">How this works</h4>
<p>Both computers each have their own private key and public key. Together they form a <strong>key-pair</strong>. The computers <strong>share their public keys</strong> with each other over the internet. So, at this point in the process each computer knows</p>
<ul>
<li>its own private key,</li>
<li>its own public key,</li>
<li>and the other computer’s public key.</li>
</ul>
<h4 id="heading-generating-symmetric-keys">Generating Symmetric Keys</h4>
<p>Both computers then use these 3 pieces of information to independently generate an <strong>identical</strong> symmetric key.</p>
<p>Each computer uses a mathematical algorithm which uses the 3 inputs mentioned above. This algorithm is part of the Diffie-Hellman key exchange algorithm. The algorithm that will be executed on each computer is something like this:</p>
<pre><code>Host
pub_2 = other computer<span class="hljs-string">'s public key
pub_1 = my public key
pri_1 = my private key

f(pub_2, pub_1, pri_1) = abcdefg // Symmetric Key

Client:
f(pub_1, pub_2, pri_2) = abcdefg // Symmetric Key</span>
</code></pre><p>The important thing to take away here is that computers have <strong>shared only public information</strong> over the internet <strong>but have still been able to create symmetric keys!</strong></p>
<p>The approach of using key-pairs and sharing public information to generate identical symmetric keys is called <strong>asymmetric encryption</strong>. It is called ‘asymmetric’ because both computers start off with their own, different, key pairs.</p>
<p><strong>So far:</strong> we have seen how to use asymmetric encryption to independently generate identical symmetric keys on both computers <em>in a secure way</em> (solving the key-exchange problem) and then securely exchange information between computers using symmetric keys for encryption and decryption.</p>
<h3 id="heading-verification">Verification</h3>
<p>So we can communicate securely. But the next part of the process of establishing an SSH session is to verify that the data hasn’t been tampered with as it has been transmitted <strong>and</strong> that the other computer is actually who it is says it is.</p>
<h4 id="heading-why-do-we-need-this">Why do we need this?</h4>
<p>Another computer could impersonate one of the computers and initiate the key exchange above. So how do we <strong>securely</strong> figure out that the message is actually from the other computer and not from an imposter?</p>
<h4 id="heading-hashing">Hashing</h4>
<p>We have to use a <strong>hash</strong> function. This is just a mathematical function that takes inputs and produces a string of a fixed size.</p>
<p>The important feature of this function is that it is virtually impossible to work out what the inputs were just using the outputs.</p>
<p>After a client and a host have generated their symmetric keys, the client will use a hashing function to generate a HMAC. This just stands for “hash-based message authentication code”. This is just another string of characters/numbers. The client will send this HMAC to the server for verification.</p>
<p>The ingredients to the hashing function are</p>
<ul>
<li>The symmetric key on the client</li>
<li>The package sequence number (each message that is sent is contained in a ‘package’ of information)</li>
<li>The (encrypted!!!) message contents</li>
</ul>
<p>An example with fake data:</p>
<pre><code>symm_key       = abcdefg
pkge_no        = <span class="hljs-number">13</span>
encr_message   = encrypted_password

Hash(symm_key, pkge_no, encr_message) = *HMAC* <span class="hljs-comment">// Hashed value</span>
</code></pre><h4 id="heading-how-does-the-host-use-this-information">How does the host use this information?</h4>
<p>When the host receives the HMAC, it can use <strong>the same</strong> hash function with these three ingredients:</p>
<ul>
<li>its own copy of the (identical!) symmetric key,</li>
<li>the package sequence number,</li>
<li>and the encrypted message.</li>
</ul>
<p>If the hashed value it computes is the same as the HMAC it received from the client, then we have verified that the connecting computer is the same as the computer who has the symmetric key.</p>
<p>Remember that only the host and client know what the symmetric key is and no other computers do!</p>
<p>So here it doesn’t matter that the host doesn’t know the decoded contents of the encrypted message —the host has still verified the identity of the connecting computer!</p>
<p>The beauty of this approach is that we have not just verified the identity of the client and made sure that the data hasn’t been tampered, but we have done so securely (without <strong>without sharing any private information)</strong>.</p>
<p><strong>Summary:</strong> we used a hash function on the client and then on the host to verify data integrity and verify the identity of the client.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ej0rVm5QFV0xIuBr4f2Dm8CIAqxZTjkfl5jP" alt="Image" width="800" height="533" loading="lazy"></p>
<h3 id="heading-authentication">Authentication</h3>
<p>The final part of the securely communicating with remote computers is:</p>
<p><em>even if</em> we have generated symmetric keys with the connecting computer and</p>
<p><em>even if</em> we are using the symmetric keys to communicate securely and</p>
<p><em>even if</em> the connecting computer is genuinely the client we expect and not an imposter,</p>
<p>then we have set up an SSH session … but does the connecting computer have <strong>permission</strong> to access the contents of the host?</p>
<p>This is called ‘authentication’: the act of checking permissions and access rights.</p>
<h4 id="heading-there-are-two-ways-of-checking-authentication">There are two ways of checking authentication:</h4>
<p><strong>1—Using a password</strong></p>
<p>The client can send the host an (encrypted) message containing a password. The host can decrypt the message and check the password in a database to check if the client has permission to access the specified ‘user’ (area of the computer). Job done.</p>
<p><strong>2 — Using key-pairs and asymmetric encryption</strong></p>
<p>Earlier, we saw how asymmetric encryption can use two key-pairs to securely generate identical symmetric keys on both the client and the host. Using similar ideas, the client can <strong>log in without a password</strong>.</p>
<p>This is a very high-level approach to the how the process works:</p>
<p><em>Setting up:</em></p>
<p>On the client, head to the terminal and use a command to generate a public key and a private key (under the surface it uses ‘RSA’, a mathematical algorithm) on the client. Copy the <strong>public</strong> key (NOT the private key!) to the clipboard.</p>
<p><em>I repeat:</em> Copy the <strong>PUBLIC</strong> key (<strong>NOT THE PRIVATE</strong> KEY!) to the clipboard.</p>
<p>Then, in the terminal on the client, use a password to remotely log in to the host. Paste the public key of the client into the appropriate folder on the host alongside any other public keys.</p>
<p>Now, the host has</p>
<ul>
<li>It’s own public/private key-pair</li>
<li>The public key of the client</li>
</ul>
<p>Looking at the section above on the key-exchange algorithm, you can see how the host has all the ingredients it needs to generate a symmetric key!</p>
<p><em>Challenging:</em></p>
<p>When the client wants to connect, the host can use issue a ‘challenge’ by sending a message that has been encrypted (with the host’s symmetric key) and say: <em>‘I will only authorise you access if you can decrypt this message!’.</em></p>
<p>The client then has</p>
<ul>
<li>its own public and private key</li>
<li>the public key of the host</li>
<li>the encrypted message</li>
</ul>
<p>So now the client has everything needed to generate an (identical) symmetric key … and decrypt the message! It can decrypt the message and send confirmation that is has ‘succeeded’ in the challenge back to the host.</p>
<p>The host is satisfied that the connecting client is authorised and grants permission for access.</p>
<p><strong>Why bother using the second approach?</strong></p>
<p>This is seen as more secure than simply using a password because a bot can use a ‘brute force’ approach to keep using lots of combinations to guess your password, but they will not have they right key-pairs for the second approach to work.</p>
<p>Further reading:</p>
<p><a target="_blank" href="https://www.hostinger.com/tutorials/ssh-tutorial-how-does-ssh-work"><strong>SSH Tutorial for Beginners - How Does SSH Work</strong></a><br><a target="_blank" href="https://www.hostinger.com/tutorials/ssh-tutorial-how-does-ssh-work">_SSH, or Secure Shell, is a remote administration protocol that allows users to control and modify their remote servers…_www.hostinger.com</a></p>
<p><a target="_blank" href="https://www.udemy.com/the-complete-junior-to-senior-web-developer-roadmap/">https://www.udemy.com/the-complete-junior-to-senior-web-developer-roadmap/</a></p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>SSH is an important tool used to remotely control other computers.</p>
<p>SSH is secure because both computers can encrypt and decrypt message using identical symmetric keys (known as ‘symmetric encryption’).</p>
<p>The main steps to initiate an SSH session are:</p>
<ol>
<li><strong>Setting up an encrypted channel.</strong> Using asymmetric encryption to solve the key-exchange problem which independently generates identical symmetric keys on both computers without sharing any private information.</li>
<li><strong>Verification:</strong> Using hashing on both computers to verify the identity of the connecting computer</li>
<li>Verification (again). Using hashing on both computers to verify data integrity hasn’t been compromised in transmission.</li>
</ol>
<p>We can then use SSH to securely send data between the computers. One important use case of this is for <strong>authentication.</strong> Although you can use a password, using asymmetric encryption to check the connecting ‘client’ has permission to access the ‘host’ is is seen as more secure.</p>
<p>If you are interested in leveling up your SSH, I seriously recommend <a target="_blank" href="https://www.udemy.com/the-complete-junior-to-senior-web-developer-roadmap/">this</a> course. I found it really useful to sharpen up some of my skills! (<em>disclaimer:</em> I have no links or ties to the author or the platform. I took the course a while ago and found it really good!)</p>
<p>Thanks for reading!</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
