t-by的net blog

学习net的资料库

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

// 这个加密类是用了.net的System.Web.Security类的,因为是标准的,md5跟SHA码,这里有个问题,java输出不一定是16或32位数.

using System;
using System.Web.Security;

namespace common
{
 /// <summary>
 /// common 的摘要说明。
 /// </summary>
 public class common
 {
  public common()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
  
 }

 #region 公用加密类
 public class EncryptPwd

 {

  public string md5(string str,int code) // md5加密函数
  {

   if(code==16)
   {
    return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str,"MD5").ToLower().Substring(8,16) ;
   }

   if(code==32)
   {
    return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str,"MD5");
   }

   return "00000000000000000000000000000000";
  }


  public string sha1(string str)  // SHA加密函数
  {
   return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str ,"SHA1");
  }

 }
 #endregion
}

posted on 2005-12-20 22:29  钛网络  阅读(315)  评论(0)    收藏  举报