What is Cryptography?
Cryptography is the process of hiding or coding information so that only the person a message was intended for can read it. The art of cryptography has been used to code messages for thousands of years and continues to be used in bank cards, computer passwords, and ecommerce.
Types of Cryptography:
Cryptography is classified into two categories based on the types of keys and encryption algorithms:
- Symmetric Key Cryptography (Secret key)
- Asymmetric Key Cryptography (Public key)
History of Cryptography:
The history of cryptography finds its roots in Egypt around 4000 years ago. The Egyptians used hieroglyphics, the oldest cryptography technique, to communicate with each other. Later, in 500 BC, the technique was modified by replacing the characters with alphabets based on some secret rule known to only a few. This rule came to be known as the key to decipher hidden codes or messages.
Later, in the 15th century, more sophisticated techniques evolved such as Vigenere cipher and coding machines like the Enigma rotor machine. Years later, cryptography was born!
Cryptography Techniques:
ENCRYPTION
Encryption is a process which transforms the original information into an unrecognizable form. This new form of the message is entirely different from the original message. That’s why a hacker is not able to read the data as senders use an encryption algorithm. Encryption is usually done using key algorithms.
DECRYPTION
Decryption is a process of converting encoded/encrypted data in a form that is readable and understood by a human or a computer. This method is performed by un-encrypting the text manually or by using keys used to encrypt the original data.
Example of Cryptography Techniques:
How to use Cryptography Techniques in c#?
Form Design:
using System;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography; // Added this namespace for cryptography classes
namespace Cryptography
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string hash = "f0xle@rn";
private void btnEncrypt_Click(object sender, EventArgs e)
{
byte[] data = Encoding.UTF8.GetBytes(txtValue.Text);
using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()) // Fixed the MD5CryptoServiceProvider
{
byte[] keys = md5.ComputeHash(Encoding.UTF8.GetBytes(hash));
using (TripleDESCryptoServiceProvider tripDes = new TripleDESCryptoServiceProvider()
{
Key = keys,
Mode = CipherMode.ECB,
Padding = PaddingMode.PKCS7
})
{
ICryptoTransform transform = tripDes.CreateEncryptor();
byte[] results = transform.TransformFinalBlock(data, 0, data.Length);
txtEncrypt.Text = Convert.ToBase64String(results, 0, results.Length);
}
}
}
private void btnDecrypt_Click(object sender, EventArgs e)
{
byte[] data = Convert.FromBase64String(txtEncrypt.Text);
using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()) // Fixed the MD5CryptoServiceProvider
{
byte[] keys = md5.ComputeHash(Encoding.UTF8.GetBytes(hash));
using (TripleDESCryptoServiceProvider tripDes = new TripleDESCryptoServiceProvider()
{
Key = keys,
Mode = CipherMode.ECB,
Padding = PaddingMode.PKCS7
})
{
ICryptoTransform transform = tripDes.CreateDecryptor();
byte[] results = transform.TransformFinalBlock(data, 0, data.Length);
txtDecrypt.Text = UTF8Encoding.UTF8.GetString(results);
}
}
}
}
}
Output :
No comments:
Post a Comment