Encryption is the process of translating plain text data (plaintext) into something that appears to be random and meaningless (ciphertext).It is used to transform a data into some un-readable form so that authenticated person only can read/access the data. It requires some secret information to transform the plain text to cipher text; it is usually referred as key.

Decryption is the process of converting ciphertext back to plaintext. To encrypt more than a small amount of data, symmetric encryption is used.

There are many modern cryptographic methods used for encryption and decryption and it is classified in to two classes of key based algorithms.

Symmetric Algorithm

Same key is used for both Encryption and Decryption. The key will be kept as secret.

Symmetric Ciphers is divided into Stream and Block Ciphers.

Stream Ciphers – It encrypts a single bit of plain text at a time.

Block Ciphers – It takes number of bits and encrypts them as a single unit.

Asymmetric Algorithm

Different key is used for Encryption and Decryption. It is also called as public Key algorithm.

Encryption key is public and the Decryption key will be kept as secret.

By using this asymmetric algorithm, anyone can encrypt the message by using encryption key but the message can be decrypted only by using decryption key.

Hybrid Encryption – Symmetric and Asymmetric algorithm are used together and it is called as Hybrid Encryption.

Passed Text = This is my password to protect
EncryptedText = m7YCTb0Q6yCUmAFVYg+hYuauJkvxmrJtXGZfzSUk6/A=
DecryptedText = This is my password to protect

That's it we are done with the above method.

C# Encrypt Password using MD5 example

MD5 is also considered one of the best ways to save password, but in this method we would not be able to decrypt it, Md5() is one way function,means you can Encrypt Something but after that you can not decrypt it, so using it means when we save Encrypted string or password in database we save encryption key also somewhere in database or in Code.

So when user enters password in Login page then we re-calculate MD5 & we need to match the newly created MD5 encrypted string with the saved one in database, it if matches , user has entered correct password show home-page to it.

Which algorithm to use for encrypting password?

After checking above algorithms, you may think which one we should use for password encryption.

MD5 and SHA are not encryption algorithms, and it is important that you understand the difference. They are digest or signature algorithms; they take an input string of arbitrary size and produce a fixed-length result. Each MD5 result maps to multiple different input strings. These are strictly one-way operations -- there is no way to "undo" an MD5 or SHA hash to find the original text.

If you want a digest algorithm, then MD5 is OK and SHA is better. If you really do want encryption that can be decrypted, then you need something like AES or RSA.