如题,注意是文件夹,不是文件。不能利用rar工具。
谢谢!
谢谢!
解决方案 »
- 自动去读U盘图像缩略图显示打印(热插拔略有不足希望高人指点)
- 内嵌里webBrowser,如何调用IE的自定义插件?
- datagridview 绑定强类型dataset,删除问题
- 再次提问Remoting外网访问问题
- 根据鼠标右击的位置分配不同的ContextMenuStrip怎么实现
- 有关替换转义符的问题,在线等!!!!!!
- asp.net不能调用vb写的com组件,未将对象引用设置到对象的实例,而在winfrm中就可以调用这个com组件.急!!
- log4net问题,请各位看一下
- 求助:vs2005智能设备开发部署打包问题
- console.writer()需要那一个应用?谢谢
- 怎么拒绝某个端口上的通信(C#)?
- 嵌套Repeater的绑定数据问题
#1楼 得分:20回复于:2008-07-22 18:00:31一些简单的加解密
C# code
public static void Encrypt(string pathIn, string pathOut, string password)
{
try
{
byte[] iv = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
byte[] key = System.Text.Encoding.UTF8.GetBytes(password);
System.IO.FileStream fs = new FileStream(pathIn, FileMode.Open, FileAccess.Read);
System.IO.FileStream outfs = new FileStream(pathOut, FileMode.OpenOrCreate, FileAccess.Write);
outfs.SetLength(0);
byte[] myBytes = new byte[100];
long myInLength = 0;
long myLength = fs.Length;
System.Security.Cryptography.DESCryptoServiceProvider dsp = new DESCryptoServiceProvider();
System.Security.Cryptography.CryptoStream cs = new CryptoStream(outfs, dsp.CreateEncryptor(key, iv), CryptoStreamMode.Write);
while (myInLength < myLength)
{
int myLen = fs.Read(myBytes, 0, 100);
cs.Write(myBytes, 0, myLen);
myInLength += myLen;
}
cs.Close();
fs.Close();
outfs.Close();
}
catch (IOException ioex)
{
Log.debug("Encrypt(pathIn, pathOut, password): " + ioex.Message + "\r\nSource:" + ioex.Source + "\r\nStackTrace:" + ioex.StackTrace);
}
} public static void Decrypt(string pathIn, string pathOut, string password)
{
try
{
System.IO.FileStream fs = new FileStream(pathIn, FileMode.Open, FileAccess.Read);
System.IO.FileStream outfs = new FileStream(pathOut, FileMode.OpenOrCreate, FileAccess.Write);
outfs.SetLength(0);
long myLength = fs.Length;
long myInLength = 0;
byte[] iv = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
byte[] key = System.Text.Encoding.UTF8.GetBytes(password);
System.Security.Cryptography.DESCryptoServiceProvider dsp = new DESCryptoServiceProvider();
System.Security.Cryptography.CryptoStream cs = new CryptoStream(outfs, dsp.CreateDecryptor(key, iv), CryptoStreamMode.Write);
byte[] myBytes = new byte[100];
while (myInLength < myLength)
{
int myLen = fs.Read(myBytes, 0, 100);
cs.Write(myBytes, 0, myLen);
myInLength += myLen;
}
cs.Close();
fs.Close();
outfs.Close();
}
catch (IOException ioex)
{
Log.debug("Dncrypt(pathIn, pathOut, password): " + ioex.Message + "\r\nSource:" + ioex.Source + "\r\nStackTrace:" + ioex.StackTrace);
}
} public static string EncryptBy16MD5(string strProclaimed)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
string strCryptograph = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(strProclaimed)), 4, 8);
return strCryptograph;
} /// <summary>
/// md5 32位加密
/// </summary>
/// <param name="strProclaimed">明文</param>
/// <returns>密文</returns>
public static string EncryptBy32MD5(string strProclaimed)
{
MD5 md5 = MD5.Create();
string strCryptograph = "";
byte[] bytCode = md5.ComputeHash(Encoding.UTF8.GetBytes(strProclaimed));
for (int i = 0; i < bytCode.Length; i++)
{
// 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
strCryptograph = strCryptograph + bytCode[i].ToString("x");
}
return strCryptograph;
}
这个加密文件可以,文件夹不行。。
System.IO.FileStream fs = new FileStream(pathIn, FileMode.Open, FileAccess.Read);
会出异常!