控件操作类文件的部分手写代码[1]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

using System;
using System.Web.Security;
using System.Text;
using System.IO;
using System.Security.Cryptography;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Web.Mail;
using System.Configuration;

using System.ComponentModel;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
namespace MY
{
 /// <summary>
 /// UserClass 的摘要说明。
 /// </summary>
 public class UserClass:System.Web.UI.Page
 {
  private string[] userdata;
  private string[] managerdata;

  private string strOutPicName;
  private DbControl db;
  protected Page page = null;
  //private Hashtable ht;

  public UserClass()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   // 
   
  }
  public UserClass(Page page)
  {
   db = new DbControl();
   this.page = page;
   strOutPicName = "";
  }
  #region 加密方法
  /// <summary>
  /// 加密
  /// </summary>
  /// <param name="pToEncrypt"></param>
  /// <returns></returns>
  public  string  Encrypt(string  pToEncrypt) 
  { 
   string sKey="1234abcd";
   DESCryptoServiceProvider  des  =  new  DESCryptoServiceProvider(); 
   //把字符串放到byte数组中 
   //原来使用的UTF8编码,我改成Unicode编码了,不行 
   byte[]  inputByteArray  =  Encoding.Default.GetBytes(pToEncrypt); 
   //byte[]  inputByteArray=Encoding.Unicode.GetBytes(pToEncrypt); 

   //建立加密对象的密钥和偏移量 
   //原文使用ASCIIEncoding.ASCII方法的GetBytes方法 
   //使得输入密码必须输入英文文本 
   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);
   //Write  the  byte  array  into  the  crypto  stream 
   //(It  will  end  up  in  the  memory  stream) 
   cs.Write(inputByteArray,  0,  inputByteArray.Length); 
   cs.FlushFinalBlock(); 
   //Get  the  data  back  from  the  memory  stream,  and  into  a  string 
   StringBuilder  ret  =  new  StringBuilder(); 
   foreach(byte  b  in  ms.ToArray()) 
   { 
    //Format  as  hex 
    ret.AppendFormat("{0:X2}",  b); 
   } 
   ret.ToString(); 
   return  ret.ToString(); 
  }
  public    string  Decrypt(string  pToDecrypt) 
  { 
   string sKey="1234abcd";
   DESCryptoServiceProvider  des  =  new  DESCryptoServiceProvider(); 

   //Put  the  input  string  into  the  byte  array 
   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; 
   } 

本文关键:控件操作类文件的部分手写代码
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top