blogjava's web log

          blogjava's web log
          ...

          一對加密解密類[導入]

          public ??? string ??Encrypt( string ??pToEncrypt,?? string ??sKey)??
          ????????
          {??
          ????????????DESCryptoServiceProvider??des??
          = ?? new ??DESCryptoServiceProvider();??
          ????????????
          byte []??inputByteArray?? = ??Encoding.Default.GetBytes(pToEncrypt);???
          ????????????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())??
          ????????????
          {??
          ????????????????
          // Format??as??hex??
          ????????????????ret.AppendFormat( " {0:X2} " ,??b);??
          ????????????}
          ??
          ????????????ret.ToString();??
          ????????????
          return ??ret.ToString();??
          ????????}
          ??
          ????????
          /* *****************************************************************
          ?????????*?密碼解密
          ?????????*?*****************************************************************
          */

          ????????
          public ?? string ??Decrypt( string ??pToDecrypt,?? string ??sKey)??
          ????????
          {??
          ????????????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;??
          ????????????}
          ??
          ????????????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();?????????????
          ????????????StringBuilder??ret??
          = ?? new ??StringBuilder();??
          ?????????????
          ????????????
          return ??System.Text.Encoding.Default.GetString(ms.ToArray());??
          ????????}

          posted on 2006-05-28 14:45 record java and net 閱讀(336) 評論(0)  編輯  收藏 所屬分類: dot net相關

          導航

          常用鏈接

          留言簿(44)

          新聞檔案

          2.動態語言

          3.工具箱

          9.文檔教程

          友情鏈接

          搜索

          最新評論

          主站蜘蛛池模板: 肃宁县| 龙南县| 通江县| 神农架林区| 遵义县| 红原县| 东光县| 通化市| 曲沃县| 行唐县| SHOW| 莎车县| 遂溪县| 扬州市| 延川县| 鲁山县| 镇坪县| 平阳县| 石河子市| 新昌县| 伊宁市| 保德县| 建宁县| 白朗县| 游戏| 光泽县| 兴国县| 鲁山县| 德化县| 滨州市| 三门峡市| 鲁甸县| 贺兰县| 金塔县| 乌苏市| 梁平县| 新兴县| 土默特左旗| 松原市| 保山市| 满洲里市|