windows phone开发之客户端本地简单填充加密解密
2012-02-14 14:41
369 查看
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
{
//预先定义的字节数组如下:
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;
}
}
}
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
{
//预先定义的字节数组如下:
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;
}
}
}
相关文章推荐
- windows phone开发之客户端本地简单填充加密解密
- Windows Phone开发之客户端本地简单填充加密解密
- Jsoup开发简单网站客户端之读取本地html文件
- 与众不同 windows phone (28) - Feature(特性)之手机方向, 本地化, 应用程序的试用体验, 系统主题资源, 本地数据的加密解密
- Java版适用于PHP版3DES加密解密(PHP语言开发的MCRYPT_3DES算法、MCRYPT_MODE_ECB模式、PKCS7填充方式)
- Visual Studio 2017中使用正则修改部分内容 如何使用ILAsm与ILDasm修改.Net exe(dll)文件 C#学习-图解教程(1):格式化数字字符串 小程序开发之图片转Base64(C#、.Net) jquery遍历table为每一个单元格取值及赋值 。net加密解密相关方法 .net关于坐标之间一些简单操作
- 与众不同 windows phone (28) - Feature(特性)之手机方向, 本地化, 应用程序的试用体验, 系统主题资源, 本地数据的加密解密
- iOS开发:base64简单的加密和解密使用
- 使用XNA为Windows phone 7开发简单拼图游戏
- eclipse RCP开发一个简单的MYSQL客户端工具介绍
- SQL SERVER 数据库字段简单加密解密
- jsp开发中中文传值加密解密
- IO流简单应用(文件加密和解密)
- Java加密解密简单实现
- Android开发数据加密之手机端的加密解密
- gSoap入门之三__C++开发的简单WebService客户端程序
- 谈软件加密(解密)及逆向技术与软件开发技术的关系
- 用asp写一个简单的加密和解密的类。。。。
- webconfig简单加密解密
- Android开发 QQ sso登录和分享到QQ好友功能,调用本地QQ客户端