Symmetric / Asymmetric encryption and message signature

Symmetric Encryption

Throughout the history several kind of algorithms have been used for exchanging critical messages from one to another. Using an algorithm, the message is packed in a cipher text and sent to the recipient. The recipient need a key to bring the message in to its original form. This introduce the concept of cryptography. There are two encryption methods we can call them as “Symmetric Cryptography” and “Asymmetric Cryptography”. Symmetric Cryptography is a form of very simple algorithm which requires both the sender and the recipient to know the secret key used for encryption.

Symmetric Cryptography
Symmetric Cryptography

Process flow:

  1. Bob shares a secret key with Alice securely and make sure no one has a copy of it.\
  2. Bob encrypt the “message” with a secret key.
  3. Bob send the “message” to Alice.
  4. Alice decrypt the “message” with the secret key.

Asymmetric Encryption (Public Key encryption)

Unlike symmetric cryptography, asymmetric cryptography uses two keys in the process of encrypting and decrypting message. One key is used to encrypt the message and the another different key is used to decrypt the message. This process uses a Public/Private key pair which is why it is know as asymmetric cryptography or public key encryption. Usually the public key of the recipient is used to encrypt the data. Only the receiver is having the private key which can be used to decrypt the shared data. Basically any one who has the public key of the recipient can encrypt the data and send to the recipient. No one in the middle can read the message except the recipient.

Asymmetric Cryptography
Asymmetric Cryptography

Process flow:

  1. Alice generate Private/Public key pare.
  2. Alice shares the public key to any one and keep the private key secret.
  3. Bob encrypts the “message” with Alice’s public key.
  4. Send the “message” to Allice.
  5. Alice decrypt the “message” with Alice’s private key.

Signing Message

Signing the message is a way of producing a digital signature similar to hand written signature. The digital signature ensures the message was not altered by a 3rd person.  As in the above example, Bob sends a message to Alice. Bob uses Alice’s public key to encrypt the message. It is possible, Alice would have shared her public key to more people in addition to Bob. Now what is the proof that the new message actually came from Bob and only from Bob? Here we come up with solution “Signing”.

Unlike the encryption, Signature is produced with the senders private key assuming that sender’s public key is shared with the receiver. In our example, Bob uses his own private key to generate the signature.

Sign and Encrypt Messages
Sign and Encrypt Messages

Process Flow:

  1. Bob generate Private/Public key pair.
  2. Bob shares the public key to any one and keep the private key secret.
  3. Alice generate Private/Public key pair.
  4. Alice shares the public key to any one and keep the private key secret.
  5. Bob generate signature using his own private key.
  6. Bob encrypt the message along with the signature using Alice’s public key.
  7. Sends the signed message to Alice.
  8. Alice decrypt the message with her private key.
  9. Alice verify the signature with Bob’s public key

Why to use alternate keys?

Here is the trick. Generating the signature using Bob’s private key, ensures that this signature is created by Bob and only by Bob because the private key of Bob is never shared to any one. This guarantee that the message was sent by Bob. On the other hand,  using Alice’s public key to encrypt the message ensures that, only the owner of private key can decrypt the message.

Sign-Then-Encrypt or Encrypt-Then-Sign ?

This is arguable. Yet there are couple of practical differences/use cases with both the methods.

  1. If you Sign-Then-Encrypt, Only the receiver can decrypt and verify the signature.
  2. If you Encrypt-Then-Sign, Anyone can verify and but only the intended recipient can decrypt.

There was a paper with detailed analysis on this topic (Defective Sign & Encrypt in S/MIME, PKCS#7, MOSS, PEM, PGP and XML). This has a bit different suggestion “Sign then Encrypt then Sign” which can force more security and integrity over the message. You can read it for further exploration.

As for the asymmetric cryptography, to have the enough security and integrity, I recommend Sign-Then-Encrypt. From security perspective, you are not consuming “Vulnerable” date during decryption.

Hope to provide some example how can we do this in coming series.

Leave a Reply

Your email address will not be published. Required fields are marked *


Please wrap all source codes with [code][/code] tags.

This site uses Akismet to reduce spam. Learn how your comment data is processed.