新建 文本文档 (2)

  • Uploaded by: websterfan
  • 0
  • 0
  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View 新建 文本文档 (2) as PDF for free.

More details

  • Words: 294
  • Pages: 3
2006-10-20 16:26���� Cookies Response.Cookies["askCRM"]["USERID"] = Tools.Encrypt(strUserName.Trim(), Tools.myKey); ���� string strUid = Request.Cookies["askCRM"]["USERID"]; strUid = Tools.Decrypt(strUid, Tools.myKey); ������ ܽ ���õķ��� using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Security.Cryptography; using System.IO; using System.Text; /// <summary> /// Tools �� Ҫ �� /// public class Tools { /// <summary> /// ��ǰ���������ʹ�õ��� /// public static readonly string myKey = "q0m3sd8l"; #region ������ ܷ /// <summary> /// ������ ܷ /// /// <param name="pToEncrypt">��Ҫ�����ַ� /// <param name="sKey">�� /// ������ַ ܺ � public static string Encrypt(string pToEncrypt, string sKey) { try { DESCryptoServiceProvider des = new DESCryptoServiceProvider(); //���ַ�ŵ�byte������

// 4ʹ�õ�UTF8���룬�Ҹij�Unicode�����ˣ����� byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);

//��b��������� ܶ ��ƫ�� //ʹ�����������������Ӣ���õ� des.Key = ASCIIEncoding.ASCII.GetBytes(sKey); des.IV = ASCIIEncoding.ASCII.GetBytes(sKey); MemoryStream ms = new 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); } ret.ToString(); return ret.ToString();

} catch (Exception ex) {

JS.Alert("д��������Ϣʧ�‫���ܣ‬ϸ��Ϣ��" + ex.Message.Replace("\r\n", "").Replace("'", "")); } return ""; } #endregion #region ������ ܷ /// <summary> /// ������ ܷ /// /// <param name="pToDecrypt">��Ҫ�����ַ ܵ � /// <param name="sKey">�� ܳ /// ������ַ ܺ � public static string Decrypt(string pToDecrypt, string sKey) { try { DESCryptoServiceProvider des = new DESCryptoServiceProvider(); byte[] inputByteArray = new byte[pToDecrypt.Length / 2]; for (int x = 0; x < pToDecrypt.Length / 2; x++) { int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16)); inputByteArray[x] = (byte)i; } //��b��������� ܶ ��ƫ�� ����ֵ��Ҫ������� � des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);

des.IV = ASCIIEncoding.ASCII.GetBytes(sKey); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); //��bStringBuild����CreateDecryptʹ�õ������� ���ѽ����� ܺ õ��������� StringBuilder ret = new StringBuilder(); return System.Text.Encoding.Default.GetString(ms.ToArray()); } catch (Exception ex) { JS.Alert("�� ������Ϣʧ�‫���ܣ‬ϸ��Ϣ��" + ex.Message.Replace("\r\n", "").Replace("'", "")); } return ""; } #endregion

Related Documents

Seniorstudio 2(2)(2)
June 2020 80
Seniorstudio 2(2)(2)
June 2020 86
Seniorstudio 2(2)(2)
June 2020 77
2-2
November 2019 81
2-2
May 2020 54
2(2)
April 2020 46

More Documents from ""

April 2020 1
December 2019 4
Generate
December 2019 7