c# 账号密码加密, 写入读取ini文件
2015-12-08 22:01
756 查看
[DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retvalue, int siz, string inipath); [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
private static string m_iniPath = System.Windows.Forms.Application.StartupPath + "\\config.ini";//配置路径 //写INI文件 public static void IniWriteValue(string Section, string Key, string Value) { WritePrivateProfileString(Section, Key, Value, m_iniPath); } //读取INI文件指定 public static string IniReadValue(string Section, string Key) { StringBuilder temp = new StringBuilder(255); int i = GetPrivateProfileString(Section, Key, "", temp, 255, m_iniPath); return temp.ToString(); }
以上为Config类文件内。
Config.IniWriteValue("UserName", "account", account);//写入密码不加密
<span style="font-family: 微软雅黑; font-size: 14px; line-height: 21px;"> private string passwdKey = "asfafagsgdsgkhk"; //加密的秘钥</span>
StringBuilder ps = new StringBuilder();
for (int i = 0; i < passwd.Length; ++i)
{
int c = passwd[i] ^ passwdKey[i]; //异或加密,使用int存储
ps.Append(c + " ");
}
Config.IniWriteValue("PassWord", "passwd", ps.ToString());
<pre name="code" class="csharp"><div style="font-family: 微软雅黑; font-size: 14px; line-height: 21px;"> string account = Config.IniReadValue("UserName", "account"); </div><div style="font-family: 微软雅黑; font-size: 14px; line-height: 21px;"> string passwd = Config.IniReadValue("PassWord", "passwd");</div> //读取密码需要解密
string[] ps = passwd.Split(' ');
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ps.Length; i++)
{
sb.Append((char)(passwdKey[i] ^ int.Parse(ps[i]))); //异或解密, 转换成char
}
passwd = sb.ToString();
相关文章推荐
- C#读取摄像头处理图片AForge
- (比如C#)里面调用AutoCAD ActiveX API实现后台打印DWG文件为PDF文件
- CAD插件技术真心不难,无非是画点线条,CAD内部能实现的,C#调用acdbmgd.dll和acmgd.dll也能实现
- AutoCAD二次开发的学习者快速掌握基于.NET的开发技术
- C#托管代码与C++非托管代码互相调用
- 七牛---关于C# SDK的各种Demo
- c#的dllimport使用方法详解
- C#读取摄像头并对图像做简单处理--AVICap32篇
- C#驱动及应用
- C# DataGridView
- The project type is not supported by this installation 尚未解决
- 初涉C#防止黑客攻击站短
- C#使用参数数组
- C# 关键字extern用法
- C++通过DLL调用C#代码
- C++通过DLL调用C#代码
- 内存泄漏及手动回收
- c# desencrypt加密解密
- c# 使用正则表达式去除字符串中的汉字
- C# Socket系列三 socket通信的封包和拆包