利用异或进行的简单文件加密算法

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;//

namespace DESFileSmart
{
    public class DESFileSmartClass
    {
        /// <summary>
        /// 加/解密文件算法
        /// </summary>
        /// <param name="inFile"></param>
        /// <param name="outFile"></param>
        /// <param name="password"></param>
        public static void DESFile(string inFile, string outFile, int password)
        {
            // 创建打开文件流
            using (FileStream fin = File.OpenRead(inFile), fout = File.OpenWrite(outFile))
            {
                byte[] inData = new byte[fin.Length];
                byte[] outData = new byte[fin.Length];
                fin.Read(inData, 0, inData.Length);
                for (int i = 0; i < inData.Length; i++)
                {
                    int temp = inData[i]^password;
                    outData[i] = (byte)temp;
                }
                fout.Write(outData, 0, outData.Length);
            }
        }
    }
}

posted @ 2011-05-04 13:57  Yao,Mane  阅读(570)  评论(0编辑  收藏  举报