Cryptography: Types of Encryption-Decryption

30 May 2020 — Written by Bharat
#notes

1. Symmetric Encryption-Decryption

Here, a common key K is generated using the key-generation function, and using this key:

encrypt(plainText, K) -> cipherText
decrypt(cipherText, K) -> plainText

Features:

  • plainText cannot be derived from cipherText without knowing the key.

Pros:

  • Fast execution (comparatively - even for large plainText).

Cons:

  • Key has to be shared securely somehow (between sender and receiver), which is not a trivial problem.

2. Asymmetric Encryption-Decryption

Here, a pair of keys (publicKey + privateKey) is generated using the key-generation function, and using this pair:

encrypt(plainText, publicKey) -> cipherText
decrypt(cipherText, privateKey) -> plainText

Here, publicKey (as the name suggests) can be shared freely/openly (like over the internet).

Features:

  • plainText cannot be derived from cipherText without knowing the privateKey.

Pros:

  • Key can be shared easily.

Cons:

  • Slow execution (comparatively - for large plainText).

3. Hybrid Encryption-Decryption

Combines both:

  • benefit of open publicKey from Asymmetric method, and
  • benefit of fast execution from Symmetric method

How it works:

  1. For large plainText, sender would generate a Symmetric Key K using which he would encrypt the plainText to cipherText (Symmetric encryption).
  2. But to communicate this key K securely, he’ll decrypt the small key K using Asymmetric method (which should be fast enough for small payload of this key K) using the publicKey of the receiver (Asymmetric Encryption).
  3. cipherText can only be decrypted via key K, while this key can only be decrypted by the privateKey.
  4. Now, the public Key is known, and the cipherText is known, and both can be openly transferred.
  5. Receiver will use his privateKey to decrypt the key K (Asymmetric decryption), and using this key, he’ll decrypt the cipherText to plainText (Symmetric decryption).
  6. Thus, we used Asymmetric method to encrypt small message (key K) (which should be fast since payload is small), and transfer it along with cipherText which can be decrypted using that key using Symmetric method (which should be fast since it uses Symmetric method).

Visualisation:

Sender {
	symmetricEncrypt(myLongSecretMsg, K) -> xxgibberishxx
	asymmetricEncrypt(K, ReceiversPublicK) -> akak
}

Transfer(xxgibberishxx, akak) // from Sender to Receiver

Receiver {
	decryptAsymmetric(akak, ReceiverPrivateK) -> K
	decryptSymmetric(xxgibberishxx, K) -> myLongSecretMsg
}