How we Decrypt the text File using DES method.
1. Open visual studio and create a project
2. Add the following assembly on the page
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.IO;
3. Now write the code in the Page
public class Tester
{
public static void Main()
{
try
{
DESCryptoServiceProvider myDESProvider = new DESCryptoServiceProvider();
myDESProvider.Key = ASCIIEncoding.ASCII.GetBytes("12345678");
myDESProvider.IV = ASCIIEncoding.ASCII.GetBytes("12345678");
FileStream DecryptedFile = new FileStream("testDes.txt", FileMode.Open, FileAccess.Read);
ICryptoTransform myICryptoTransform = myDESProvider.CreateDecryptor(myDESProvider.Key, myDESProvider.IV);
CryptoStream myCryptoStream = new CryptoStream(DecryptedFile, myICryptoTransform, CryptoStreamMode.Read);
StreamReader myDecStreamReader = new StreamReader(myCryptoStream);
StreamWriter myDecStreamWriter = new StreamWriter("p1.txt");
myDecStreamWriter.Write(myDecStreamReader.ReadToEnd());
myCryptoStream.Close();
myDecStreamReader.Close();
myDecStreamWriter.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
4. Now convert the encrypted text file in the folder D:\New Folder (2)\ConsoleApplication4\ConsoleApplication4\bin\Debug (My text file path) to decrypted text file.
Now start debugging, you will see a testDes.txt file automatically converted into p1.text Decrypted text file.
No comments:
Post a Comment