How Digital Signatures Ensure Data Integrity?

Table of contents
- π§ What is a Digital Signature?
- π How Do Digital Signatures Work?
- π Step-by-Step Breakdown of Digital Signature Process
- π Why Use Digital Signatures?
- πΉ Digital Signatures vs Electronic Signatures
- π Where Are Digital Signatures Used?
- π οΈ How to Create a Digital Signature in Node.js?
- π Final Thoughts
- About Me π¨βπ»

π§ What is a Digital Signature?
A digital signature is a cryptographic technique that ensures the authenticity, integrity, and non-repudiation of digital messages or documents.
When you digitally sign a document, you are providing a unique fingerprint that proves:
β The message is from you (Authentication).
β The message was not altered in transit (Integrity).
β The sender cannot deny signing it (Non-Repudiation).
π How Do Digital Signatures Work?
A digital signature is created using asymmetric encryption (Public Key Cryptography). It involves:
1οΈβ£ Hashing the message (to create a unique fingerprint).
2οΈβ£ Encrypting the hash with the senderβs private key.
3οΈβ£ Sending the message & signature to the receiver.
4οΈβ£ Verifying the signature using the senderβs public key.
sequenceDiagram
participant Sender as π’ Sender
participant Receiver as π΅ Receiver
Sender ->> Sender: Hash the Message π’
Sender ->> Sender: Encrypt Hash with Private Key π
Sender -->> Receiver: Send Message + Digital Signature π
Receiver ->> Receiver: Decrypt Signature with Public Key π
Receiver ->> Receiver: Hash the Received Message π’
Receiver -->> Receiver: Compare Hashes β
Note right of Receiver: If hashes match, the message is authentic! π
π Step-by-Step Breakdown of Digital Signature Process
1οΈβ£ Message Hashing:
The sender applies a hashing algorithm (e.g., SHA-256) to the original message.
This creates a fixed-length unique hash (fingerprint).
2οΈβ£ Signing the Hash:
The sender encrypts the hash using their private key.
This encrypted hash becomes the digital signature.
3οΈβ£ Message Transmission:
- The original message + digital signature are sent to the receiver.
4οΈβ£ Signature Verification:
The receiver decrypts the signature using the senderβs public key.
The receiver hashes the received message using the same algorithm.
If the hashes match, the message is authentic and unchanged!
π Why Use Digital Signatures?
β
Prevents Tampering β Ensures the message wasnβt altered.
β
Proves Authenticity β Verifies the senderβs identity.
β
Ensures Non-Repudiation β The sender cannot deny sending the message.
πΉ Digital Signatures vs Electronic Signatures
Feature | Digital Signature β | Electronic Signature β |
Security | High (uses cryptography) | Low (image/text-based) |
Verification | Can be mathematically verified | Usually cannot be verified |
Legality | Strong legal backing | Varies by jurisdiction |
Use Case | Secure documents, software signing | Online contract approvals |
π Digital Signatures are cryptographically secured, whereas Electronic Signatures are often just images of handwritten signatures.
π Where Are Digital Signatures Used?
π Software Distribution β Ensures apps & updates come from a trusted source.
π Secure Email (PGP, S/MIME) β Verifies sender authenticity.
π Blockchain & Cryptocurrency β Used for secure transactions.
π Legal Documents (e.g., DocuSign) β Provides legal validity.
π οΈ How to Create a Digital Signature in Node.js?
Want to see a digital signature in action? Hereβs an example using RSA encryption in Node.js with the built-in crypto
const crypto = require('crypto');
// Generate RSA Key Pair
const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', {
modulusLength: 2048,
});
// Original Message
const message = "Secure Message";
// Create Digital Signature
const sign = crypto.createSign('SHA256');
sign.update(message);
sign.end();
const signature = sign.sign(privateKey, 'hex');
console.log("Signature:", signature);
// Verify the Signature
const verify = crypto.createVerify('SHA256');
verify.update(message);
verify.end();
const isValid = verify.verify(publicKey, signature, 'hex');
console.log(isValid ? "β
Signature is valid!" : "β Signature is invalid!");
This Node.js script:
β
Generates RSA key pairs
β
Creates a digital signature for a message
β
Verifies the signature using the public key
π Final Thoughts
Digital Signatures are essential for security, providing:
Authenticity β Verifies the sender.
Integrity β Ensures data wasnβt altered.
Non-Repudiation β The sender cannot deny signing.
Would you like a tutorial on how to implement digital signatures in AWS KMS or OpenSSL? Letβs discuss in the comments! π
About Me π¨βπ»
I'm Faiz A. Farooqui. Software Engineer from Bengaluru, India.
Find out more about me @ faizahmed.in
Subscribe to my newsletter
Read articles from Faiz Ahmed Farooqui directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Faiz Ahmed Farooqui
Faiz Ahmed Farooqui
Principal Technical Consultant at GeekyAnts. Bootstrapping our own Data Centre services available at https://bolt.sh I lead the development and management of innovative software products and frameworks at GeekyAnts, leveraging a wide range of technologies including OpenStack, Postgres, MySQL, GraphQL, Docker, Redis, API Gateway, Dapr, NodeJS, NextJS, and Laravel (PHP). With over 9 years of hands-on experience, I specialize in agile software development, CI/CD implementation, security, scaling, design, architecture, and cloud infrastructure. My expertise extends to Metal as a Service (MaaS), Unattended OS Installation, OpenStack Cloud, Data Centre Automation & Management, and proficiency in utilizing tools like OpenNebula, Firecracker, FirecrackerContainerD, Qemu, and OpenVSwitch. I guide and mentor a team of engineers, ensuring we meet our goals while fostering strong relationships with internal and external stakeholders. I contribute to various open-source projects on GitHub and share industry and technology insights on my blog at blog.faizahmed.in. I hold an Engineer's Degree in Computer Science and Engineering from Raj Kumar Goel Engineering College and have multiple relevant certifications showcased on my LinkedIn skill badges.