Cryptography & Network Security Notes
Cryptography & Network Security Notes
Key aspects:
1. Protecting data and systems from cyber threats.
2. Ensuring only authorized users can access sensitive data.
3. Preventing unauthorized modifications and ensuring data integrity.
3. Security Approaches
There are multiple approaches to securing computer systems:
1. Prevention: Involves using firewalls, encryption, and strong authentication to
block attacks before they happen.
2. Protection: When Threat is ready to occur, protect the system.
3. Resilience: Threat has occurred now we need to solve the threat.
4. Detective Approach: Identifies security breaches using intrusion detection
systems (IDS) and monitoring tools.
5. Corrective Approach: Focuses on recovering from security incidents through
backups and disaster recovery plans.
6. Defense-in-Depth: A layered security strategy combining multiple protection
methods like firewalls, antivirus software, and access controls.
7. Zero Trust Security: Assumes no entity inside or outside the network is
trustworthy without verification.
Example: Implementing both firewalls and IDS for layered protection.
4. Principles of Security
Security principles form the foundation of cybersecurity measures:
1. Confidentiality:
i. Ensures that sensitive data is accessible only to authorized users.
ii. Example: Encrypting data before transmission.
2. Integrity:
i. Ensures data is accurate and not altered without authorization.
ii. Data can be modified by authorized users only.
iii. Example: Using hash functions like SHA-256 to verify data
integrity.
3. Availability:
Ensures systems and data are accessible when needed.
Example: Implementing redundancy and failover mechanisms.
4. Authentication:
i. Verifies the identity of users before granting access.
ii. Example: Using passwords, biometrics, or two-factor
authentication (2FA).
5. Non-Repudiation:
i. Ensures that actions cannot be denied after execution.
ii. Example: Digital signatures in electronic transactions.
5. Types of Attacks
Cyberattacks can be classified into various categories based on their target and impact:
Malware Attacks:
Use of malicious software like viruses, worms, and ransomware.
Example: WannaCry ransomware encrypting files and demanding payment.
Phishing Attacks:
Fraudulent attempts to obtain sensitive information via fake emails or websites.
Example: An email pretending to be from a bank requesting login credentials.
1. Introduction to Cryptography
Cryptography is the process of securing communication by converting
information into a secure format. It ensures confidentiality, integrity,
authentication, and non-repudiation of data.
• Early Cryptography: Used in ancient civilizations (e.g., Caesar cipher).
• Modern Cryptography: Uses mathematical algorithms for secure
communication.
Example: Online banking transactions use cryptographic algorithms to ensure data
security.
• Plaintext: "HELLO"
• Ciphertext (Caesar Cipher with shift 3): "KHOOR"
Encryption transforms plaintext into ciphertext, and decryption reverses the process.
o Substitution
o Transposition
Substitution Techniques -
A method where characters in plaintext characters are replaced with other characters
according to a predefined system.
3. Polyalphabetic Ciphers:
a. Each character will have a different substituting character.
b. (A → Z, A → X hence AA → ZX). [ 1 → many]
Keyed Ciphers:
4. Vigenère Cipher: (polyalphabetic)
a. Uses a keyword-based shifting mechanism for encryption.
b. Add the key value to plain text,
➢ C = (p + k) % 26.
7. Hill Cipher:
➢ C = K * P mod 26
a. Key ➔ M*N matrix,
b. break the plain text in Mx1 matrix and multiply with key matrix and do mod
26.
Steps:
1. Divide the plaintext into two equal halves: Left and Right.
2. Repeat for several rounds (e.g., 16 rounds):
a. Apply function F(k, R) i.e round fn on Right half and key.
b. XOR result of F(k, R) with Left to get new Right.
c. Now the result of XOR of left becomes new Right and the Right becomes
left for next round.
3. Combine the final Left and Right halves to get the ciphertext.
✅ Pros:
❌ Cons:
2. Asymmetric Key Cryptography: it uses two keys: a public key of receiver (for
encryption) and a private key of receiver (for decryption).
How it works:
Example Algorithms:
1. RSA (Rivest–Shamir–Adleman)
2. ECC (Elliptic Curve Cryptography)
3. DSA (Digital Signature Algorithm)
✅ Pros:
Larger key sizes provide better security but require more computational power.
Example: Alice and Bob share a secret key. Alice encrypts a message using this
key, and Bob decrypts it using the same key.
2. Algorithm Types & Modes
Types of Symmetric Key Algorithms:
1. Block Ciphers:
a. Encrypts data in fixed-size blocks (e.g., 64-bit, 128-bit).
b. Example: DES, AES, Blowfish, IDEA, RC5
2. Stream Ciphers:
a. Encrypts data bit-by-bit or byte-by-byte.
b. Example: RC4 (used in SSL, WEP)
Modes of Operation in Block Ciphers: Block ciphers use different modes of operation
to process data securely
➕ Advantages:
2. CBC – Cipher Block Chaining Mode: Each plaintext block is XORed with the
previous ciphertext block before encryption. The first block uses an Initialization Vector
(IV).
➕ Advantages:
Encrypts the previous ciphertext block (or IV), takes s selected bits from the output,
and XORs them with the plaintext to get ciphertext.
➕ Advantages
➖ Disadvantages
➕ Advantages
➖ Disadvantages
1. Cannot be parallelized
2. Sensitive to IV reuse . Regenerated IV must use unique IV every time
3. Vulnerable to certain attacks if IV or key is reused
4. Vulnerable to modification attacks
Encrypts a counter value (which increases with each block), and XORs the output with
plaintext. Acts like a stream cipher.
➕ Advantages
➖ Disadvantages
1. IV (nonce) and counter must never repeat — reusing them compromises security
2. Slightly more complex counter management
Initialization Vector for first step:
3. Overview of Symmetric Key Cryptography
Advantages:
1. Faster encryption and decryption.
2. Less computationally expensive than asymmetric cryptography. Suitable for bulk
data encryption.
Disadvantages:
1. Key distribution is difficult.
2. If the key is compromised, security is lost.
3. Does not provide authentication (only confidentiality).
Use Cases:
• Data encryption in cloud storage.
• VPN (Virtual Private Network) encryption.
• Wireless security protocols (WPA2, WPA3).
Weaknesses of DES:
• 56-bit key is vulnerable to brute-force attacks.
• Can be cracked using modern computing power.
DES was replaced by AES (Advanced Encryption Standard) and Triple DES (3DES).
Strengths:
1) Resistant to differential and linear cryptanalysis.
2) Stronger than DES due to a 128-bit key.
Weakness:
1) Patent restrictions made it less widely adopted.
2) Not widely used today due to AES dominance.
3) Example: Used in Pretty Good Privacy (PGP) encryption for emails.
Subkey generation:
RC5 (Rivest Cipher 5) Algorithm
Example:
Advantages:
1) Secure key exchange (no need to share a secret key).
2) Provides confidentiality, authentication, and non-repudiation.
Disadvantage:
1) Slower than symmetric encryption due to complex mathematical operations.
2) Computationally expensive for large data encryption.
Example Calculation:
• Choose p = 7, q = 11 → n = 77.
• Compute ϕ(n) = (7-1) × (11-1) = 60.
• Choose e = 17 (since gcd(17,60) = 1).
• Compute d such that (d × 17) mod 60 = 1 → d = 53.
Public Key: (77, 17), Private Key: (77, 53).
If plaintext M = 10,
Encryption: C = (10^17) mod 77 = 26.
Decryption: M = (26^53) mod 77 = 10.
Strengths of RSA:
1) Highly secure if large key sizes are used.
2) Used in SSL/TLS encryption, VPNs, and digital signatures.
Weaknesses:
1) Slow for large data encryption.
2) Vulnerable to brute force if small key sizes are used.
How it works:
1. A random symmetric key is generated by the sender.
2. Data is encrypted using this symmetric key.
3. The symmetric key is encrypted with the recipient's public key.
4. Both encrypted data and key are sent to the recipient.
5. The recipient decrypts the key with their private key and then decrypts the data.
Example in SSL/TLS (HTTPS):
Example:
Use Cases:
1) Password storage (hashed passwords in databases).
2) Data integrity verification, authentication.
3) Blockchain security (Bitcoin mining).
Internet Security Protocols
Security protocols protect data transmission over the internet. These protocols ensure
confidentiality, integrity, and authentication of information exchanged between
systems.
HTTPS websites,
SSL (Secure Sockets Layer) Encrypts web traffic
online banking
Secures email
S/MIME (Secure/Multipurpose messages using Email confidentiality
Internet Mail Extensions) and authentication
encryption
Benefits of SSL:
1) Encrypts sensitive data (e.g., passwords, credit card details).
2) Provides authentication via digital certificates. Prevents Man-in-the-Middle
(MITM) attacks.
Limitations:
SSL v2 and v3 are deprecated due to vulnerabilities. TLS 1.2 & 1.3 are recommended for
better security.
Alert Protocol
This protocol is used to convey SSL-related alerts to the peer entity. Each message in this
protocol contains 2 bytes.
Change-Cipher Protocol:
Used in SSL to switch from a pending to a current secure state after the Handshake is
complete. It sends a 1-byte message to activate the new encryption settings.
Password-Based Authentication
A password is a secret combination of characters used for authentication.
Example:
Weak password: password123
Strong password: G$8n!yT5@z1wX0
Key Components:
1) User: Wants to access a service.
2) Client-server: The front-end login page.
3) Authorization server: Verifies user credentials and generates a token.
4) Resource server: Grants access when a valid token is provided.
Why It Matters:
Enhances security without sacrificing user experience.
Stateless and encrypted — hard for hackers to misuse.
Works on both websites and mobile apps.
Certificate-Based Authentication
Biometric Authentication
Biometric authentication verifies a user's identity based on biological characteristics.
Advantages:
1. Difficult to fake or duplicate.
2. Faster authentication compared to passwords.
3. Eliminates the need to remember passwords.
Disadvantages:
1. Privacy concerns over biometric data storage.
2. Biometric scanners may fail due to injuries or environmental factors.
3. High implementation cost.
Example:
Face id in iPhones.
Fingerprint login on smartphones (e.g., Touch ID in iPhones).
Advantages of PGP:
Provides end-to-end encryption for secure email communication.
Uses public-key cryptography, ensuring only the intended recipient can read the
message.
Allows digital signatures to verify sender authenticity.
Disadvantages of PGP:
❌Complex setup and key management.
❌Requires both sender and receiver to use PGP software.
Example Use Case: Used by journalists and whistleblowers for secure communication.
Advantages of S/MIME:
✅ Integrated into most email clients (Outlook, Apple Mail).
✅ Uses digital certificates for verification, making it highly secure.
Disadvantages of S/MIME:
❌Requires Certificate Authorities (CAs) for authentication.
❌Expensive compared to PGP, as it requires paid certificates.
Example Use Case: Corporate email security for secure communication between
employees.
Introduction to Firewall
A firewall is a N/W security system that filters incoming and outgoing network traffic
based on a set of rules to prevent unauthorized access. It protects networks from cyber
threats like malware, hacking attempts, and unauthorized access.
Functions of a Firewall:
1. Monitors and filters network traffic.
2. Blocks unauthorized access to private networks.
3. Prevents malware and cyberattacks.
4. Enforces security policies for network users.
Firewall
Description Example Use Case
Type
Cloud A firewall hosted in the cloud for Used by cloud service providers
Firewall securing remote networks. (AWS, Azure).
Types of Firewalls
Advantages:
Simple and efficient.
Low cost and low resource usage.
Disadvantages:
❌Stateless: Cannot track active connections.
❌Less secure; vulnerable to IP spoofing and certain attacks.
Advantages:
High level of security.
Can log and analyze traffic at the application layer.
Hides internal network from the outside world.
Disadvantages:
❌Processing Overhead: Due to deep inspection and application-level filtering.
❌Slower compared to lower-layer firewalls.
3. Circuit-Level Gateway
● Function: Operates at the session layer (Layer 5 of OSI).
● Working:
○ Establishes two TCP connections:
■ One between internal host and the gateway.
■ Another between gateway and external host.
○ Performs security checks before connection is established.
○ Once the connection is approved, data flows freely without inspection.
Advantages:
Faster than packet filtering and proxy firewalls.
Hides internal network structure.
Suitable for session-based protocols.
Disadvantages:
❌Does not inspect data packets after connection is established.
❌Limited visibility into data content —
can allow malicious payloads if connection is trusted.
Next-Generation Firewall (NGFW)
What is it?
A Next-Generation Firewall (NGFW) enhances traditional firewalls by adding deep
packet inspection, application control, intrusion prevention, and user-based policies.
It provides smarter, multi-layered security.
Key Features:
1. Deep Packet Inspection (DPI): Inspects entire packet to detect malware or
suspicious content.
2. Application Control: Identifies and manages apps like Facebook, YouTube,
regardless of port/protocol.
3. Intrusion Prevention System (IPS): Detects and blocks known/unknown threats
like SQL injection, XSS.
4. User Identity Integration: Enforces rules based on users/groups (via Active
Directory, etc.).
5. SSL/HTTPS Inspection: Decrypts encrypted traffic to find hidden threats.
6. Threat Intelligence & Sandboxing: Blocks zero-day threats using cloud-based
analysis and behavior detection.
Advantages:
✅ Strong protection against modern threats.
✅ Greater visibility into traffic and user behavior.
✅ Controls application usage and enforces policies.
Disadvantages:
❌Higher cost and complexity.
❌Requires more system resources and skilled management.
1. Misconfiguration
Wrong rules may block legit traffic or allow threats.
2. Outdated Software
Unpatched firewalls are vulnerable to attacks.
3. Hardware Failures
Faulty devices can cause downtime or network issues.
4. Connectivity Problems
Bad configs can interrupt network communication.
5. Performance Lag
Slow firewalls can reduce internet speed.
6. Lack of Clear Policies
Inconsistent or missing rules create security gaps.
7. Traffic Blocks
Legit inbound/outbound traffic may be wrongly blocked.
Firewall Configuration:
1. Secure the Firewall
1. Change default passwords to strong, unique ones.
2. Update firmware to fix security vulnerabilities.
3. Disable SMTP and other outdated protocols.
4. Restrict TCP traffic and close unused ports.
5. Ensure Compliance
1. Follow rules like PCI-DSS, HIPAA, etc.
2. Enable logging and auditing of all access.
3. Review logs regularly and store audit data safely.
Example: A firewall is configured to allow only HTTPS (port 443) traffic and block
insecure HTTP (port 80) traffic.
DMZ (Demilitarized Zone) Network
It hosts public-facing services (like web, email, and DNS servers), allowing external
access without exposing the internal network to threats.
1. Traffic Filtering: Firewalls route and filter incoming traffic to DMZ servers based
on rules.
2. Isolated Access: External users can access DMZ services (e.g., web servers), but
cannot reach the internal network.
3. Security Layering: If a DMZ server is hacked, the internal firewall blocks further
access, protecting sensitive data.
4. Inbound & Outbound Access: DMZ allows inbound traffic to public services but
restricts or blocks outbound access to internal systems.
Example: A web server in the DMZ allows customers to access a company's website
while keeping the internal database secure.