Cryptography in Computer Networks: Symmetric, Asymmetric, Hashing & Digital Signatures
0Sahil Dubey
COMPUTER NETWORKS • CHAPTER 35
Cryptography in Computer Networks: Symmetric, Asymmetric, Hashing & Digital Signatures
Suppose you send your password, bank information or private message through a network.
If the data travels in normal readable form, anyone who successfully intercepts it may try to read or change it.
Cryptography gives us techniques to hide data, detect modification, verify identity and prove that a message was signed using a particular private key.
The easiest way to understand cryptography is to imagine four tools: a lock, two different keys, a fingerprint and a signature.
ConfidentialityKeep information secret
IntegrityDetect unwanted change
AuthenticationVerify identity or origin
Non-RepudiationDigital evidence of origin
Direct Answer
Cryptography is the science of protecting information by transforming it using mathematical algorithms and keys.
Symmetric cryptography uses the same secret key for encryption and decryption, while asymmetric cryptography uses a public key and a private key.
A cryptographic hash function creates a fixed-length digital fingerprint of data. A digital signature uses public-key cryptography to help verify the origin and integrity of a message.
What Is Cryptography?
Cryptography means protecting information using mathematical techniques.
The original readable data is converted into another form so that unauthorized people cannot easily understand it.
Simple Definition:
Cryptography is the technique of securing information using algorithms and keys so that only intended users can correctly read, verify or use it.
Cryptography is used in:
HTTPS websites
Online banking
UPI and payment systems
Wi-Fi security
VPN communication
Email security
Digital certificates
Software updates
Secure messaging
Why Is Cryptography Needed in Computer Networks?
When data travels through a network, several security problems are possible.
An attacker may try to:
Read private information.
Modify a message.
Pretend to be another user or server.
Replay an old valid message.
Create a fake message.
Main Need:
Cryptography protects data when we cannot fully trust the communication path.
Important Cryptography Terms
Plaintext
Original readable information.
Ciphertext
Encrypted unreadable-looking representation.
Encryption
Conversion of plaintext into ciphertext.
Decryption
Conversion of ciphertext back into plaintext.
Cipher
Cryptographic algorithm used for encryption and decryption.
Key
A value used by a cryptographic algorithm to control its transformation.
Cryptanalysis
Study of techniques used to analyse or break cryptographic protection.
Confidentiality
Prevent unauthorized people from reading information.
Integrity
Detect whether information was changed.
Authentication
Help verify who created or sent data.
Non-Repudiation
Digital signatures can provide evidence that supports proving the origin of a signed message when private keys are properly controlled.
Basic Working of Encryption
Basic Cryptographic Transformation
Plaintext
HELLO
Encryption
Algorithm + Key
Ciphertext
Protected Form
Decryption
Recover Plaintext
Symmetric Key Cryptography
Symmetric cryptography uses the same secret key, or closely related secret-key material, for both encryption and decryption.
Symmetric Encryption:
Sender and receiver share one secret key.
Shared Secret Key Model
Sender
Has secret key
SAME
SECRET
KEY
Receiver
Has same secret key
Both endpoints must protect the shared key.
How Symmetric Encryption Works
Sender and receiver obtain the same secret key.
Sender encrypts plaintext using that secret key.
Ciphertext travels through the network.
Receiver uses the secret key to decrypt it.
Symmetric Trick:
One secret key - both sides.
Main Advantage
Symmetric encryption is generally fast and suitable for encrypting large amounts of data.
Main Problem
Both sides need a secure way to obtain the same secret key.
If the shared secret key is stolen, anyone holding that key may be able to decrypt protected information or create valid encrypted data depending on the cryptographic mode being used.
AES - Advanced Encryption Standard
AES is one of the most widely used modern symmetric block ciphers.
AES supports key sizes of:
AES-128
128-bit key.
AES-192
192-bit key.
AES-256
256-bit key.
ChaCha20
Modern symmetric stream cipher used in several security protocols.
Exam Point:
AES is symmetric cryptography.
DES and 3DES
DES
Uses an effective 56-bit secret key and is no longer considered secure for modern general-purpose protection because brute-force attacks are practical.
3DES
Applies DES operations multiple times. It improved security compared with DES but is now considered a legacy algorithm and has largely been replaced by modern ciphers.
Exam Memory:
DES = old symmetric cipher.
AES = modern symmetric standard.
Block Cipher vs Stream Cipher
Point
Block Cipher
Stream Cipher
Basic Idea
Processes fixed-size blocks
Generates a stream used to protect data continuously
Example
AES
ChaCha20
Use
Files, network records, stored data and many protocols
Efficient continuous-data encryption
Asymmetric Key Cryptography
Asymmetric cryptography uses two mathematically related keys.
Public Key - may be shared.
Private Key - must be kept secret.
PUBLIC KEY
Can be distributed to others.
PRIVATE KEY
Must remain under the owner's control.
Public Key and Private Key
A public-key pair can be used in different ways depending on the algorithm and protocol.
For Confidentiality
In a basic public-key encryption model:
Encrypt using receiver's public key.
Decrypt using receiver's private key.
For Digital Signature
In a digital signature model:
Sign using sender's private key.
Verify using sender's public key.
How Asymmetric Encryption Works
1. Receiver Shares
Public Key
2. Sender Encrypts
Using receiver's public key
3. Ciphertext Travels
Through network
4. Receiver Decrypts
Using private key
RSA
RSA is a well-known public-key cryptographic algorithm.
It can be used for operations such as:
Public-key encryption in suitable schemes
Digital signatures
Security protocols and certificate systems
RSA security depends on proper key sizes, secure padding schemes and correct implementation. Textbook diagrams often simplify RSA to “public key / private key,” but practical cryptography requires much more than raw mathematical RSA operations.
Elliptic Curve Cryptography - ECC
ECC is another important form of asymmetric cryptography.
It can provide strong security with smaller key sizes than traditional RSA for comparable security levels.
Easy Memory:
RSA and ECC are examples of asymmetric cryptography.
Symmetric vs Asymmetric Cryptography
Point
Symmetric
Asymmetric
Keys
One shared secret key
Public and private key pair
Speed
Usually faster
Usually slower
Large Data
Very suitable
Usually not used to encrypt very large data directly
Key Distribution
Difficult because secret must be shared securely
Public key can be openly distributed
Examples
AES, ChaCha20
RSA, ECC
Digital Signature
Not public-key digital signature
Used for digital signatures
Hybrid Cryptography
Modern secure network communication commonly combines symmetric and asymmetric cryptography.
Step 1 - Authentication
Certificates and public-key cryptography help authenticate endpoints.
Step 2 - Shared Secrets
A secure key-establishment process creates session keys.
Step 3 - Bulk Encryption
Fast symmetric cryptography protects normal application data.
Symmetric cryptography efficiently protects large amounts of data.
What Is Cryptographic Hashing?
Hashing is different from encryption.
A cryptographic hash function takes an input of almost any practical length and produces a fixed-length output called a:
Hash Value / Message Digest / Digital Fingerprint
Input Message
"Computer Networks"
HASH
Fixed-length digest
Example concept:
256-bit fingerprint
Hashing is not encryption.
A cryptographic hash is designed as a one-way transformation. There is no normal “decrypt the hash” operation.
Properties of a Good Cryptographic Hash Function
Deterministic
Same input gives the same hash.
Fixed-Length Output
Output size remains fixed for a chosen hash algorithm.
Preimage Resistance
Given a hash, it should be computationally infeasible to find an original input producing it.
Second-Preimage Resistance
Given one message, it should be hard to find another message with the same hash.
Collision Resistance
It should be difficult to find any two different inputs having the same hash.
Avalanche Behaviour
A small input change should cause a large unpredictable change in the digest.
SHA-2, SHA-3, MD5 and SHA-1
SHA-256
Member of SHA-2 family with 256-bit output.
SHA-3
Modern cryptographic hash family based on a different internal design from SHA-2.
SHA-1
Cryptographically broken for collision resistance and should not be used for new security designs.
MD5
Also broken for collision resistance and unsuitable for modern cryptographic security.
Exam Trick:
SHA-256 = modern widely used cryptographic hash.
MD5 and SHA-1 = old and insecure for collision-resistant security uses.
Avalanche Effect
A good cryptographic hash should react strongly even to a tiny change in input.
Message 1
NETWORK
Digest A = completely different-looking fingerprint
Message 2
NETWORL
Digest B = another very different fingerprint
Avalanche Effect:
Tiny input change - large unpredictable output change.
HMAC - Hash-Based Message Authentication Code
A normal hash does not prove who created a message.
HMAC combines a cryptographic hash function with a secret key.
Message
Data to protect
Shared Secret Key
Known to trusted parties
HMAC
Integrity + authentication check
Hash:
Integrity fingerprint.
HMAC:
Hash + Secret Key - integrity and message authentication.
What Is a Digital Signature?
A digital signature is a public-key cryptographic mechanism used to help verify the origin and integrity of digital information.
DIGITAL
SIGNATURE
Simple Definition:
A digital signature is created using the signer's private key and verified using the corresponding public key.
A digital signature is not a scanned handwritten signature image.
It is a mathematical cryptographic value.
How Digital Signature Works
Sender Side
1. Create the message.
2. Calculate its cryptographic hash.
3. Sign using the sender's private key and a digital-signature algorithm.
4. Send message + signature.
Receiver Side
1. Receive message + signature.
2. Hash the received message.
3. Verify signature using sender's public key.
4. Confirm whether the signature matches the received message.
Message Hash
Fingerprint message
Private Key
Create signature
Send
Message + Signature
Public Key
Verify signature
Digital Signature Trick:
Private Key = Sign
Public Key = Verify
What Does a Digital Signature Provide?
Integrity
Modification of signed data normally causes signature verification to fail.
Authentication
Helps verify that the signature was created using the private key corresponding to the trusted public key.
Non-Repudiation Support
Can provide strong evidence of origin when private keys, certificates and operational controls are properly managed.
Not Confidentiality by Itself
Signing does not automatically hide the message.
Encryption vs Hashing vs Digital Signature
Encryption
Main purpose: confidentiality.
Protected data can be decrypted with the correct key.
Hashing
Main purpose: fingerprint / integrity-related use.
Designed to be one-way.
Digital Signature
Main purpose: origin authentication + integrity + non-repudiation support.
Digital Certificates
A public key is useful only if we know whose key it really is.
A digital certificate helps bind an identity to a public key.
Simplified Digital Certificate
Subject
Identity of certificate holder.
Public Key
Public key belonging to that subject.
Issuer
Certificate Authority that issued the certificate.
Validity
Period during which the certificate is valid.
Signature
Issuer's digital signature over the certificate information.
PKI and Certificate Authority
PKI stands for:
Public Key Infrastructure
PKI provides systems for managing:
Public keys
Digital certificates
Certificate Authorities
Certificate validation
Revocation information
CA = Certificate Authority
Its job is to issue and digitally sign certificates after following its validation process.
Cryptographic Key Management
Strong algorithms are useless if keys are handled badly.
Key Generation
Keys must be generated using secure randomness and approved methods.
Key Distribution
Secret keys must reach trusted endpoints safely.
Key Storage
Private and secret keys require strong protection.
Key Rotation
Long-lived systems may periodically replace cryptographic keys.
Key Revocation
Compromised or invalid credentials must no longer be trusted.
Key Destruction
Old sensitive keys should be securely removed when no longer required.
Common Cryptographic Threats
Brute-Force Attack
Attacker systematically tries possible keys.
Man-in-the-Middle Attack
Attacker tries to position themselves between two endpoints and manipulate communication.
Replay Attack
Previously valid communication is captured and sent again.
Weak Key Management
Strong cryptography fails if secret or private keys are exposed.
Hash Collision Attack
Attacker tries to find different inputs producing the same digest.
Implementation Failure
Bugs, weak random numbers, bad protocol design or incorrect configuration can break security even when the algorithm itself is strong.
Solved Cryptography Numericals
Numerical 1: Key Space
Suppose a toy cryptographic key contains 8 bits.
Number of Possible Keys = 2^n
n = 8
Key Space = 2^8
= 256
Answer = 256 possible keys
Numerical 2: 10-Bit Key Space
Key Space = 2^10
= 1024
Answer = 1024 possible keys
Numerical 3: Symmetric Keys Required for Multiple Users
If every pair of users needs a different shared symmetric key:
Number of Keys = n(n - 1) / 2
For 10 users:
Keys = 10(10 - 1) / 2
= 10 × 9 / 2
= 45
Answer = 45 shared symmetric keys
Numerical 4: Asymmetric Keys for 10 Users
If each user has:
One public key
One private key
Total Keys = 2n
n = 10
Total = 2 × 10
= 20 keys
Answer = 10 public + 10 private = 20 total keys
Numerical 5: SHA-256 Output Size
SHA-256 produces:
256 bits
Convert to bytes:
256 / 8 = 32 bytes
SHA-256 Digest = 256 bits = 32 bytes
Numerical 6: SHA-256 Hexadecimal Length
One hexadecimal digit represents 4 bits.
256 / 4 = 64
SHA-256 is commonly written as 64 hexadecimal characters.
Numerical 7: Symmetric Keys for 20 Users
Keys = n(n - 1) / 2
= 20 × 19 / 2
= 190
Answer = 190 pairwise symmetric keys
Numerical 8: Hash Output Possibilities
A toy hash produces a 16-bit output.
Possible Digests = 2^16
= 65,536
Real cryptographic hashes use much larger output sizes. This example is only for understanding the formula.
Cryptography Remember Tricks
Cryptography:
Protect information using algorithms and keys.
Plaintext:
Readable data.
Ciphertext:
Encrypted data.
Symmetric:
Same shared secret key.
Asymmetric:
Public key + Private key.
Confidentiality:
Encryption.
Hash:
Digital fingerprint.
HMAC:
Hash + Secret key.
Digital Signature:
Private key signs.
Public key verifies.
AES:
Modern symmetric cipher.
RSA / ECC:
Asymmetric cryptography.
MD5 / SHA-1:
Do not use for modern collision-resistant cryptographic security.
Certificate:
Identity + Public Key + CA Signature.
Common Cryptography Exam Mistakes
1. Hashing and encryption are the same.
Wrong. Encryption is reversible with the correct key. A cryptographic hash is designed to be one-way.
2. Symmetric encryption uses public and private keys.
Wrong. Symmetric encryption uses a shared secret key.
3. Asymmetric cryptography uses the same key for encryption and decryption.
Wrong. It uses a mathematically related public/private key pair.
4. Public key must always remain secret.
Wrong. A public key is designed to be distributed. The private key must be protected.
5. Digital signature hides the message.
Wrong. Signing provides origin/integrity properties but does not automatically provide confidentiality.
6. Sender signs using public key.
Wrong. The sender uses the private key to create a digital signature.
7. Receiver verifies digital signature using sender's private key.
Wrong. Verification uses the sender's public key.
8. SHA-256 can be decrypted.
Wrong. SHA-256 is a cryptographic hash function, not an encryption algorithm.
9. MD5 is secure for modern digital signatures.
Wrong. MD5 has serious collision weaknesses.
10. DES is a modern recommended cipher.
Wrong. DES is obsolete because its key space is too small.
11. Digital certificate is the same as digital signature.
Wrong. A certificate contains identity and public-key information and is itself digitally signed by its issuer.
12. Strong encryption solves every security problem.
Wrong. Security also depends on key management, authentication, software quality, endpoint protection and correct protocol design.
13. Encryption always guarantees integrity.
Not automatically. Secure protocols use encryption modes or authentication mechanisms that also protect integrity.
14. HMAC and normal hash are identical.
Wrong. HMAC includes a shared secret key.
40 Important Cryptography Questions With Answers
1. What is cryptography?
Answer: Cryptography is the science of protecting information using mathematical algorithms and cryptographic keys.
2. What is plaintext?
Answer: Plaintext is the original readable form of information before encryption.
3. What is ciphertext?
Answer: Ciphertext is the encrypted form of data produced after applying an encryption algorithm.
4. What is encryption?
Answer: Encryption converts plaintext into ciphertext using a cryptographic algorithm and key.
5. What is decryption?
Answer: Decryption converts ciphertext back into plaintext using the required cryptographic key and algorithm.
6. What is symmetric cryptography?
Answer: Symmetric cryptography uses a shared secret key for encryption and decryption.
7. Give examples of symmetric algorithms.
Answer: AES and ChaCha20 are modern examples. DES and 3DES are older examples.
8. What is the main advantage of symmetric encryption?
Answer: It is generally fast and efficient for protecting large amounts of data.
9. What is the main problem of symmetric encryption?
Answer: The sender and receiver must securely obtain and protect the same secret key.
10. What is AES?
Answer: AES is Advanced Encryption Standard, a widely used modern symmetric block cipher.
11. What key sizes does AES support?
Answer: AES supports 128-bit, 192-bit and 256-bit keys.
12. Why is DES no longer considered secure?
Answer: DES has an effective 56-bit key, which is too small against modern brute-force attacks.
13. What is asymmetric cryptography?
Answer: Asymmetric cryptography uses a mathematically related public key and private key.
14. Which key can be shared publicly?
Answer: The public key.
15. Which key must remain secret?
Answer: The private key.
16. Give examples of asymmetric cryptography.
Answer: RSA and Elliptic Curve Cryptography are common examples.
17. How is asymmetric encryption used for confidentiality?
Answer: In a basic model, data is encrypted using the receiver's public key and decrypted using the receiver's private key.
18. Why is symmetric encryption usually used for bulk data?
Answer: Symmetric encryption is computationally faster than public-key encryption.
19. What is hybrid cryptography?
Answer: Hybrid cryptography combines public-key mechanisms for authentication or key establishment with fast symmetric encryption for normal data transfer.
20. What is a cryptographic hash function?
Answer: It is a one-way mathematical function that converts input data into a fixed-length message digest.
21. Is hashing reversible?
Answer: Cryptographic hashing is designed to be one-way and does not have a normal decryption operation.
22. What is collision resistance?
Answer: Collision resistance means it should be computationally difficult to find two different messages having the same hash.
23. What is preimage resistance?
Answer: Given a hash value, it should be computationally infeasible to find an input that produces that hash.
24. What is the avalanche effect?
Answer: A very small change in input should produce a large unpredictable change in cryptographic output.
25. What is SHA-256?
Answer: SHA-256 is a member of the SHA-2 family that produces a 256-bit digest.
26. How many bytes are in a SHA-256 digest?
Answer: 256 divided by 8 equals 32 bytes.
27. Is MD5 secure for modern cryptographic collision resistance?
Answer: No. MD5 has serious collision weaknesses and should not be used for new security designs requiring collision resistance.
28. What is HMAC?
Answer: HMAC is a message authentication mechanism that combines a cryptographic hash function with a shared secret key.
29. What is a digital signature?
Answer: A digital signature is a public-key cryptographic mechanism used to verify the origin and integrity of digital information.
30. Which key is used to create a digital signature?
Answer: The signer's private key.
31. Which key verifies a digital signature?
Answer: The corresponding public key.
32. Does digital signature automatically hide the message?
Answer: No. Signing is mainly used for integrity and origin authentication. Encryption is used for confidentiality.
33. What is a digital certificate?
Answer: A digital certificate binds identity information to a public key and is digitally signed by its issuer.
34. What is a Certificate Authority?
Answer: A Certificate Authority is an organization or system that issues and signs digital certificates under defined validation rules.
35. What is PKI?
Answer: PKI means Public Key Infrastructure and manages public keys, certificates, trust relationships and certificate validation.
36. How many pairwise symmetric keys are required for 10 users?
Answer: 10 × 9 / 2 = 45 keys.
37. How many total public and private keys are required for 10 users if each has one key pair?
Answer: 10 public keys + 10 private keys = 20 total keys.
38. What is brute-force attack?
Answer: A brute-force attack systematically tries possible key values until the correct one is found.
39. Why is key management important?
Answer: Even strong algorithms can fail if keys are generated, stored, shared or revoked insecurely.
40. Give the easiest cryptography memory line.
Answer: Symmetric uses one shared key, asymmetric uses public/private keys, hashing creates a fingerprint and digital signature uses private key to sign and public key to verify.
20 Cryptography MCQs With Answers
1. Cryptography is mainly used for:
A. Network security
B. Increasing monitor size
C. Cable installation
D. Printer control
Answer: A
2. Original readable data is called:
A. Ciphertext
B. Plaintext
C. Digest
D. Certificate
Answer: B
3. Encrypted data is called:
A. Plaintext
B. Ciphertext
C. Token
D. Frame
Answer: B
4. Symmetric encryption uses:
A. One shared secret key
B. Only public key
C. Only private key
D. No key
Answer: A
5. Which is a symmetric cipher?
A. AES
B. RSA
C. ECC
D. Digital certificate
Answer: A
6. Which is an asymmetric algorithm?
A. AES
B. RSA
C. SHA-256
D. HMAC
Answer: B
7. Public-key cryptography uses:
A. Public and private key pair
B. Only shared password
C. No key
D. CRC only
Answer: A
8. Which key must remain secret in asymmetric cryptography?
A. Public key
B. Private key
C. Certificate
D. Hash
Answer: B
9. Hashing produces:
A. Fixed-length digest
B. IP address
C. MAC address
D. Routing table
Answer: A
10. SHA-256 output length is:
A. 64 bits
B. 128 bits
C. 256 bits
D. 512 bytes
Answer: C
11. SHA-256 output size in bytes is:
A. 16 bytes
B. 32 bytes
C. 64 bytes
D. 256 bytes
Answer: B
12. Which is NOT secure for modern collision-resistant cryptographic use?
A. SHA-256
B. SHA-3
C. MD5
D. Modern SHA-2
Answer: C
13. HMAC combines hash function with:
A. Secret key
B. IP address
C. MAC address
D. Routing protocol
Answer: A
14. Digital signature is created using:
A. Sender's private key
B. Sender's public key
C. Receiver's private key only
D. No key
Answer: A
15. Digital signature is verified using:
A. Sender's public key
B. Sender's private key
C. Receiver's password
D. DES key
Answer: A
16. Digital signature mainly provides:
A. Integrity and origin authentication
B. Data compression only
C. Routing
D. MAC learning
Answer: A
17. Digital certificate contains:
A. Identity and public key information
B. Only plaintext password
C. Only MAC address
D. Routing table
Answer: A
18. CA stands for:
A. Certificate Authority
B. Cipher Algorithm
C. Connection Address
D. Crypto Application
Answer: A
19. Pairwise symmetric keys needed for n users are:
A. n
B. 2n
C. n(n - 1) / 2
D. n² + n
Answer: C
20. Best memory line is:
A. Symmetric = one secret key, asymmetric = key pair
B. Hashing = encryption
C. Public key must remain secret
D. Signature hides the message
Answer: A
Frequently Asked Questions
What is cryptography in simple words?
Cryptography protects digital information using mathematical algorithms and cryptographic keys.
What is symmetric encryption?
Symmetric encryption uses a shared secret key for encryption and decryption.
What is asymmetric encryption?
Asymmetric cryptography uses a public key and a private key instead of one shared secret key.
What is hashing?
Hashing converts data into a fixed-length digital fingerprint using a one-way cryptographic hash function.
What is the difference between hashing and encryption?
Encryption is designed to be reversible using the correct key, while cryptographic hashing is designed as a one-way transformation.
What is a digital signature?
A digital signature is created using a private key and verified using the corresponding public key to help prove message origin and integrity.
Does digital signature encrypt the message?
No. A digital signature does not automatically provide confidentiality. Encryption is required when the message itself must remain secret.
What is AES?
AES is Advanced Encryption Standard, a widely used modern symmetric block cipher.
What is RSA?
RSA is a public-key cryptographic algorithm used in areas such as digital signatures and suitable public-key encryption schemes.
What is HMAC?
HMAC combines a cryptographic hash function with a shared secret key to provide message integrity and authentication.
What is a digital certificate?
A digital certificate binds identity information with a public key and is digitally signed by a certificate issuer.
Why is key management important?
Strong cryptographic algorithms cannot protect information if secret or private keys are generated, shared, stored or revoked insecurely.