MongoDB Realm Encryption with Android Keystore System?

I’ve been trying to securely encrypt the data inside my local MongoDB Realm, but I’m having troubles, because I’m not sure how should I safely store the key inside the Android Keystore System, and pass that generated key as a bytearray to the MongoDB configuration?

As far as I know, we are not able to retrieve the bytearray of a generated key from the Android Keystore. So how are we supposed to safely and securely generate the encryption key and encrypt our local MongoDB Realm?

I’ve been searching for a solution for days, but haven’t been able to find any article/guide on this one.
I would appreciate any help! Thank you!

Encrypting data in a local MongoDB Realm database on Android involves generating and securely storing an encryption key. While Android Keystore provides a secure mechanism for generating and storing keys, it does not directly allow retrieval of the key as a bytearray. Instead, you can retrieve the key as a Key object and use it to perform encryption and decryption operations.