zoukankan      html  css  js  c++  java
  • 加密解密

    //加密

    public static string GDEncode(string data, string Key) 
    {
    Key = "12345678";
    byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(Key);
    byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(Key);
    DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
    int i = cryptoProvider.KeySize;
    MemoryStream ms = new MemoryStream();
    CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write);
    StreamWriter sw = new StreamWriter(cst);
    sw.Write(data);
    sw.Flush();
    cst.FlushFinalBlock();
    sw.Flush();
    return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);
    }

    //解密

    public static string GJDecode(string data, string Key) 
    {
    Key = "12345678";
    byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(Key);
    byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(Key);
    byte[] byEnc;
    try
    {
    byEnc = Convert.FromBase64String(data);
    }
    catch
    {
    return data;
    }
    DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
    MemoryStream ms = new MemoryStream(byEnc);
    CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read);
    StreamReader sr = new StreamReader(cst);
    String str;
    str = sr.ReadToEnd();
    if (str.Trim() == "") str = data;
    return str;
    }

  • 相关阅读:
    day3 程序流程控制
    day2 程序流程控制
    String.prototype.formatWith
    未能找到文件“in oslyncsc.exe”
    Azure DocumentDB
    查询表中所有字段的最大长度(大数据情况)
    查询表中所有字段的最大长度
    linux开发
    sql server cvs 导入
    清除“远程桌面连接”的历史记录
  • 原文地址:https://www.cnblogs.com/Dreamer-HJ/p/11904483.html
Copyright © 2011-2022 走看看