首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Windows Mobile >

Windows Phone怎么实现md5加密

2012-12-15 
Windows Phone如何实现md5加密?我已经添加了using System.Security.Cryptographyd这句代码,可还是提示未

Windows Phone如何实现md5加密?
我已经添加了using System.Security.Cryptographyd;这句代码,可还是提示
未能找到类型或命名空间名称“MD5CryptoServiceProvider”(是否缺少 using 指令或程序集引用?)

[最优解释]


public class MD5CryptoServiceProvider : MD5
    {
        public MD5CryptoServiceProvider() : base()
        {
        }
    }

    /// <summary>
    /// Summary description for MD5.
    /// </summary>
    public class MD5 : IDisposable
    {
        static public MD5 Create(string hashName)
        {
            if (hashName == "MD5")
                return new MD5();
            else
                throw new NotSupportedException();
        }

        static public String GetMd5String(String source)
        {
            MD5 md = MD5CryptoServiceProvider.Create();
            byte[] hash;
            //Create a new instance of ASCIIEncoding to
            //convert the string into an array of Unicode bytes.
            UTF8Encoding enc = new UTF8Encoding();
            //            ASCIIEncoding enc = new ASCIIEncoding();
            //Convert the string into an array of bytes.
            byte[] buffer = enc.GetBytes(source);
            //Create the hash value from the array of bytes.
            hash = md.ComputeHash(buffer);
            StringBuilder sb = new StringBuilder();
            foreach (byte b in hash)
                sb.Append(b.ToString("x2"));
            return sb.ToString();
        }

        static public byte[] GetMd5ByteArray(String source)
        {
            MD5 md = MD5CryptoServiceProvider.Create();


            byte[] hash;
            //Create a new instance of ASCIIEncoding to
            //convert the string into an array of Unicode bytes.
            UTF8Encoding enc = new UTF8Encoding();
            //            ASCIIEncoding enc = new ASCIIEncoding();
            //Convert the string into an array of bytes.
            byte[] buffer = enc.GetBytes(source);
            //Create the hash value from the array of bytes.
            hash = md.ComputeHash(buffer);

            return hash;
        }

        static public MD5 Create()
        {
            return new MD5();
        }

热点排行