Introduction to Symmetric and Asymmetric Encryption
suggest changeYou can improve the security of data in transit or in storage by encrypting it. System.Security.Cryptography has two approaches: symmetric and asymmetric.
Symmetric Encryption
This method uses a private key in order to perform the data transformation.
Pros:
- Symmetric algorithms consume fewer resources and are faster than asymmetric ones.
- The amount of data you can encrypt is unlimited.
Cons:
- Encryption and decryption use the same key. Someone will be able to decrypt your data if the key is compromised.
- You could end up with many different secret keys to manage if you choose to use a different secret key for different data.
Under System.Security.Cryptography you have different classes that perform symmetric encryption, they are known as block ciphers:
- AesManaged (AES algorithm).
- AesCryptoServiceProvider (AES algorithm FIPS 140-2 compliant).
- DESCryptoServiceProvider (DES algorithm).
- RC2CryptoServiceProvider (Rivest Cipher 2 algorithm).
- RijndaelManaged (AES algorithm). Note: RijndaelManaged is not FIPS-197 compliant.
- TripleDES (TripleDES algorithm).
Asymmetric Encryption
This method uses a combination of public and private keys in order to perform the data transformation.
Pros:
- It uses larger keys than symmetric algorithms, so those keys are harder to guess by brute force.
- It is easier to guarantee who is able to encrypt and decrypt the data because it relies on two keys (public and private).
Cons:
- There is a limit on the amount of data that you can encrypt. The limit is different for each algorithm and is typically proportional to the key size. An
RSACryptoServiceProviderwith a 1,024-bit key can encrypt at most 117 bytes with PKCS#1 v1.5 padding (128 minus 11), and less with OAEP. - Asymmetric algorithms are very slow in comparison to symmetric algorithms.
Under System.Security.Cryptography you have access to different classes that perform asymmetric encryption:
- DSACryptoServiceProvider (Digital Signature Algorithm). This signs data. It does not encrypt it.
- RSACryptoServiceProvider (RSA Algorithm algorithm)
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents