This is a mirror of official site: http://jasper-net.blogspot.com/

Encrypt a File using DES (Data Encryption standard) Algorithm in ASP.NET

| Wednesday, August 18, 2010
Security in cryptography

Cryptography play important role in Security. Using Cryptography we can Encrypt and Decrypt the information in the Coded form.

How we Encrypt the File using DES (Data Encryption standard) algorithm.

1.Open visual studio and create a project

2.Add the following assembly on the page

using Microsoft.VisualBasic;
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");
           ICryptoTransform myICryptoTransform = myDESProvider.CreateEncryptor(myDESProvider.Key, myDESProvider.IV);
           FileStream ProcessFileStream = new FileStream("test.txt", FileMode.Open, FileAccess.Read);
           FileStream ResultFileStream = new FileStream("testDes.txt", FileMode.Create, FileAccess.Write);
           CryptoStream myCryptoStream = new CryptoStream(ResultFileStream, myICryptoTransform, CryptoStreamMode.Write);
            byte[] bytearrayinput = new byte[ProcessFileStream.Length];
            ProcessFileStream.Read(bytearrayinput, 0, bytearrayinput.Length);
           myCryptoStream.Write(bytearrayinput, 0, bytearrayinput.Length);
            myCryptoStream.Close();
           ProcessFileStream.Close();
           ResultFileStream.Close();
       }
       catch (Exception ex)
       {
           Console.WriteLine(ex.Message);
       }
   }

Read more: C# Corener

Posted via email from .NET Info

1 comments:

Anonymous said...

Thank you for some other excellent post. The place
else may anyone get that type of info in such a perfect manner of writing?
I have a presentation next week, and I'm on the search for such information.

Have a look at my blog post :: Highly recommended Internet site