hexdefender
Email
  • Introduction to Linux
    • Overview
    • Linux Kernel
    • Linux Distros
    • Introduction to Kali Linux
    • Install Kali on VirtualBox
    • Install Kali on AWS
  • Linux Commands
    • Linux File Systems
    • Basic File and Directory commands
    • File Permissions and Ownerships
    • System Commands in Linux
    • Text Processing Commands in Linux
    • Linux Archive Utility
    • Package Management in Kali Linux
    • Networking Commands
    • Disk Utility Tools
    • Linux List of CLI Command lookup
    • Linux CLI Cheatsheet
    • Assignment
  • Networking Essentials
    • Overview
    • Networking Protocols
    • IP Addressing & Subnetting
    • DNS and DNS Security
    • Network Devices and Architecture
    • VPNs and Secure Tunnels
    • Network Address Translation (NAT) & Port Forwarding
    • Wireless Networks & Protocols
    • Cloud Networking & Security
    • Common Network Tools
  • Bash Scripting
    • Fundamentals of Bash
    • Variables, Branching and Loops
    • System Variables in Bash
    • Functions and Error Handling in Bash Scripts
    • File Handling and Text Processing
    • 5 Useful Bash Scripts for Everyday Tasks
    • Useful Assignments
  • Fundamentals of Cybersecurity
    • Introduction to Cybersecurity
    • Importance of Cybersecurity
    • Important Cybersecurity Frameworks
    • Cybersecurity Roles and Career Options
  • Penetration Testing
    • Reconnaissance and Footprinting
    • Exploitation Techniques
      • Introduction
      • Service Enumeration
      • Password Attacks
      • Exploit Discovery
      • The Art of Exploitation
      • The Pentester's guide to Metasploit
    • Post Exploitation - Malware & Escalation
  • Web Application Security
    • Common Web Vulnerabilities
    • OWASP Top 10
    • SQL Injections
    • Cross Site Scripting Attacks
    • Web Application Firewalls
    • Secure Coding Practices
  • Cryptography
    • Basic concepts of cryptography
    • Examples of Asymetric & Hashing functions
    • Public Key Infrastructure
    • Digital Signatures
    • Symmetric and Asymmetric Encryption
  • Social Engineering
    • Introduction to Social Engineering
    • Mitigation Strategies for Social Engineering
  • Digital Forensics
    • Digital Forensics Basics
    • Forensics Tools and Techniques
    • Reverse Engineering Fundamentals
    • Malware Analysis
Powered by GitBook
On this page
  1. Cryptography

Examples of Asymetric & Hashing functions

Certainly! Let’s delve deeper into asymmetric cryptography and hashing, providing thorough explanations and ample examples for better understanding.


Guide to Cryptography: In-Depth Focus on Asymmetric Cryptography and Hashing

1. Asymmetric Cryptography

Definition: Asymmetric cryptography, also known as public-key cryptography, utilizes two different keys: a public key, which can be shared openly, and a private key, which is kept secret. This dual-key approach allows for secure data transmission, digital signatures, and authentication without the need for sharing a secret key.

1.1 Key Pair Generation

To implement asymmetric cryptography, a pair of keys must be generated. The public key is derived from the private key using mathematical algorithms. The most common algorithm for key generation is RSA (Rivest-Shamir-Adleman).

Key Generation Example (RSA):

  1. Choose Two Prime Numbers: Select two distinct large prime numbers, ( p ) and ( q ).

  2. Calculate ( n ): Multiply ( p ) and ( q ) to get ( n ), which will be used as part of the public key. [ n = p times q ]

  3. Calculate ( phi(n) ): Compute Euler's totient function, ( phi(n) ), where [ phi(n) = (p-1) times (q-1) ]

  4. Choose Public Exponent ( e ): Select a small integer ( e ) such that ( 1 < e < phi(n) ) and ( gcd(e, phi(n)) = 1 ).

  5. Calculate Private Exponent ( d ): Determine ( d ) such that [ d times e \mod \phi(n) = 1 ]

The public key is ( (e, n) ) and the private key is ( (d, n) ).

1.2 Encryption and Decryption Process

The process of encrypting and decrypting data using asymmetric cryptography can be illustrated as follows:

Encryption:

  1. Convert the plaintext message into an integer ( m ) such that ( 0 < m < n ).

  2. Calculate the ciphertext ( c ) using the recipient’s public key ( (e, n) ): [ c = m^e \mod n ]

