ElDavoo / wa-crypt-tools

Manage WhatsApp .crypt12, .crypt14 and .crypt15 files.
GNU General Public License v3.0
583 stars 78 forks source link

feature request: export 64-digit encryption key #35

Closed privnote42 closed 1 year ago

privnote42 commented 2 years ago

Hello, I have a feature request. Would it be possible to output / export the 64-digit encryption key so that I can import an E2E encrypted backup?

This is the use case: I forgot my password for the E2E encrypted backup and did not save the 64-digit encryption key.

I wanted to update my phone to a new LineageOS version, so I backed up Whatsapp and then deleted all partitions. I also made a backup of the Whatsapp folder in /data/data, so I still have encrypted_backup.key as a file.

The export also works without problems, but unfortunately Whatsapp does not seem to accept this non-encrypted database; at least when I reinstalled Whatsapp, I was not offered a restore with it.

ElDavoo commented 2 years ago

I don't know if that's going to work, but it's certainly doable. Tomorrow morning I will make it that it will be printed in verbose mode. In the meantime, you can try inserting a print(key) in the program, as the Key object has the print method

privnote42 commented 2 years ago

Hi, I have already tried to output the key in the load_crypt15 function. But I only get a byte hex code there, which I can't convert with the decode function either, because i got an error. UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa2 in position 3: invalid start byte

Or is that already all I need? This would be the output (I have already changed some parts so that my real key is not published here): b'<k\x1f\xb1_\xc0\x06\xbe\xff\xeb\x1cU\nI\x13\xf9\x9c\xe0I\x16DP\x51N\\x9doJ\xc8R\xfc~'

I would then translate it like this 1FB1C006....C8FC

privnote42 commented 2 years ago

ok, I think I got it now. Now I just output the key object at the end of the main function. The hex function was probably the missing piece of the puzzle, now I probably have the right hex code. The next restore attempt I can only do in 12h, because of the frequent reinstallations today...

I will let you know after my next try is done

privnote42 commented 2 years ago

ok, the displayed key was accepted during restore. Thanks again for your help.

Unfortunately, the restore itself did not restore my chats. I have now found another way and have overwritten the msgstore.db directly in the folder /data/data/com.whatsapp/databases/ after I did the failed restore (without reinstalling whatsapp). Before overwriting, I stopped whatsapp to be on the safe side and after restarting, all my chats were there again.

Just a quick note in case anyone has the same problem as me with a non-functioning restore

ElDavoo commented 2 years ago

ok, sorry for not doing it yesterday. Would you mind making a pull request?

ElDavoo commented 1 year ago

you just had to uncomment line 683 lol