delphi 从xe2开始,自带了system.zip 单元,支持压缩解压。但一直对加密解密不能很好的支持。
自从delphi xe12开始,新增了password字段。但如果你设置密码,那么运行后就会报“Zip file cryptor is not specified”的错误。
说是因为法律方面的问题,一波龙没有实现具体的加密解密过程。而只是留了一个cryptor接口。网上找了一下,国外有delphi爱好者实现了这个加密解密接口。
GitHub - UweRaabe/EncryptedZipFile: TZipFile with Password Encryption
github上下载 PKWAREZipCryptor.pas 文件,然后引用该文件。
var zip: TZipFile;
LocalHeader: TZipHeader;
zip := TZipFile.Create;
zip.Cryptor:= TPKWAREZipCryptor.Create;
LocalHeader.IsEncrypted:= true;
zip.Password:= '123456';
……
经测试,使用此接口加密解密正常。且生成的zip文件能与winrar互相解密。
这个接口帮了我的大忙,在此感谢大神的奉献!也顺便介绍给遇到相同问题的朋友。
Delphi加密解压

最低0.47元/天 解锁文章
5077






