<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Repana Reddy Sekhar</title>
    <description>The latest articles on DEV Community by Repana Reddy Sekhar (@repana_tech_docs).</description>
    <link>https://dev.to/repana_tech_docs</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1247136%2F6bbfc4fc-03a3-480a-bc46-b8a2d488ce5d.png</url>
      <title>DEV Community: Repana Reddy Sekhar</title>
      <link>https://dev.to/repana_tech_docs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/repana_tech_docs"/>
    <language>en</language>
    <item>
      <title>Encryption vs Hashing 🤔 Lets decode</title>
      <dc:creator>Repana Reddy Sekhar</dc:creator>
      <pubDate>Sat, 10 Feb 2024 06:30:15 +0000</pubDate>
      <link>https://dev.to/repana_tech_docs/encryption-vs-hashing-lets-decode-2a24</link>
      <guid>https://dev.to/repana_tech_docs/encryption-vs-hashing-lets-decode-2a24</guid>
      <description>&lt;p&gt;Everyone thinks encryption and hashing are same, but there is so much difference between them which we will see next.&lt;/p&gt;

&lt;p&gt;While both techniques are essential for protecting data, they serve distinct purposes. In this post, we'll delve into the disparities between encryption and hashing, exploring their applications and providing practical code examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  Encryption:
&lt;/h2&gt;

&lt;p&gt;Encryption is a process that transforms readable data into an unreadable format, commonly known as ciphertext. This conversion is reversible, meaning that the ciphertext can be decrypted back into the original plaintext if the proper key is available. Encryption is commonly used to secure data during transmission or storage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;

public class EncryptionExample {

    private static final String secretKey = "MySecretKey123"; // Replace with a strong and secure key

    public static void main(String[] args) {
        // Original data
        String originalData = "Sensitive information";

        // Encryption example using AES algorithm
        String encryptedData = encrypt(originalData);
        System.out.println("Original data: " + originalData);
        System.out.println("Encrypted data: " + encryptedData);

        // Decryption example
        String decryptedData = decrypt(encryptedData);
        System.out.println("Decrypted data: " + decryptedData);
    }

    private static String encrypt(String data) {
        try {
            // Generate a key specification from the secret key
            SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), "AES");

            // Create a Cipher instance with AES algorithm
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);

            // Encrypt the data
            byte[] encryptedBytes = cipher.doFinal(data.getBytes());

            // Encode the encrypted data using Base64
            return Base64.getEncoder().encodeToString(encryptedBytes);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    private static String decrypt(String encryptedData) {
        try {
            // Generate a key specification from the secret key
            SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), "AES");

            // Create a Cipher instance with AES algorithm
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);

            // Decode the Base64 encoded encrypted data
            byte[] encryptedBytes = Base64.getDecoder().decode(encryptedData);

            // Decrypt the data
            byte[] decryptedBytes = cipher.doFinal(encryptedBytes);

            // Convert the decrypted bytes to a string
            return new String(decryptedBytes);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember to replace the secretKey in the EncryptionExample program with a strong and secure key. The decrypt function in this program demonstrates the decryption process using the same key used for encryption.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hashing:
&lt;/h2&gt;

&lt;p&gt;Hashing is a one-way process that converts input data into a fixed-size string of characters, commonly referred to as a hash or digest. Unlike encryption, hashing is not reversible, meaning that you cannot retrieve the original data from its hash. Hashing is frequently employed for data integrity verification and password storage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.security.MessageDigest;

public class HashingExample {

    public static void main(String[] args) {
        // Original data
        String originalData = "Sensitive information";

        // Hashing example using SHA-256 algorithm
        String hashedData = hash(originalData);
        System.out.println("Original data: " + originalData);
        System.out.println("Hashed data: " + hashedData);
    }

