2

-Update:

Looked into TWRP log, and it seems like it has key problems:

I:Setting up '/data' as data/media emulated storage.
I:mount -o bind '/data/media' '/sdcard' process ended with RC=0
I:mount -o bind '/data/media/0' '/sdcard' process ended with RC=0
I:File Based Encryption is present
e4crypt_initialize_global_de
Determining wrapped-key support for /data
fbe.data.wrappedkey = true
Wrapped key supported on /data
calling retrieveAndInstallKey
Key exists, using: /data/unencrypted/key
Using Keymaster HAL: 4 from QTI for encryption.  Security level: TRUSTED_ENVIRONMENT, HAL: android.hardware.keymaster@4.0::IKeymasterDevice/default
begin failed, code -62
Upgrading key in memory only: /data/unencrypted/key
upgrade_key failed, code -38
e4crypt_initialize_global_de returned fail

And this is after I wanted to decrypt it:

I:Command 'decrypt *********' received
I:Set page: 'singleaction_page'
I:operation_start: 'TWRP CLI Command'
Attempting to decrypt data partition or user data via command line.
E:Unexpected value for crypto key location
E:Error getting crypt footer and key
E:Could not get footer
Failed to decrypt data.
I:Done reading ORS command from command line
I:operation_end - status=0

Checked the location at /data/unencrypted/key and the files are there for sure.

Currently I'm on the same ROM as the one that on I could access my internal storage, but the issue could be that I went FDE -> FBE -> FDE as it's mentioned in the comments.

Keymaster error codes are respectively:

KEY_REQUIRES_UPGRADE = -62
INVALID_ARGUMENT = -38

How to fix the keys is the answer I might looking for.

Long story short, I screwed up, and now I have an encrypted storage (with my files that I want back) but TWRP and the OS thinks it is not.

It goes like this:

  • The Magisk v22.0 update screwed up my phone, which stuck in a bootloop.
  • After countless tries with Magisk (updating, uninstalling. installing, removing mods, adding mods) in TWRP, I read somewhere to dirty flash the ROM.
  • Due to an HDD failure in my PC, I did not have any storage to back up my internal storage from the phone.
  • Because I wanted to update the ROM anyways (from MIUI 11 to 12) I decided to flash the newer one. That was the first mistake. This made the bootloop worse, and now it stuck in fastboot mode, no recovery. After many sleepless nights I found out that not every USB-C cable is equal, and I couldn't reach my phone via fastboot because of the cable itself.
  • Due to an HDD failure in my PC, I did not have any storage to back up my internal storage from the phone.
  • So now I was able to flash an original fastboot ROM which still gave me bootloop, but after wiping (not formatting, so the /sdcard fs doesn't gets erased) Data and Cache in TWRP.
  • Then reflashed the fastboot ROM, and somehow it worked. When It booted up, I had to type in my screenlock pin again, and after setup all my files were available.
  • Now that the phone worked again, I wanted to finish what I started, to update to latest EU (recovery) ROM. This was the second mistake. It did not work (because it required formatting data, which I did not wanted to, and just wiped it), and came bootloop again.
  • So I went back to the fastboot ROM again, which fixed the phone again.
  • But this time, it thinks the internal storage is not encrypted.

Now I can't access the internal storage. Even the camera app says that first I need an SD Card to take photos.

It's clearly still encrypted because when I browse it in TWRP, the structure and files are there, but the names are like "74t7Z1,dnvgIIexr1QAfhD".

The problem being neither the OS, nor TWRP knows the storage is encrypted, so it doesn't even tries to decrypt it, and there are no options to do it.

Tried to set encryption in the running OS, but it gave me the same results: even tho TWRP asks for decryption key, and says it successfully decrypted, the storage is still a mess like it's in encrypted state.

Is there any way to manually force some flag, so I can access my files again? I have the encryption key, I just need some way to decrypt the storage. I think of something like an ADB command to flag the partition as encrypted, so TWRP and OS would try to decrypt it.

Thanks in advance!

14
  • your description is too broad. it looks like you switched encryption type from FDE -> FBE -> FDE so at least you should install ROM+recovery which support FBE. be aware encryption keys are downgrade protected
    – alecxs
    Apr 15 at 8:19
  • It seems like it really is an encryption key problem. TWRP log showed this: Determining wrapped-key support for /data fbe.data.wrappedkey = true Wrapped key supported on /data calling retrieveAndInstallKey Key exists, using: /data/unencrypted/key Using Keymaster HAL: 4 from QTI for encryption. Security level: TRUSTED_ENVIRONMENT, HAL: android.hardware.keymaster@4.0::IKeymasterDevice/default begin failed, code -62 Upgrading key in memory only: /data/unencrypted/key upgrade_key failed, code -38 e4crypt_initialize_global_de returned fail Apr 15 at 12:39
  • pulled the whole block, which is 230GB (256GB storage...). How do I decrypt a double encryption? This is the question I cant find an answer to :/ Apr 18 at 11:13
  • tucana:/ # df -h Filesystem Size Used Avail Use% Mounted on tmpfs 3.6G 288K 3.6G 1% /dev tmpfs 3.6G 0 3.6G 0% /mnt tmpfs 3.6G 140K 3.6G 1% /tmp /dev/block/sda30 356M 1.1M 355M 1% /cache /dev/block/sde51 320M 139M 181M 44% /firmware /dev/block/sda32 228G 15G 214G 7% /data This is the current state after pulling, formatting data, then installing latest OS wich already has force encryption. Just push back data? Because the img is like 230GB :D Apr 18 at 16:06
  • well, rip then Tho I don't want to let it go. Is there any way to decrypt *.img offline/locally Apr 18 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.