首页上一页 1 下一页尾页 2 条记录 1/1页
我新建了一个类文件DBConfig 但在其他窗体代码中用DBconfig.Encryp( 加密内容 ) 调用不到,是什么原因呀?
发表在C#图书答疑
2010-07-03
是否精华
是
否
版块置顶:
是
否
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography; //加密解密用
using System.IO; //MemoryStream文件流用
namespace 从ini文件中读取数据库连接
{
class DBConfig
{
public string Encryp(string what)
{
string encryptKey = "secr";//加密key
try
{
DESCryptoServiceProvider descsp = new DESCryptoServiceProvider();
byte[] key = Encoding.Unicode.GetBytes(encryptKey);
byte[] data = Encoding.Unicode.GetBytes(what.Trim());
MemoryStream MStream = new MemoryStream();
CryptoStream CStream = new CryptoStream(MStream, descsp.CreateEncryptor(key, key), CryptoStreamMode.Write);
CStream.Write(data, 0, data.Length);
CStream.FlushFinalBlock();
return Convert.ToBase64String(MStream.ToArray());
}
catch
{
MessageBox.Show("加密失败!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return string.Empty;
}
}
public string Descryp(string what) //有返回值的方法
{
string encryptKey = "secr";//解密key
try
{
DESCryptoServiceProvider descsp = new DESCryptoServiceProvider();
byte[] key = Encoding.Unicode.GetBytes(encryptKey);
byte[] data = Convert.FromBase64String(what.Trim());
MemoryStream MStream = new MemoryStream();
CryptoStream CStream = new CryptoStream(MStream, descsp.CreateDecryptor(key, key), CryptoStreamMode.Write);
CStream.Write(data, 0, data.Length);
CStream.FlushFinalBlock();
return Encoding.Unicode.GetString(MStream.ToArray());
}
catch
{
MessageBox.Show("解密失败!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return string.Empty;
}
}
}
}
[font color=#FF0000]
[strong]//在其他窗体代码中用DBconfig.Encryp("加密内容") 调用不到,是什么原因呀?
[/strong][/font]
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography; //加密解密用
using System.IO; //MemoryStream文件流用
namespace 从ini文件中读取数据库连接
{
class DBConfig
{
public string Encryp(string what)
{
string encryptKey = "secr";//加密key
try
{
DESCryptoServiceProvider descsp = new DESCryptoServiceProvider();
byte[] key = Encoding.Unicode.GetBytes(encryptKey);
byte[] data = Encoding.Unicode.GetBytes(what.Trim());
MemoryStream MStream = new MemoryStream();
CryptoStream CStream = new CryptoStream(MStream, descsp.CreateEncryptor(key, key), CryptoStreamMode.Write);
CStream.Write(data, 0, data.Length);
CStream.FlushFinalBlock();
return Convert.ToBase64String(MStream.ToArray());
}
catch
{
MessageBox.Show("加密失败!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return string.Empty;
}
}
public string Descryp(string what) //有返回值的方法
{
string encryptKey = "secr";//解密key
try
{
DESCryptoServiceProvider descsp = new DESCryptoServiceProvider();
byte[] key = Encoding.Unicode.GetBytes(encryptKey);
byte[] data = Convert.FromBase64String(what.Trim());
MemoryStream MStream = new MemoryStream();
CryptoStream CStream = new CryptoStream(MStream, descsp.CreateDecryptor(key, key), CryptoStreamMode.Write);
CStream.Write(data, 0, data.Length);
CStream.FlushFinalBlock();
return Encoding.Unicode.GetString(MStream.ToArray());
}
catch
{
MessageBox.Show("解密失败!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return string.Empty;
}
}
}
}
[font color=#FF0000]
[strong]//在其他窗体代码中用DBconfig.Encryp("加密内容") 调用不到,是什么原因呀?
[/strong][/font]