mukulhase / WebWhatsapp-Wrapper

An API for sending and receiving messages over web.whatsapp [Working as of 18th May 2018]
https://webwhatsapi.readthedocs.io/en/latest/
MIT License
2.03k stars 795 forks source link

Decryption problem #722

Open GuilhermeHumberto opened 5 years ago

GuilhermeHumberto commented 5 years ago

Hi guys!! This morning my code began to return error in decrypting files sent by Whatsapp. Can anyone tell me what it can be?

Tks!


WAPI.downloadFile2(url, function(result) {
    console.log("type", tipo);
    console.log("result", result);
    console.log("mediakey", mediakey);
    console.log("mimetype", mimetype);
    Store.CryptoLib.decryptE2EMedia(tipo, result, mediakey, mimetype).then(function(a) {
        let reader = new FileReader();
        reader.readAsDataURL(a._blob);
        reader.onload = function (e) {
            callback(reader.result);
        };
    }).catch(function(e) {
        console.log("Error: " + e);
    });
});

returning in browser console:

type AUDIO result ArrayBuffer(4522) {} mediakey WDvy1U2igfAJ1LPlTzjPYavmS+J7K2zAowil9KKyN7w= mimetype audio/ogg

and error:

Error: MediaEncryptionError: encryption error: TypeError: t[e] is not a function; stack: TypeError: t[e] is not a function

eduardobento commented 5 years ago

Same problem here.

GuilhermeHumberto commented 5 years ago

When I change xhr.responseType = 'arraybuffer'; to xhr.responseType = 'blob'; in window.WAPI.downloadFile2, the console of browser return Error: MediaEncryptionError: decrypt async, missing "payload"

😞

window.WAPI.downloadFile2 = function(url, done) {
    let xhr = new XMLHttpRequest();
    xhr.onload = function () {
        if (xhr.readyState == 4) {
            if (xhr.status == 200) {
                done(xhr.response);
            } else {
                console.error(xhr.statusText);
            }
        } else {
            console.log(err);
            done(false);
        }
    };
    xhr.open("GET", url, true);
    //xhr.responseType = 'arraybuffer';
    xhr.responseType = 'blob';
    xhr.send(null);
};
ivornei commented 5 years ago

convert type to lowercase to solve...

Store.CryptoLib.decryptE2EMedia(type.toLowerCase(), xhr.response, messageObj.mediaKey, messageObj.mimetype)

GuilhermeHumberto commented 5 years ago

@ivornei tks for this! I'm testing and apparently it's working...