一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

一個(gè).Net加密解密類-程序開(kāi)發(fā)-紅黑聯(lián)盟

 大卷風(fēng) 2010-10-06
一個(gè).Net加密解密類
文章錄入:7747.Net    責(zé)任編輯:7747.Net  58

【字體:

using System;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CommHelper
{
 public class CEntrypt
 {
  private static string sKeyForEncryptTitle;

  public CEntrypt()
  { }

  #region 解密Base64
  /// <summary>
  /// 解密Base64
  /// </summary>
  /// <param name="asContent"></param>
  /// <returns></returns>
  public static string Base64TextUTF8Decode(string asContent)
  {
   try
   {
    byte[] bytes = Convert.FromBase64String(asContent);
    UTF8Encoding encoding = new UTF8Encoding();
    return encoding.GetString(bytes);
   }
   catch
   {
    return "";
   }
  }
  #endregion

  #region 加密Base64
  /// <summary>
  /// 加密Base64
  /// </summary>
  /// <param name="asText"></param>
  /// <returns></returns>
  public static string Base64UTF8Encode(string asText)
  {
   try
   {
    string s = asText;
    UTF8Encoding encoding = new UTF8Encoding();
    return Convert.ToBase64String(encoding.GetBytes(s));
   }
   catch
   {
    return "";
   }
  }
  #endregion

  #region  解密UTF8
  /// <summary>
  /// 解密UTF8
  /// </summary>
  /// <param name="asEnCodeText"></param>
  /// <returns></returns>
  public static string DecodeUTF8Text(string asEnCodeText)
  {
   try
   {
    byte[] bytes = Convert.FromBase64String(asEnCodeText);
    UTF8Encoding encoding = new UTF8Encoding();
    return encoding.GetString(bytes);
   }
   catch
   {
    return "";
   }
  }
  #endregion

  #region static 加密UTF8
  /// <summary>
  /// 加密UTF8
  /// </summary>
  /// <param name="asDecodeText"></param>
  /// <returns></returns>
  public string EnCodeUTF8Text(string asDecodeText)
  {
   try
   {
    UTF8Encoding encoding = new UTF8Encoding();
    return Convert.ToBase64String(encoding.GetBytes(asDecodeText));
   }
   catch
   {
    return "";
   }
  }
  #endregion

  #region EncryptHelper加密

  /// <summary>
  /// 加密
  /// </summary>
  /// <param name="Text"></param>
  /// <returns></returns>
  public static string Encrypt(string Text)
  {
   return Encrypt(Text, "EncryptHelper");
  }
  /// <summary>
  /// 加密數(shù)據(jù)
  /// </summary>
  /// <param name="Text"></param>
  /// <param name="sKey"></param>
  /// <returns></returns>
  public static string Encrypt(string Text, string sKey)
  {
   DESCryptoServiceProvider des = new DESCryptoServiceProvider();
   byte[] inputByteArray;
   inputByteArray = Encoding.Default.GetBytes(Text);
   des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
   des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
   System.IO.MemoryStream ms = new System.IO.MemoryStream();
   CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
   cs.Write(inputByteArray, 0, inputByteArray.Length);
   cs.FlushFinalBlock();
   StringBuilder ret = new StringBuilder();
   foreach (byte b in ms.ToArray())
   {
    ret.AppendFormat("{0:X2}", b);
   }
   return ret.ToString();
  }

  #endregion

  #region EncryptHelper解密


  /// <summary>
  /// 解密
  /// </summary>
  /// <param name="Text"></param>
  /// <returns></returns>
  public static string Decrypt(string Text)
  {
   return Decrypt(Text, "EncryptHelper");
  }
  /// <summary>
  /// 解密數(shù)據(jù)
  /// </summary>
  /// <param name="Text"></param>
  /// <param name="sKey"></param>
  /// <returns></returns>
  public static string Decrypt(string Text, string sKey)
  {
   DESCryptoServiceProvider des = new DESCryptoServiceProvider();
   int len;
   len = Text.Length / 2;
   byte[] inputByteArray = new byte[len];
   int x, i;
   for (x = 0; x < len; x++)
   {
    i = Convert.ToInt32(Text.Substring(x * 2, 2), 16);
    inputByteArray[x] = (byte)i;
   }
   des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
   des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
   System.IO.MemoryStream ms = new System.IO.MemoryStream();
   CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
   cs.Write(inputByteArray, 0, inputByteArray.Length);
   cs.FlushFinalBlock();
   return Encoding.Default.GetString(ms.ToArray());
  }

  #endregion

  #region DeCodeID 解密
  public static string DecodeID(string Encode)
  {
   if (Encode == "")
   {
    return "";
   }
   int length = Encode.Length;
   if (length < 5)
   {
    return "";
   }
   int num2 = Convert.ToInt32(Encode.Substring(2, 1));
   int num3 = Convert.ToInt32(Encode.Substring(4, 1));
   int startIndex = ((num2 * 2) + (num3 * 2)) + 7;
   if (length < (startIndex + 20))
   {
    return "";
   }
   num2 = (Convert.ToInt32(Encode.Substring(startIndex, 1)) * 10) + Convert.ToInt32(Encode.Substring(startIndex + 1, 1));
   startIndex = (startIndex + 2) - 1;
   string str = "";
   for (int i = 0; i < num2; i++)
   {
    startIndex = (startIndex + 3) + 1;
    str = str + Encode.Substring(startIndex, 1);
   }
   return str;
  }
  #endregion

  #region EncodeID 加密
  public static string EncodeID(string ID)
  {
   int num6;
   int num = (DateTime.Now.Hour * DateTime.Now.Minute) * DateTime.Now.Second;
   if (num < 100)
   {
    num = (num + 0x70) * 0x25;
   }
   string str = "";
   for (num6 = 1; num6 < 100; num6++)
   {
    int num2 = num * (num6 % 50);
    str = str + num2.ToString().Trim();
    if (str.Length > 120)
    {
     break;
    }
   }
   int num3 = Convert.ToInt32(str.Substring(2, 1));
   int num4 = Convert.ToInt32(str.Substring(4, 1));
   int length = ((num3 * 2) + (num4 * 2)) + 7;
   num3 = ID.Length;
   string str2 = str.Substring(0, length);
   if (num3 < 10)
   {
    str2 = str2 + "0";
   }
   str2 = str2 + num3.ToString().Trim();
   for (num6 = 0; num6 < num3; num6++)
   {
    str2 = str2 + str.Substring(1 + (num6 * 3), 3) + ID.Substring(num6, 1);
   }
   num3 = str2.Length;
   try
   {
    str2 = str2 + str.Substring(20, 110 - num3);
   }
   catch
   {
   }
   return str2;
  }
  #endregion

  #region DecodeURL 解密
  public static string DecodeURL(string NameValueStr)
  {
   uint num;
   if ((NameValueStr == null) || (NameValueStr == ""))
   {
    return "";
   }
   string str = NameValueStr.Trim().Replace("X", "1U1").Replace("Y", "2U2").Replace("Z", "3U3").Replace("V", "4U5").Replace("W", "7U6").Replace("O", "8U7").Replace("P", "0U8").Replace("Q", "0U9").Replace("R", "1U0").Replace("S", "2U4").Replace("x", "U1").Replace("y", "U2").Replace("z", "U3").Replace("u", "U4").Replace("v", "U5").Replace("w", "U6").Replace("o", "U7").Replace("p", "U8").Replace("q", "U9").Replace("r", "U0");
   string str2 = "";
   string str3 = "";
   for (int i = 1; i < str.Length; i++)
   {
    if (str[i] == 'U')
    {
     if (str2 != "")
     {
      num = Convert.ToUInt32(str2);
      str3 = str3 + Convert.ToChar(num).ToString().Trim();
      str2 = "";
     }
    }
    else
    {
     char ch2 = str[i];
     str2 = str2 + ch2.ToString().Trim();
    }
   }
   if (str2 != "")
   {
    num = Convert.ToUInt32(str2);
    str3 = str3 + Convert.ToChar(num).ToString().Trim();
   }
   return str3;
  }
  #endregion

  #region EncodeURL 加密
  public static string EncodeURL(string NameValueStr)
  {
   if ((NameValueStr == null) || (NameValueStr == ""))
   {
    return "";
   }
   string str = "";
   NameValueStr = NameValueStr.Trim();
   for (int i = 0; i < NameValueStr.Length; i++)
   {
    str = str + "U" + Convert.ToUInt16(NameValueStr[i]).ToString().Trim();
   }
   return str.Replace("1U1", "X").Replace("2U2", "Y").Replace("3U3", "Z").Replace("4U5", "V").Replace("7U6", "W").Replace("8U7", "O").Replace("0U8", "P").Replace("0U9", "Q").Replace("1U0", "R").Replace("2U4", "S").Replace("U1", "x").Replace("U2", "y").Replace("U3", "z").Replace("U4", "u").Replace("U5", "v").Replace("U6", "w").Replace("U7", "o").Replace("U8", "p").Replace("U9", "q").Replace("U0", "r");
  }
  #endregion
 }
}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多

    色婷婷久久五月中文字幕| 99秋霞在线观看视频| 亚洲视频在线观看免费中文字幕| 亚洲一区二区精品免费| 黄片在线免费观看全集| 91精品国自产拍老熟女露脸| 91亚洲精品综合久久| 亚洲最大的中文字幕在线视频| 国产色偷丝袜麻豆亚洲| 国产av天堂一区二区三区粉嫩 | 国产欧美精品对白性色| 国产精品99一区二区三区| 欧美黑人精品一区二区在线| 亚洲中文字幕在线乱码av| 国产又粗又猛又爽又黄| 久久99国产精品果冻传媒| 亚洲第一视频少妇人妻系列| 久久国产精品亚州精品毛片| 欧美日韩最近中国黄片| 欧美精品久久99九九| 欧美尤物在线视频91| 国产传媒欧美日韩成人精品| 婷婷亚洲综合五月天麻豆| 久久夜色精品国产高清不卡| 亚洲欧美中文日韩综合| 91后入中出内射在线| 日韩中文字幕免费在线视频| 欧美日韩有码一二三区| 丝袜破了有美女肉体免费观看| 亚洲欧美日韩精品永久| 一区二区三区四区亚洲专区| 亚洲香艳网久久五月婷婷| 欧美一区日韩一区日韩一区| 观看日韩精品在线视频| 久久精品国产99精品最新| 亚洲精品国男人在线视频| 日韩成人动画在线观看| 白白操白白在线免费观看| 国产精品一区二区视频大全| 欧美精品在线观看国产| 国产又粗又深又猛又爽又黄|