Cryptography in Asp.net


Introduction:

 

Generally we use Authentication and Authorization for security in our applications. But what we have to do if we want to transfer data from one place to another place with security, there comes the use of Cryptography.

 

What is Cryptography?

 

The discipline which embodies principles, means and methods for the transformation of data in order to hide its information content, prevent its undetected modification, or prevent its unauthorized use.

In the other word, the conversion of data into a secret code for protection of privacy using a specific algorithm and a secret key. The original text, or "plaintext", is converted into a coded equivalent called "ciphertext" via an encryption algorithm. The ciphertext can only be decoded (decrypted) using a predefined secret key.

 

Why Cryptography?

 

If you want to send Data to your friend over a network, which is highly confidential, there is no guarantee that the data you are sending will reach to him correctly. Some third persons may modify that information. So to transmit data over networks we can use Cryptography. .Net framework contains several classes to work with cryptography in your application. To use cryptography in your applications you have to add the following namespace as reference


Using System.Security.Cryptography;

 

Cryptography provides the following features:

  • Prevents Data being transferred from reading by unknown persons and third parties.
  • Prevents Data being transferred from unknown modifications.
  • Makes sure that data is coming from the proposed location.

Types of Cryptography:

 

Cryptography is several types. We can use cryptography in our applications in the following ways:

  1. Symmetric Cryptography
  2. Asymmetric Cryptography
  3. Digital Signatures
  4. Hashing

Let us about each type of Cryptography

 

Symmetric Cryptography:

 

It is also called as Secret Key Encryption since the data is encrypted using a single "Secret Key". This key is known only to sender and receiver of data. At first sender encrypts the data with the secret key and the receiver decrypts the data send by the sender with the same Key. Both the sender and receiver must be care about the key; they must keep the key in secret otherwise third parties can also decrypt the data if they know the key.

 

Asymmetric Cryptography:

 

This Encryption is different form Symmetric Encryption since it uses two keys

  1. Public Key
  2. Private Key

The public key is not maintained secret where all private keys are kept secret and confidential by the owner of the key.

 

If the data encrypted by the private key should be decrypted by the public key and if the data encrypted by the public key should be decrypted by the Private key only.

Generally to transmit the data you have to encrypt it with public key and this data can be decrypted only with corresponding private key.

Hence this Encryption also called as Public Key Encryption.

 

Digital Signatures:

 

Digital signatures utilize public key cryptography and one-way hash functions to produce a signature of the data that can be authenticated, and is difficult to forge or repudiate.

Digital Signatures are used to verify and identity of the sender and ensure data integrity. Generally they are used with Asymmetric Key Encryption (Public key Encryption)

A block of data attached to a message that serves to "digitally sign" the message; it is transmitted along with the message to a recipient. The purpose of the digital signature is to identify the sender, verify the message has not been altered in transit, and provide support for no repudiation. It is a two-step cryptographic process: first, the message to be transmitted undergoes a hash algorithm (for example, SHA-1) to obtain a message digest (or hash value).

Digital Signature has three advantages:

 

  • Authenticity
  • Integrity
  • Non-repudiation

Hashing:

 

Hash algorithms create a fixed length output for a given. If any one changes the original data even a bit then the hash generated will be different from the original hash. Hash algorithms are generally used in Digital Signatures.

The .Net Framework contains several method and classes to implement the above-specified type of encryption in System.Security.Cryptography.


Similar Articles