.net里倒是有加密的函数,可是必须要求你把所要加密的内容读到内存中,加密之后再写回去。
在你的浏览器或.netSDK帮助中输入一下地址:
ms-help://MS.NETFrameworkSDK.CHS/cpguidenf/html/cpconcryptographicservices.htm

解决方案 »

  1.   

    .net里倒是有加密的函数,可是必须要求你把所要加密的内容读到内存中,加密之后再写回去。
    在你的浏览器或.netSDK帮助中输入一下地址:
    ms-help://MS.NETFrameworkSDK.CHS/cpguidenf/html/cpconcryptographicservices.htm
      

  2.   

    .net里倒是有加密的函数,可是必须要求你把所要加密的内容读到内存中,加密之后再写回去。
    在你的浏览器或.netSDK帮助中输入一下地址:
    ms-help://MS.NETFrameworkSDK.CHS/cpguidenf/html/cpconcryptographicservices.htm
      

  3.   

    什么函数,你能给我写出来吗?要知道,我这个文本文件(XML)比较大阿。
      

  4.   


    例子....hoho,忘记是那个人写的了,不好意思了那个人...
    也许有点帮组把.....using System.Security.Cryptography
    public string crypString(string s)
    {
    FileStream fs = new FileStream("EncryptedFile.txt",FileMode.Create,FileAccess.Write);
    byte[] bytearrayinput = (new UnicodeEncoding()).GetBytes(s);
    DESCryptoServiceProvider des = new DESCryptoServiceProvider();
    ICryptoTransform desencrypt = des.CreateEncryptor();
    CryptoStream cryptostream = new CryptoStream(fs,desencrypt,CryptoStreamMode.Write);
    cryptostream.Write(bytearrayinput,0,bytearrayinput.Length);
    cryptostream.Close();
    //加密结束,下面是解密
    FileStream fsread = new FileStream("EncryptedFile.txt",FileMode.Open,FileAccess.Read);
    ICryptoTransform desdecrypt = des.CreateDecryptor();
    CryptoStream cryptostreamDecr = new CryptoStream(fsread,desdecrypt,CryptoStreamMode.Read);
    //返回的是已经解密的字符串
    return (new StreamReader(cryptostreamDecr, new UnicodeEncoding())).ReadToEnd();
    }//如果你想直接返回加密的字符串,看下面的方法
    public string crypString(string s)
    {
    FileStream fs = new FileStream("EncryptedFile.txt",FileMode.Create,FileAccess.ReadWrite);
    byte[] bytearrayinput = (new UnicodeEncoding()).GetBytes(s);
    DESCryptoServiceProvider des = new DESCryptoServiceProvider();
    ICryptoTransform desencrypt = des.CreateEncryptor();
    CryptoStream cryptostream = new CryptoStream(fs,desencrypt,CryptoStreamMode.Read);
    string returnValue = (new StreamReader(cryptostream, new UnicodeEncoding())).ReadToEnd();
    cryptostream.Close();
    return returnValue;
    }