Cross-platform compatible encryption of SD-card for Android How would I go about encrypting my brand new 256GB SD-card, which is meant for my Android phone, considering the following:


Card should be usable across multiple Android devices, and other platforms (Linux..). As a consequence, native Android SD-card encryption is not a solution as the contents are not readable on other platforms, nor recoverable if the phone fails or needs a reset.
Use case is protecting data, mostly pictures, from phone thief/finder, not from a gvt agency or police. My understanding is that most encryption methods are broken on Android for these purposes as the keys are often accessible from memory. In that sense, the phone is considered trusted once unlocked, so encryption should be transparent so that files are accessible via standard phone apps (i.e. pictures show in Gallery).


Ideas:


Full disk encryption methods such as Luks. I found this program : EDS which apparently can mount Luks volume if the phone is rooted. I have no idea how efficient this is performance-wise, or if it is safe for the card.
Commercial programs using their own file-based encryption but available on multiple platforms such as Boxcryptor, or Cryptomator. Their purpose is originally to encrypt files before storing them in the cloud. It doesn't seem that I can access files using regular apps using this solution. 
Changing my phone to one on which I can install UbPorts :)
Using Termux and rooting the phone to mount a gocryptfs or other encrypted file system
Using Android default sd card encryption (FDE/FBE), dumping memory to get access to the encryption key and using that from Linux to access files
Other welcome idea !


I cannot find any info about this use case which seems very strange to me.. 

Thank you very much for any input !
FDE

In previous versions Android's default encryption for /data and Adoptable Storage was Full Disk Encryption (FDE) which is a custom implementation of dm-crypt. userdata partition (on FDE as well as FBE) is hard (or impossible) to decrypt off-the-device because of hardware-backed encryption. In case of Adoptable Storage implemented since Android M, key is saved at /data/misc/vold/expand_*.key, you don't need to dump memory but accessing /data requires root. Key is stored unencrypted because of the assumption:


  Because the contents of an adopted storage device are strongly tied to the Android device that adopted it, the encryption keys should not be extractable from the parent device, and therefore the storage device can't be mounted elsewhere.


But if you are already rooted and once you have the key, it's possible to decrypt the SD Card on a Linux machine using dmsetup. Also note that removing physical SD Card will break your /sdcard and the apps you would have moved.

FBE

Recent versions of Android mostly use File Based Encryption (FBE) which bases on Linux filesystem encryption (for ext4 and f2fs). It doesn't use a single key, instead the master key generates per file (per inode in fact) keys on the go. On Android encrypted master key is saved to /data/misc/vold/user_keys/de/ and /data/misc/vold/user_keys/ce/ along with other related files. Further subdirectories are named after the UserID e.g. 0 for device owner. Here de is for Device Encrypted storage which is entirely hardware-based encrypted and is available at boot without user interaction. ce is Credential Encrypted storage which requires user PIN/password for decryption in addition to hardware-backed key. Different directories on /data partition are (not encrypted or) encrypted with different keys; DE or CE, for user 0 or user 10 and so on.

So each user has 2 encrypted keys - one for CE and the other for DE - just like the encrypted key stored to the footer of userdata partition as in the case of FDE. The keys can't be simply used for decrypting files on PC as opposed to a single key required to decrypt whole block device in case of FDE Adoptable Storage. Also FBE with Adoptable Storage doesn't work on Nougat and Oreo, and doesn't look very stable on Pie. I'm not sure how it's gonna work when things get streamlined. If some implementations store unencrypted (CE/DE) master keys in /data/misc/vold/user_keys/, there would be higher chances for FBE to work across multiple platforms.

OTHER OPTIONS

If you don't want to go with Android's native FDE or FBE, you can manually setup dm-crypt (plain / LUKS), or try FUSE-based solutions first like encfs or gocryptfs; they are relatively simpler. Binaries are available here.

FBE can be manually managed with fscrypt tool but I don't think that would be a very feasible option at the moment. You may give a try though.

ecryptfs is another Linux kernel's native feature. Android by default never used ecryptfs AFAIK, so it depends on ROM builder if they built kernel with CONFIG_ECRYPT_FS=y or not. You might need to rebuild kernel.

All of the above options work well but all need root access and manual configuration on Android e.g. an init.d script, or a third party solution.

Or if you just want to encrypt selected directories and not the whole SD card, give MiXplorer a try. It includes Java port of encfs which doesn't require root. However directory decrypted in MiXplorer won't be accessible to other apps. For Boxcrypter type of use case, I prefer rclone because it's open-source.

RELATED:


Decrypting microSD card on another Android device or desktop computer