如何使用c#实现加密压缩 想做个单文件软件,所以不想使用ICSharpCode.SharpZipLib中组件(虽然有其源码,但文件太大,且许多功能都非所需,不想直接使用,再因技术太差,无法直接提取中需要部分),如此前提下,如何实现加密压缩,要求压缩率较大。不要提这种建议:采用一种压缩算法,再使用另外一种加密算法。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 lz不妨去看看 http://www.7-zip.org/sdk.htmlskd里面有压缩和解压的c#源码另外,7zip算法的压缩率应该是相当高的了 可直接使用winrar加密压缩文件 string strtxtPath = "C:\\A\\1.txt"; string strzipPath = "C:\\B\\1.zip"; System.Diagnostics.Process Process1 = new System.Diagnostics.Process(); Process1.StartInfo.FileName = "Winrar.exe"; Process1.StartInfo.CreateNoWindow = true; Process1.StartInfo.Arguments = " a -r "+strzipPath+" " + strtxtPath ; Process1.StartInfo.Arguments = " a -ep " + strzipPath + " " + strtxtPath; ////加密压缩c Process1.StartInfo.Arguments = " a -p123456 " + strzipPath + " " + strtxtPath; Process1.Start(); if (Process1.HasExited) { int iExitCode = Process1.ExitCode; if (iExitCode == 0) { Response.Write(iExitCode.ToString() + " 完成"); } else { Response.Write(iExitCode.ToString() + " 有错"); } } protected void Button1_Click(object sender, EventArgs e) { string strtxtPath = "C:\\freezip\\free.txt"; string strzipPath = "C:\\freezip\\free.zip"; System.Diagnostics.Process Process1 = new System.Diagnostics.Process(); Process1.StartInfo.FileName = "Winrar.exe"; Process1.StartInfo.CreateNoWindow = true; //// 1 ////压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt) ////到c:\freezip\free.rar //strzipPath = "C:\\freezip\\free";//默认压缩方式为 .rar //Process1.StartInfo.Arguments = " a -r " + strzipPath + " " + strtxtPath; //// 2 ////压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt) ////到c:\freezip\free.rar //strzipPath = "C:\\freezip\\free";//设置压缩方式为 .zip //Process1.StartInfo.Arguments = " a -afzip " + strzipPath + " " + strtxtPath; //// 3 ////压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt) ////到c:\freezip\free.zip 直接设定为free.zip //Process1.StartInfo.Arguments = " a -r "+strzipPath+" " + strtxtPath ; //// 4 ////搬迁压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt) ////到c:\freezip\free.rar 压缩后 原文件将不存在 //Process1.StartInfo.Arguments = " m " + strzipPath + " " + strtxtPath; //// 5 ////压缩c:\freezip\下的free.txt(即文件free.txt) ////到c:\freezip\free.zip 直接设定为free.zip 只有文件 而没有文件夹 //Process1.StartInfo.Arguments = " a -ep " + strzipPath + " " + strtxtPath; //// 6 ////解压缩c:\freezip\free.rar ////到 c:\freezip\ //strtxtPath = "c:\\freezip\\"; //Process1.StartInfo.Arguments = " x " + strzipPath + " " + strtxtPath; //// 7 ////加密压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt) ////到c:\freezip\free.zip 密码为123456 注意参数间不要空格 //Process1.StartInfo.Arguments = " a -p123456 " + strzipPath + " " + strtxtPath; //// 8 ////解压缩加密的c:\freezip\free.rar ////到 c:\freezip\ 密码为123456 注意参数间不要空格 //strtxtPath = "c:\\freezip\\"; //Process1.StartInfo.Arguments = " x -p123456 " + strzipPath + " " + strtxtPath; //// 9 ////-o+ 覆盖 已经存在的文件 //// -o- 不覆盖 已经存在的文件 //strtxtPath = "c:\\freezip\\"; //Process1.StartInfo.Arguments = " x -o+ " + strzipPath + " " + strtxtPath; ////10 //// 只从指定的zip中 //// 解压出free1.txt //// 到指定路径下 //// 压缩包中的其他文件 不予解压 //strtxtPath = "c:\\freezip\\"; //Process1.StartInfo.Arguments = " x " + strzipPath + " " +" free1.txt" + " " + strtxtPath; //// 11 //// 通过 -y 对所有询问回应为"是" 以便 即便发生错误 也不弹出WINRAR的窗口 //// -cl 转换文件名为小写字母 //strtxtPath = "c:\\freezip\\"; //Process1.StartInfo.Arguments = " t -y -cl " + strzipPath + " " + " free1.txt"; Process1.Start(); if (Process1.HasExited) { int iExitCode = Process1.ExitCode; if (iExitCode == 0) { Response.Write(iExitCode.ToString() + " 正常完成"); } else { Response.Write(iExitCode.ToString() + " 有错完成"); } } } vwxyzh:下载了你所提供的源文件地址,但发现时命令行下运行的,本人初学编程,一则看不懂那个源码,二则不能实现将其转换为winform中代码,三则其是否能实现加密,如何加密 参考protobuf-net可以参考FortuneBase中protobuf-net例子参考地址www.cnblogs.com/mail-ricklee c# 界面开发 treepanel节点刷新 C# 网络编程 基础问题2 用Console.WriteLine怎么输不出? ====第2个ASPX页接不到第1个SESSION页上的SESSION值问题==== 在一个文本框中只有输入数字,winfrom c# 二进制流转成excel vs2010连接数据库 的问题 急!! 求修改~c#编for循环语句,求数学平均成绩!~~ wpf 中 image控件中的bitmapsource/bitmapimage大小变化? C#多线程委托一个方法,很奇怪的问题 GridView的CheckBox的选中问题
skd里面有压缩和解压的c#源码
另外,7zip算法的压缩率应该是相当高的了
string strtxtPath = "C:\\A\\1.txt";
string strzipPath = "C:\\B\\1.zip";
System.Diagnostics.Process Process1 = new System.Diagnostics.Process();
Process1.StartInfo.FileName = "Winrar.exe";
Process1.StartInfo.CreateNoWindow = true; Process1.StartInfo.Arguments = " a -r "+strzipPath+" " + strtxtPath ; Process1.StartInfo.Arguments = " a -ep " + strzipPath + " " + strtxtPath; ////加密压缩c
Process1.StartInfo.Arguments = " a -p123456 " + strzipPath + " " + strtxtPath;
Process1.Start();
if (Process1.HasExited)
{
int iExitCode = Process1.ExitCode;
if (iExitCode == 0)
{
Response.Write(iExitCode.ToString() + " 完成");
}
else
{
Response.Write(iExitCode.ToString() + " 有错");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string strtxtPath = "C:\\freezip\\free.txt";
string strzipPath = "C:\\freezip\\free.zip";
System.Diagnostics.Process Process1 = new System.Diagnostics.Process();
Process1.StartInfo.FileName = "Winrar.exe";
Process1.StartInfo.CreateNoWindow = true; //// 1
////压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
////到c:\freezip\free.rar
//strzipPath = "C:\\freezip\\free";//默认压缩方式为 .rar
//Process1.StartInfo.Arguments = " a -r " + strzipPath + " " + strtxtPath; //// 2
////压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
////到c:\freezip\free.rar
//strzipPath = "C:\\freezip\\free";//设置压缩方式为 .zip
//Process1.StartInfo.Arguments = " a -afzip " + strzipPath + " " + strtxtPath; //// 3
////压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
////到c:\freezip\free.zip 直接设定为free.zip
//Process1.StartInfo.Arguments = " a -r "+strzipPath+" " + strtxtPath ; //// 4
////搬迁压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
////到c:\freezip\free.rar 压缩后 原文件将不存在
//Process1.StartInfo.Arguments = " m " + strzipPath + " " + strtxtPath; //// 5
////压缩c:\freezip\下的free.txt(即文件free.txt)
////到c:\freezip\free.zip 直接设定为free.zip 只有文件 而没有文件夹
//Process1.StartInfo.Arguments = " a -ep " + strzipPath + " " + strtxtPath; //// 6
////解压缩c:\freezip\free.rar
////到 c:\freezip\
//strtxtPath = "c:\\freezip\\";
//Process1.StartInfo.Arguments = " x " + strzipPath + " " + strtxtPath; //// 7
////加密压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
////到c:\freezip\free.zip 密码为123456 注意参数间不要空格
//Process1.StartInfo.Arguments = " a -p123456 " + strzipPath + " " + strtxtPath; //// 8
////解压缩加密的c:\freezip\free.rar
////到 c:\freezip\ 密码为123456 注意参数间不要空格
//strtxtPath = "c:\\freezip\\";
//Process1.StartInfo.Arguments = " x -p123456 " + strzipPath + " " + strtxtPath;
//// 9
////-o+ 覆盖 已经存在的文件
//// -o- 不覆盖 已经存在的文件
//strtxtPath = "c:\\freezip\\";
//Process1.StartInfo.Arguments = " x -o+ " + strzipPath + " " + strtxtPath; ////10
//// 只从指定的zip中
//// 解压出free1.txt
//// 到指定路径下
//// 压缩包中的其他文件 不予解压
//strtxtPath = "c:\\freezip\\";
//Process1.StartInfo.Arguments = " x " + strzipPath + " " +" free1.txt" + " " + strtxtPath; //// 11
//// 通过 -y 对所有询问回应为"是" 以便 即便发生错误 也不弹出WINRAR的窗口
//// -cl 转换文件名为小写字母
//strtxtPath = "c:\\freezip\\";
//Process1.StartInfo.Arguments = " t -y -cl " + strzipPath + " " + " free1.txt"; Process1.Start();
if (Process1.HasExited)
{
int iExitCode = Process1.ExitCode;
if (iExitCode == 0)
{
Response.Write(iExitCode.ToString() + " 正常完成");
}
else
{
Response.Write(iExitCode.ToString() + " 有错完成");
}
}
}
参考地址www.cnblogs.com/mail-ricklee