c# ini文件加密 大家可以提供建议也可以直接提供代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 其实ini加密 无非是加密里面的 值· 建议可以用 MD5 加密值 到网上下载一个MD5的源码 思路 string a=MD5.DoMD5("需要加密的值"); a 就成为加密后的值 然后用流存进 ini 文件中 ini是个文本文件其实,有N种方法加密解密常见的有:用API操作INI和自解析~不管操作和自解析,都可以采用,讲每个字符XOR一个任意数,然后解密时候还XOR这个任意数,就得到这个字符本身。这是最初级的。还可以用流提供的加密流,比如 System.Security.Cryptography 空间里的类们~ using System;using System.Collections.Generic;using System.Text;using System.Security.Cryptography;namespace Common{ public class DESEncrypt { public DESEncrypt() { } #region 加密数据 /// <summary> /// 加密处理 /// </summary> /// <param name="str">要加密的字符串</param> /// <returns></returns> public static string Encrypt(string str) { return Encrypt(str,"zhangyue2010"); } /// <summary> /// 加密处理 /// </summary> /// <param name="str">要加密的字符串</param> /// <param name="key">key值</param> /// <returns></returns> public static string Encrypt(string str, string key) { //定义访问数据加密标准 DESCryptoServiceProvider dsp = new DESCryptoServiceProvider(); byte[] inputArray; inputArray = Encoding.Default.GetBytes(str); dsp.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(key,"md5").Substring(0,8)); dsp.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(key, "md5").Substring(0, 8)); System.IO.MemoryStream ms = new System.IO.MemoryStream(); CryptoStream cs = new CryptoStream(ms, dsp.CreateEncryptor(), CryptoStreamMode.Write); cs.Write(inputArray,0,inputArray.Length); cs.FlushFinalBlock(); StringBuilder sb = new StringBuilder(); foreach(byte b in ms.ToArray()) { sb.AppendFormat("{0:X2}",b); } return sb.ToString(); } #endregion #region 解密数据 /// <summary> /// 解密处理 /// </summary> /// <param name="str"></param> /// <returns></returns> public static string Decrypt(string str) { return Decrypt(str,"zhangyue2010"); } /// <summary> /// 解密处理 /// </summary> /// <param name="str"></param> /// <param name="key"></param> /// <returns></returns> public static string Decrypt(string str, string key) { DESCryptoServiceProvider dsp = new DESCryptoServiceProvider(); int len; len = str.Length / 2; byte[] inputArray=new byte[len]; int i, j; for (i = 0; i < len; i++) { i = Convert.ToInt32(str.Substring(i*2,2),16); inputArray[i] = (byte)i; } dsp.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(key,"md5").Substring(0,8)); dsp.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(key, "md5").Substring(0, 8)); System.IO.MemoryStream ms = new System.IO.MemoryStream(); CryptoStream cs = new CryptoStream(ms,dsp.CreateDecryptor(),CryptoStreamMode.Write); cs.Write(inputArray,0,inputArray.Length); cs.FlushFinalBlock(); return Encoding.Default.GetString(ms.ToArray()); } #endregion }}可以看看呦 求电子书编译原理 textbox里为什么有些字符不能输入? 类序列化成XML时 如何加属性 当页面中有web控件时刷新后怎样才能不出现:"不重新发送信息,则无法刷新网页"这个提示.. " "Form1” : 成员名称不能与它们的封闭类型相同 "编译错误什么意思? help,怎样把按钮设置成缺省的按钮? 如何在C#的一个页面类获取任意一个页面的对象? 求一种支持动态产生类的语言 使用datagrid数据绑定来录入数据,请各位帮忙!急用,解决就马上给分…… 关于VS.NET的调试窗口 C#做传奇登陆器问题(贴上源码)大家帮我分析下啊! 关于WPF多点触控问题
到网上下载一个MD5的源码 思路
string a=MD5.DoMD5("需要加密的值"); a 就成为加密后的值 然后用流存进 ini 文件中
常见的有:
用API操作INI和自解析~
不管操作和自解析,都可以采用,讲每个字符XOR一个任意数,然后解密时候还XOR这个任意数,就得到这个字符本身。这是最初级的。
还可以用流提供的加密流,比如 System.Security.Cryptography 空间里的类们~
using System.Collections.Generic;
using System.Text;using System.Security.Cryptography;namespace Common
{
public class DESEncrypt
{
public DESEncrypt() { }
#region 加密数据
/// <summary>
/// 加密处理
/// </summary>
/// <param name="str">要加密的字符串</param>
/// <returns></returns>
public static string Encrypt(string str)
{
return Encrypt(str,"zhangyue2010");
}
/// <summary>
/// 加密处理
/// </summary>
/// <param name="str">要加密的字符串</param>
/// <param name="key">key值</param>
/// <returns></returns>
public static string Encrypt(string str, string key)
{
//定义访问数据加密标准
DESCryptoServiceProvider dsp = new DESCryptoServiceProvider();
byte[] inputArray;
inputArray = Encoding.Default.GetBytes(str);
dsp.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(key,"md5").Substring(0,8));
dsp.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(key, "md5").Substring(0, 8));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, dsp.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inputArray,0,inputArray.Length);
cs.FlushFinalBlock();
StringBuilder sb = new StringBuilder();
foreach(byte b in ms.ToArray())
{
sb.AppendFormat("{0:X2}",b);
}
return sb.ToString();
}
#endregion #region 解密数据
/// <summary>
/// 解密处理
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Decrypt(string str)
{
return Decrypt(str,"zhangyue2010");
}
/// <summary>
/// 解密处理
/// </summary>
/// <param name="str"></param>
/// <param name="key"></param>
/// <returns></returns>
public static string Decrypt(string str, string key)
{
DESCryptoServiceProvider dsp = new DESCryptoServiceProvider();
int len;
len = str.Length / 2;
byte[] inputArray=new byte[len];
int i, j;
for (i = 0; i < len; i++)
{
i = Convert.ToInt32(str.Substring(i*2,2),16);
inputArray[i] = (byte)i;
}
dsp.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(key,"md5").Substring(0,8));
dsp.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(key, "md5").Substring(0, 8));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms,dsp.CreateDecryptor(),CryptoStreamMode.Write);
cs.Write(inputArray,0,inputArray.Length);
cs.FlushFinalBlock();
return Encoding.Default.GetString(ms.ToArray());
}
#endregion
}
}
可以看看呦