Decryption:

  1. Using the private key ( (d, n) ), the recipient can recover the plaintext message ( m ): [ m = c^d mod n ]

Example: Let’s consider small prime numbers for simplicity.

  • ( p = 61 ), ( q = 53 )

  • Calculate ( n ): [ n = 61 times 53 = 3233 ]

  • Calculate ( phi(n) ): [ \phi(n) = (61-1) times (53-1) = 3120 ]

  • Choose ( e = 17 ) (a common choice).

  • Calculate ( d ): [ d times 17 mod 3120 = 1 implies d = 2753 quad (text{using the Extended Euclidean Algorithm}) ]

Now, the public key is ( (17, 3233) ) and the private key is ( (2753, 3233) ).

Encrypting a Message: Suppose we want to encrypt the message ( m = 123 ). [ c = 123^{17} \mod 3233 = 855 ]

Decrypting the Ciphertext: The recipient can decrypt ( c = 855 ): [ m = 855^{2753} \mod 3233 = 123 ]

2. Cryptographic Hash Functions

Definition: A cryptographic hash function is a mathematical algorithm that converts an input (or 'message') into a fixed-size string of bytes, typically a digest that uniquely represents the data. It is designed to be a one-way function, meaning that it is infeasible to reverse the process and obtain the original input from the hash output.

2.1 Properties of Cryptographic Hash Functions

  1. Deterministic: The same input will always produce the same output.

  2. Fast Computation: The hash value should be quick to compute for any given data.

  3. Pre-image Resistance: Given a hash ( h ), it should be infeasible to find any input ( x ) such that ( h = hash(x) ).

  4. Collision Resistance: It should be infeasible to find two distinct inputs ( x ) and ( y ) such that ( hash(x) = hash(y) ).

  5. Avalanche Effect: A small change in the input should produce a significantly different hash.

2.2 Common Hash Algorithms

  • MD5 (Message Digest 5): Produces a 128-bit hash value. It is no longer considered secure due to vulnerabilities that allow for collision attacks.

  • SHA-1 (Secure Hash Algorithm 1): Produces a 160-bit hash value. Like MD5, it has known vulnerabilities and is not recommended for secure applications.

  • SHA-256: Part of the SHA-2 family, producing a 256-bit hash value. It is widely used and considered secure for most applications.

  • SHA-3: The latest member of the Secure Hash Algorithm family, providing enhanced security features.

2.3 Hashing Example (SHA-256)

Hashing a Message:

  1. Consider the message "Hello, World!".

  2. Use SHA-256 to compute the hash:

import hashlib

# Create a SHA-256 hash of the input message
message = "Hello, World!"
hash_object = hashlib.sha256(message.encode())
hash_hex = hash_object.hexdigest()

print(f"SHA-256 Hash: {hash_hex}")

Output:

SHA-256 Hash: a591a6d40bf420404a011733cfb7b190d62c65bf0bcda190f400e9f7d42b303c

Verifying Integrity: To verify the integrity of a file, one can compute its hash value and compare it to a previously computed hash. If the values match, the file has not been altered.

Example: If a file has a known SHA-256 hash of abc123..., any changes to the file would produce a different hash value, indicating tampering.

3. Applications of Asymmetric Cryptography and Hashing

  • Secure Email Communication: Asymmetric encryption enables secure email communications through PGP (Pretty Good Privacy) and S/MIME (Secure/Multipurpose Internet Mail Extensions).

  • Digital Signatures: Hash functions are used to create digital signatures. A sender hashes a message and encrypts the hash with their private key. The recipient can verify the signature using the sender's public key and ensure that the message has not been altered.

  • Secure Web Browsing: HTTPS uses a combination of asymmetric and symmetric encryption to secure data transmission between a client and server.

  • Blockchain and Cryptocurrencies: Hash functions are fundamental in blockchain technology. Each block contains a hash of the previous block, creating a secure and immutable ledger.


4. Conclusion

Understanding asymmetric cryptography and cryptographic hash functions is essential in the realm of information security. Asymmetric cryptography enables secure key exchanges and digital signatures, while hashing ensures data integrity and authenticity. By applying these cryptographic principles, individuals and organizations can significantly enhance their security measures against unauthorized access and tampering.

PreviousBasic concepts of cryptographyNextPublic Key Infrastructure

Last updated 8 months ago