In Brief: Signing vs Encryption
The difference between signing and encryption was a problem that me and a colleague were faced with recently. Although I have some education in cryptography, it is not something I use on a day-to-day so my colleague and I were running around in circles for a while before figuring it out. Here is a distillation of what we needed to know.
Let’s keep it brief.
Symmetric vs Asymmetric Encryption
Symmetric encryption uses one private key, that is shared between parties. Any messages sent between two parties is encrypted and decrypted using this private key with one of the following algorithms: AES, Salsa20-ChaCha20, Twofish, Blowfish (don’t use this one), DES, (or this one).
Asymmetric encryption uses two keys, a public and a private one. The public key is usually shared, but the private is a secret to everyone except its owner. Messages are encrypted with a public key and decrypted with the corresponding private key. Algorithms for this type of encryption are: RSA, ECC, Diffie-Hellman.
Please note that your choice of encryption algorithm depends on your use case.
How does it work?
Symmetric Encryption
TODO: Insert diagram of symmetric cryptography
Pretty simple. Alice wants to send Bob a secure message. After exchanging the secret key through secure channels (its own topic), Alice uses an algorithm to encrypt(plaintext, secret_key)
the message and send it to Bob.
Bob then uses the same algorithm to decrypt(message, secret_key)
. He can the read the original, un-encrypted message.
Asymmetric Encryption
TODO: Insert diagram of asymmetric cryptography
Same scenario, Alice wants to send Bob a secure message. However, with asymmetric cryptography, Alice and Bob don’t need to worry about switching briefcases to exchange their secret key. Bob has a publicly available key that anyone can use to encrypt a message and send it to him. Alice does exactly that (encrypt(plaintext, bobs_public_key)
) and sends it.
Now Bob, and only Bob, has the ability to decrypt this message, since he is using his private key to do so. (decrypt(message, bobs_private_key)
).
Signing
So now Alice can send Bob secure messages, but how can Bob be sure that Alice is really the one sending them?
What if this happened?
Eve: Hey Bob, I’m leaving the book club because I hate you. - Alice
Bob would be devastated.
How can Alice and Bob avoid bad actors, like Eve? There’s a simple solution, Under an asymmetric encryption system, Alice can sign the message with her private key. Bob will have her public key and can easily decrypt the signature (usually a hash()
of the contents) to verify that it looks right (matches his own hash()
of the message**, and truly did come from Alice.
Since signing involves the private key of the sender, Alice, it can even be used without encryption to simply verify the identity of the sender.
Happy together!
Under an asymmetric encryption system:
Encryption: Only intended recipients can read the message
Signing: The sender is who they say they are
Both of these seem advantageous, so let’s look at a flow where both are used to securely transmit messages between Alice and Bob.
TODO: Create diagram of signing and encryption flow
We’ll use (S) to denote operations for signing and (E) for operations denoting encryption/decryption.
- Given
plaintext
(Alice’s message) - Alice (S):
h = hash(plaintext)
- Alice (S):
sign = encrypt(h, alices_private_key)
- Alice (E):
message = ({plaintext, sign}, bobs_public_key)
- Alice sends
message
- Bob (E):
plaintext, sign = decrypt(message, bobs_private_key)
- Bob (S):
h = hash(plaintext)
- Bob (S):
assert(h == decrypt(sign, alices_public_key))
Summary
Cryptography is a broad, mathematical domain. This article was intended to briefly answer the question “What is the difference between signing and encryption?”. If you found this distillation of cryptographic ideas helpful, I’m glad. If you found it interesting, please browse through the links below.