u013628742
西裤大师兄
2016-07-26 07:28
采纳率: 100%
浏览 1.2k
已采纳

asp.net DES加密解密怎么弄

public string DecrytFun(string custData)
{
byte[] key = Encoding.ASCII.GetBytes("201206==");
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(custData));
CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateDecryptor(key, key), CryptoStreamMode.Read);
StreamReader reader = new StreamReader(cryptoStream);
return reader.ReadToEnd();
}

怎么把他写成exe的,并且在本程序目录执行的时候,1.txt是密文,每行一个,解密后输出到2.txt里面,最好能私信发个QQ或者联系方式,方便发代码。在线等。。。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • showbo
    已采纳

    xxx.aspx

    
    <%@ Page Language="C#" EnableSessionState="True" %>
    <%@ Import Namespace="System.IO" %>
    <%@ Import Namespace="System.Web.Security" %>
    <%@ Import Namespace="System.Security.Cryptography" %>
    <script runat="server">
        public string DecrytFun(string custData)
        {
            byte[] key = Encoding.ASCII.GetBytes("201206==");
            DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
            MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(custData));
            CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateDecryptor(key, key), CryptoStreamMode.Read);
            StreamReader reader = new StreamReader(cryptoStream);
            return reader.ReadToEnd();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="source">要解密的文件路径</param>
        /// <param name="target">解密后保存的文件路径</param>
        public void DecryFile(string source, string target)
        {
            string s = File.ReadAllText(source);
            string[] arr = s.Replace("\r", "").Split('\n');
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            foreach (string _s in arr) if (_s.Trim() != "") sb.Append(DecrytFun(_s) + "\r\n");
            File.WriteAllText(target, sb.ToString().TrimEnd());
        }
        protected void Page_Load(Object sender, EventArgs args)
        {
            string source = Server.MapPath("1.txt"), target = Server.MapPath("2.txt");
            DecryFile(source, target);
            Response.Redirect("2.txt");
        }
    </script>
    
    点赞 评论

相关推荐