    private static String hash(String data) {
        try {
            // Create a MessageDigest instance with SHA-256 algorithm
            MessageDigest digest = MessageDigest.getInstance("SHA-256");

            // Update the digest with the data bytes
            byte[] hashedBytes = digest.digest(data.getBytes());

            // Convert the hashed bytes to a hexadecimal representation
            StringBuilder hexStringBuilder = new StringBuilder();
            for (byte hashedByte : hashedBytes) {
                hexStringBuilder.append(String.format("%02x", hashedByte));
            }

            return hexStringBuilder.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Summary: Encryption ensures confidentiality by transforming data into a reversible format, while hashing provides data integrity and password protection through irreversible processes. Understanding when and how to use each technique is crucial for implementing robust security measures in applications and systems.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;Feel free like this blog and subscribe for more tech blogs.&lt;br&gt;
Feel free to buy me a coffee: &lt;a href="https://ko-fi.com/repanareddysekhar"&gt;https://ko-fi.com/repanareddysekhar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>encryption</category>
      <category>hash</category>
      <category>blockchain</category>
      <category>solana</category>
    </item>
    <item>
      <title>SOLID Principles</title>
      <dc:creator>Repana Reddy Sekhar</dc:creator>
      <pubDate>Sat, 06 Jan 2024 18:25:11 +0000</pubDate>
      <link>https://dev.to/repana_tech_docs/solid-principles-2bpd</link>
      <guid>https://dev.to/repana_tech_docs/solid-principles-2bpd</guid>
      <description>&lt;p&gt;The SOLID principles are a set of five design principles in software development intended to make software designs more understandable, flexible, and maintainable. &lt;br&gt;
These principles were introduced by Robert C. Martin (also known as Uncle Bob) to guide developers in creating better software architecture.&lt;/p&gt;

&lt;p&gt;We will look each of these principles one by one:&lt;/p&gt;

&lt;h2&gt;
  
  
  Single Responsibility Principle (SRP)
&lt;/h2&gt;

&lt;p&gt;It states that &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A class should have one and only one reason to change&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b_RKm7YZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xwwrlrg8nv10hkxrx23b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b_RKm7YZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xwwrlrg8nv10hkxrx23b.png" alt="Image description" width="800" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we carefully observe in the above Employee class, we are doing two things i.e storing employee and calculating pay which defies SRF.&lt;/p&gt;

&lt;p&gt;The Solution for the above problem is just create two classes like below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KnZoNid7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wcprn7huv62eop08a2ax.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KnZoNid7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wcprn7huv62eop08a2ax.png" alt="Image description" width="800" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Open Closed Principle (OCP):
&lt;/h2&gt;

&lt;p&gt;It states that    &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Example:&lt;br&gt;
Let us consider below class to calculate penal fee based on lender:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5xvpwVWW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bkph7pk2zg56bbew2v8l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5xvpwVWW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bkph7pk2zg56bbew2v8l.png" alt="Image description" width="800" height="514"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Suppose if we want to add another lender, we need to modify this class which is not best practice and defies OCP.&lt;/p&gt;

&lt;p&gt;Solution for the above problem is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rPe-EJah--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqapjviw79h2bf2f8h7c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rPe-EJah--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqapjviw79h2bf2f8h7c.png" alt="Image description" width="800" height="585"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Liskov Substitution Principle (LSP)
&lt;/h2&gt;

&lt;p&gt;It states that    &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Objects of a superclass should be replaceable with objects of its subclasses without affecting the correctness of the program&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words,&lt;br&gt;
Inheritance hierarchies such that derived classes must be completely substitutable for their base classes&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dAeTO3ZL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dwfgnqyi5zs8xdwn44h6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dAeTO3ZL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dwfgnqyi5zs8xdwn44h6.png" alt="Image description" width="800" height="590"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above code, we have seen it clearly violates LSP.&lt;/p&gt;

&lt;p&gt;Solution for the above problem is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NlstpGwo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ibcdheesjnvw57jddm0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NlstpGwo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ibcdheesjnvw57jddm0.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Interface Segregation Principle
&lt;/h2&gt;

&lt;p&gt;It states that    &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Clients shouldn’t be forced to depend on methods they do not use.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b6SK_epa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vhq1xmvbmkb5bg6dd1im.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b6SK_epa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vhq1xmvbmkb5bg6dd1im.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Solution:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--piGyk0Ad--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v2cgg7j8idra1b9iou3o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--piGyk0Ad--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v2cgg7j8idra1b9iou3o.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Dependency Inversion Principle
&lt;/h2&gt;

&lt;p&gt;It states that    &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;High-level module must not depend on the low-level module, but they should depend on abstractions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fzoJ8wcB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/msdae922jxqh3ailk6yo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fzoJ8wcB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/msdae922jxqh3ailk6yo.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Solution:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TMbY1TEf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/geiugvyewhetds37di3t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TMbY1TEf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/geiugvyewhetds37di3t.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--icy7vvJT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/25hyqrz4z97ariz2ylau.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--icy7vvJT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/25hyqrz4z97ariz2ylau.png" alt="Image description" width="800" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Maintainability&lt;/li&gt;
&lt;li&gt;Flexibility and Extensibility &lt;/li&gt;
&lt;li&gt;Readability and Understanding &lt;/li&gt;
&lt;li&gt;Quality Software&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;Feel free like this blog and subscribe for more tech blogs.&lt;br&gt;
Feel free to buy me a coffee: &lt;a href="https://ko-fi.com/repanareddysekhar"&gt;https://ko-fi.com/repanareddysekhar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>solidprinciples</category>
      <category>java</category>
      <category>springboot</category>
    </item>
  </channel>
</rss>
