Instructor: In this lesson,
we will learn about digital signatures.
A digital signature is a cryptographic technique
that ensures the authenticity
and integrity of a message or document.
It uses a pair of keys, a private key to sign the data
and a corresponding public key to verify the signature.
With a digital signature
and the sender's public key,
the signature recipient can confirm the identity
of the sender
and ensure the content
of the digitally signed message has not been altered.
Let's learn more about digital signatures
and non-repudiation.
Then let's do a walkthrough of a digital signature.
First, we have digital signatures.
Digital signatures ensure the authenticity
and integrity of a message, document, or piece of data.
They work by using a pair of cryptographic keys,
a private key that is used to create the signature
and a public key that is used to verify the signature.
Let's walk through the digital signature process
to better understand it.
In our scenario, let's assume Alice wants
to send Bob a digitally signed email.
It's important to note that both Alice
and Bob have their own public and private key pairs.
So to create a digital signature for her email,
Alice's email client will take her message for Bob
and run it through a hashing algorithm such as SHA 256.
This creates a unique hash digest
that is based on Alice's message to Bob.
Next Alice's email Client will use her private key
to encrypt the hash digest, which again is a hash
of her message to Bob.
This encrypted hash digest is appended to her email
and is known as a digital signature.
Note, Alice did not encrypt her actual email message to Bob.
That's because digital signatures focus on authenticity
and integrity, not confidentiality.
Back to our scenario.
Bob's email client now receives the email
and digital signature from Alice's email client.
At this point,
Bob's email client will decrypt Alice's digital signature,
which remember, is an encrypted hash of her email.
Bob's email client does this signature decryption
with Alice's public key, which is publicly available.
So Bob's email client decrypts Alice's digital signature,
and the result is the hash digest of Alice's message
that Alice's email client created.
Now, Bob's email client takes Alice's email message
and using the same hashing algorithm
that Alice's email client used, he hashes Alice's email.
If the calculated hash digest
matches the received hash digest,
then the email message was not modified in transit
and the message integrity has not been compromised.
But what about authenticity?
How do we know that it was really Alice's email client
that's signed the message?
That's where non-repudiation comes in.
And one of the key benefits of digital signatures is
that they not only provide integrity,
they also provide non-repudiation.
So second, we have non-repudiation.
Non-repudiation means
that once a digital signature is created,
the signer cannot later deny having signed the document.
This is because the signature is created
using the signer's private key,
which only the signer has access to.
After all, in our digital signature example, the only person
who could have encrypted Alice's email
with her private key was Alice.
This is because Alice keeps her private key private.
It is never shared.
So at email receipt, Bob can determine that Alice had
to be the one to encrypt the digital signature
because he can use Alice's public key
to decrypt the digital signature.
And in asymmetric encryption,
a public key can only decrypt something that was encrypted
by the associated private key.
So Bob decrypts Alice's digital signature
using her public key,
providing both integrity and non-repudiation.
But if Alice also wants to provide confidentiality,
she will need to encrypt the message itself.
And this can be done using Bob's public key.
This works because if something is encrypted
with Bob's public key, then only Bob
with his private key can decrypt it.
And since Bob keeps his private key private,
the confidentiality of the message from Alice
to Bob is assured.
This is where people get a bit confused.
So you may need to remember that to provide privacy
and confidentiality, the receiver's public key,
that's Bob's public key, is used
to encrypt the message.
To ensure the integrity of the message,
Alice needs to hash it to create a hash digest.
And to ensure authenticity of the message
through non-repudiation,
Alice needs to encrypt the hash digest of her message
with her private key.
If all three actions are taken, we call this encrypting
and digitally signing the message.
Most email clients can be configured to support this
as long as you have public
and private key pairs assigned to all your users.
Now using OpenSSL, let's walk through a demonstration
of a digital signature.
In the real world, this process would be done for you,
but it's important to understand academically how each
of these steps would occur.
So we'll walk through the process manually.
Again, our scenario
will be Alice sending a digital signature to Bob.
In the real world to start off,
both Alice and Bob would already have public
and private key pairs.
In this case, they don't.
But for a digital signature, we're only going
to need Alice's public and private key pair.
So let's create those.
We'll start by creating Alice's private key
using this OpenSSL command.
And it's created.
Then we'll create Alice's public key,
alice_public.key from Alice's private key,
which is called alice_private.key.
There we go.
Now, the first step in the digital signature process
is Alice creating a message to send to Bob.
We'll do this using the echo command
and create a file called alice_message.txt
that just says, this is Alice's message to Bob.
Next, we need to create Alice's digital signature.
This will require hashing Alice's alice_message.txt file,
and signing it
with Alice's private key called Alice_private.key.
This is done in one step,
and the result will be a file called alice_signature.bin
where bin stands for binary, which is the format
that the signature file will be in.
And it's created.
Now Alice would send her alice_message.txt file
along with her digital signature,
the alice_signature.bin file
and her public key, alice_public.key to Bob.
With all of that in hand,
Bob will decrypt the alice_signature.bin file
with the alice_public.key file.
The result will be the hash digest
of the alice_message.txt file that Alice created.
Then Bob will take the alice_message.txt file
that Alice sent him,
and he will hash it with the same hashing algorithm
that Alice used, in this case, SHA 256.
At this point, Bob has the hash
of the alice_message.txt file
that Alice created and the one that he created.
So he compares them.
If they are the same, the digital signature is verified OK
and the integrity of the message is validated.
This will all happen in one OpenSSL command.
As you can see, the digital signature has been verified OK.
This is the end of our demonstration.
So remember,
digital signatures are a cryptographic method used
to ensure authenticity and integrity of data.
They use a pair of keys, a private key
to create the signature
and a public key to verify it, confirming
that the data has not been altered.
Digital signatures also provide non-repudiation,
meaning the signer cannot deny having signed the data
because the signature was created with their private key,
which only they possess.
While digital signatures ensure authenticity
and integrity, they do not provide confidentiality.
To achieve that,
the message itself must be encrypted
using the recipient's public key.
Combining these techniques, digital signatures
for authenticity and integrity
and encryption for confidentiality, creates a secure
and trustworthy communication process.