User Tools

Site Tools


notes:csharp:cryptography

Cryptography in C# and .NET

Algorithm Encryption Keys
Rijndael symmetric private/shared
Rivest Shamir Adleman asymmetric public/private
Digital Signature Algorithm asymmetric public/private
Hash Algorithm Description
Secure Hash Algorithm stronger than MD5 against brute force attacks
- SHA1 uses a 160-bit hash size
- SHA256 uses 256 bits
- SHA384 uses 384 bits
- SHA512 uses 512 bits; it is the strongest and the slowest from the SHA algorithms
Message Digest Algorithm 5 faster than SHA; MD5 uses 128-bit hash size
RACE Integrity Primitives Evaluation MD RIPEDM160 uses a 160-bit hash size

The purpose of hash algorithms is to create a fixed-length hash value from binary strings. The hash algorithms are used with digital signatures and for data integrity. If the same binary string is hashed again, the same hash value is returned.

Class Description
RijndaelManaged Implements shared key (symmetric) encryption. The encryption/decription algorithms using symmetric keys are much faster than those using asymmetric keys. The downside is that the keys must be exchanged in a safe manner.
RSACryptoServiceProvider Implements public key (asymmetric) encryption by using the RSA algorithm. With asymmetric encryption, a public key is used to encrypt data but a private key is used to decrypt data. The public key is known to everyone who must be able to encrypt data. The private key is known only to those who should decrypt data.
DSACryptoServiceProvider Implements asymmetric encryption by using the DSA algorithm.
SHA1Managed Computes a unique hash of data using the SHA algorithm. Hashing is a one-way process and hashed data cannot be reversed.

The .NET Framework contains classes for encryption in the namespace System.Security.Cryptography. The classes with a Cng (Cryptography Next Generation) prefix or suffix are newer versions of the native Crypto API. There are a few abstract classes such as MD5, SHA1, or DES. The classes with the suffix CryptoServiceProvider implement the abstract base classes.

Category Abstract Base Class Concrete Classes
Hash MD5 MD5Cng
SHA1 SHA1Managed, SHA1Cng
SHA256 SHA256Managed, SHA256Cng
SHA384 SHA384Managed, SHA384Cng
SHA512 SHA512Managed, SHA512Cng
RIPEMD160 RIPEMD160Managed
Symmetric DES DESCryptoServiceProvider
TripleDES TripleDESCryptoServiceProvider
Aes AesCryptoServiceProvider, AesManaged
RC2 RC2CryptoServiceProvider
Rijandel RijandelManaged
notes/csharp/cryptography.txt · Last modified: 2017/12/13 by leszek