Replies: 9 comments 13 replies
-
I confirm zip.js can work as you described. This is actually exactly how https://gildas-lormeau.github.io/zip.js/demos/demo-read-file.html detects and handle passwords. See also the code below. zip.js/tests/all/test-crypto.js Lines 21 to 40 in 9e65bce However I see that you're using "DZXF" so I guess the issue is in this library. |
Beta Was this translation helpful? Give feedback.
-
Are you sure the call of |
Beta Was this translation helpful? Give feedback.
-
DZXF.unitl.unFile is my read zip/rar/7z DZXF.unitl.unFile(u8,callback,password,key) check u8 head match func
|
Beta Was this translation helpful? Give feedback.
-
I confirm that you can pass the password in the options of However, the name of the function does not match the one you were debugging ( Insert |
Beta Was this translation helpful? Give feedback.
-
let u8 = new Uint8Array([80,75,3,4,20,0,0,0,0,0,152,144,216,84,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,196,227,180,243,210,175,46,116,120,116,80,75,3,4,20,0,0,0,0,0,132,145,216,84,128,244,216,118,12,0,0,0,12,0,0,0,16,0,0,0,200,195,206,210,200,165,118,182,238,205,226,118,46,116,120,116,254,255,132,40,143,190,132,40,143,190,102,47,80,75,3,4,20,0,0,0,0,0,124,145,216,84,192,232,220,131,10,0,0,0,10,0,0,0,12,0,0,0,200,246,183,201,200,247,176,161,46,116,120,116,200,248,180,239,200,248,180,239,202,199,80,75,1,2,20,0,20,0,0,0,0,0,152,144,216,84,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,196,227,180,243,210,175,46,116,120,116,80,75,1,2,20,0,20,0,0,0,0,0,132,145,216,84,128,244,216,118,12,0,0,0,12,0,0,0,16,0,0,0,0,0,0,0,0,0,32,0,0,0,40,0,0,0,200,195,206,210,200,165,118,182,238,205,226,118,46,116,120,116,80,75,1,2,20,0,20,0,0,0,0,0,124,145,216,84,192,232,220,131,10,0,0,0,10,0,0,0,12,0,0,0,0,0,0,0,0,0,32,0,0,0,98,0,0,0,200,246,183,201,200,247,176,161,46,116,120,116,80,75,5,6,0,0,0,0,3,0,3,0,176,0,0,0,150,0,0,0,0,0]);
await DZXF.unitl.unFile(u8,null)
//{你大爷.txt: Uint8Array(0), 让我去v额外v.txt: Uint8Array(12), 撒飞洒啊.txt: Uint8Array(10)}
await DZXF.unitl.unFile(u8,null,123)
//{你大爷.txt: Uint8Array(0), 让我去v额外v.txt: Uint8Array(12), 撒飞洒啊.txt: Uint8Array(10)}
await DZXF.unitl.unFile(u8,null,undefined)
//{你大爷.txt: Uint8Array(0), 让我去v额外v.txt: Uint8Array(12), 撒飞洒啊.txt: Uint8Array(10)}
await DZXF.unitl.unFile(u8,null,undefined)
//{你大爷.txt: Uint8Array(0), 让我去v额外v.txt: Uint8Array(12), 撒飞洒啊.txt: Uint8Array(10)}
await DZXF.unitl.unFile(u8,null,"123243534")
//common_forumlocal.js?Xrh:310
// Uncaught (in promise) DOMException: A length of 0 was specified for PBKDF2's Derive Bits operation.
await DZXF.unitl.unFile(u8,null,123574574)
//{你大爷.txt: Uint8Array(0), 让我去v额外v.txt: Uint8Array(12), 撒飞洒啊.txt: Uint8Array(10)}
await DZXF.unitl.unFile(u8,null,"123574574")
//Uncaught (in promise) DOMException: A length of 0 was specified for PBKDF2's Derive Bits operation. |
Beta Was this translation helpful? Give feedback.
-
Sorry, it turns out that the clown is me! When I uploaded the file, I converted it into a zipfile because I judged that it was not a picture. As a result, my uploaded zipfile was compressed again |
Beta Was this translation helpful? Give feedback.
-
i see doc Promise.race(iterable); will best than the try/catch |
Beta Was this translation helpful? Give feedback.
-
Still having issues Thank you at last, the password problem that was plaguing me was solved. async unZip (u8,cb,password,key){
let T=this.T;
await this.ZipInitJS();
let entries = await (new zip.ZipReader(new zip.Uint8ArrayReader(u8))).getEntries();
if(entries.length>0){
let contents = {};
await Promise.all(
entries.map(
async entry=>{
if(!entry.directory)contents[entry.filename] = await this.ZipReadEntry(entry,password);
return true;
}
)
);
if(key){
Object.assign(T.Libjs,contents);
}
return key? T.Libjs[key]:contents;
}else{
return u8;
}
}
async ZipReadEntry(entry,password){
if(!entry.encrypted)return await entry.getData(new zip.Uint8ArrayWriter());
else{
try{
return await entry.getData(new zip.Uint8ArrayWriter(),{password});
}catch(e){
if(e.message=='File contains encrypted entry'){
let newpassword = window.prompt('need a read password');
if(newpassword){
return this.ZipReadEntry(entry,newpassword);
}
}
throw 'miss password';
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Still having issues Thank you at last, the password problem that was plaguing me was solved. async unZip (u8,cb,password,key){
let T=this.T;
await this.ZipInitJS();
let entries = await (new zip.ZipReader(new zip.Uint8ArrayReader(u8))).getEntries();
if(entries.length>0){
let contents = {};
await Promise.all(
entries.map(
async entry=>{
if(!entry.directory)contents[entry.filename] = await this.ZipReadEntry(entry,password);
return true;
}
)
);
if(key){
Object.assign(T.Libjs,contents);
}
return key? T.Libjs[key]:contents;
}else{
return u8;
}
}
async ZipReadEntry(entry,password){
if(!entry.encrypted)return await entry.getData(new zip.Uint8ArrayWriter());
else{
try{
return await entry.getData(new zip.Uint8ArrayWriter(),{password});
}catch(e){
if(e.message=='File contains encrypted entry'){
let newpassword = window.prompt('need a read password');
if(newpassword){
return this.ZipReadEntry(entry,newpassword);
}
}
throw 'miss password';
}
}
} |
Beta Was this translation helpful? Give feedback.
-
if file need password but i use errror password
i write a password in config,but zip not need password ,than has a PBKDFerr
i hope
I set a password in reader config, the reader first read file it not to using password to try read. if it real need a password ,then try to use password ,
password error : thow a password err message.
password true! then next file all using password.
add a try mode config
all file are try to no password reader,when it err,try to using password to read,if err. then thow password error message.
Beta Was this translation helpful? Give feedback.
All reactions