专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Windows Mobile

Windows Phone怎么实现md5加密

发布时间:2010-05-30 00:37:35 文章来源:www.iduyao.cn 采编人员:星星草
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();
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: