【发布时间】:2017-10-04 08:55:40
【问题描述】:
场景:上传文件而不是尝试使用带有密码保护的DotNetZip 压缩文件,密码是使用Membership.GeneratePassword() 方法生成的。一切正常,只是有时用户无法使用生成的密码解压缩文件。有线的事情是,这种情况只发生在某些时候,比如说 15 次中的 1 次。
生成密码:
public static String FilePassword()
{
while (_filePassword.Length < 12)
{
_filePassword += string.Concat(Membership.GeneratePassword(1, 0).Where(char.IsLetterOrDigit));
}
return _filePassword;
}
保存文件:
if (FileUploadControl.HasFile)
{
fileName = Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(FileSavePath + fileName);
// Archive uploaded file to zip.
using (ZipFile zip = new ZipFile())
{
// File to be archived.
var file = FileUploadControl.PostedFile;
// Enable encryption of file
zip.Encryption = EncryptionAlgorithm.PkzipWeak;
// Set password.
zip.Password = Settings.FilePassword();
// Set temporary folder path for archive process.
zip.TempFileFolder = tempPath;
// Add file to archive with its path.
zip.AddFile(FileSavePath + file.FileName, "");
File objFile = new File(file.FileName, FileSavePath);
// Save zip file with the name as file ID.
zip.Save(FileSavePath + file.FileName);
}
}
我在创建方法时记录了密码,并且在使用密码保护 zip 文件时,它们总是匹配的,我看不出有什么问题,为什么有时在解压缩文件时显示错误的密码。
【问题讨论】:
-
您能否向我们展示一些有效和无效的密码示例?
-
你检查过密码的字符编码吗?
-
@mjwills 密码是字母数字,工作密码之一:vKkowRZBtIxo,无效密码:QjCFFaM9LumZ
标签: c# asp.net .net zip dotnetzip