欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > 内容正文

windows phone开发之客户端本地简单填充加密解密

来源: 开发者 投稿于  被查看 27259 次 评论:267

windows phone开发之客户端本地简单填充加密解密


using System; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Ink; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Microsoft.Phone.Controls; 
using System.Security.Cryptography; 
 
 
//创建人:vakin  时间:2011-12-15 
 
namespace MicroBlogForWP7.Classes.Util 

    //将输入的字符串转换为字节数组 
    //然后使用ProtectedData以及预先定义的字节数组进行加密 
    //加密后得到的也是一个字节数据 
    //最后使用Convert.ToBase64String得到其对应的字符串 
 
    public class Encrypt 
    { 
        //预先定义的字节数组如下:  www.2cto.com
        byte[] opt = new byte[] { 1, 2, 4, 8, 16 }; 
 
        /// <summary> 
        /// 密码的加密操作 
        /// </summary> 
        /// <param name="userpassword">未加密的密码内容</param> 
        /// <returns></returns> 
        private string EncryptPwd(string userpassword) 
        { 
            byte[] input = System.Text.Encoding.UTF8.GetBytes(userpassword); 
 
            string result = Convert.ToBase64String(ProtectedData.Protect(input, opt));  
 
            return result; 
        } 
 
        /// <summary> 
        /// 解密解码。没有加密的情况下返回null 
        /// </summary> 
        /// <param name="userpassword">加密后的密码内容</param> 
        /// <returns></returns> 
        private string DecryptPwd(string userpassword) 
        { 
            if (string.IsNullOrEmpty(userpassword)) 
            { 
                //没有加密的密码 
                return null; 
            } 
 
            byte[] output = Convert.FromBase64String(userpassword); 
 
            byte[] en = ProtectedData.Unprotect(output, opt); 
 
            string result = System.Text.Encoding.UTF8.GetString(en, 0, en.Length); 
 
            return result;  
        } 
    } 


摘自 _亚

相关文章

    暂无相关文章
相关频道:

用户评论