Realm Studio with Encryption


#1

Is viewing an encrypted realm supported in Realm Studio?


Open an encrypted realm on OSX
#2

Yes, but you need to provide the encryption key hex encoded. See e.g. this Java example here: https://github.com/realm/realm-java/blob/master/examples/encryptionExample/src/main/java/io/realm/examples/encryption/EncryptionExampleActivity.java#L51


#3

Hi there. I’m also having a problem opening a Realm database in Realm Studio after encrypting it.

I am using Realm in a Xamarin Forms project using C#. The saving and reloading in the App itself works fine (I’m storing the key as a base64 encoded string using Xamarin.Auth and converting it back and it works as intended). But when I copy the DB from my emulator to my laptop and try and open the database using the HEX string generated in my log statements, it says 'Unable to open a realm at path : Realm file decryption failed.

The HEX generated is the same from both the initial generation of the byte key and the reloading of it.

I don’t usually code in C#, so I apologise if it’s a stupid error, but as far as I can tell I’m encrypting as per the example you’ve given, and logging the HEX correctly.

Any help would be very welcome.

byte[] key = null;

// Try and access the keystore for the Realm encryption key
Account account = AccountStore.Create().FindAccountsForService(Constants.APP_NAME).FirstOrDefault();

if(account != null)
	key = Convert.FromBase64String(account.Properties[ENCRYPTION_KEY_NAME]);

// If it's not available this is the first install. Generate one and store it.
if(key == null)
{
	key = new byte[64];
	var rng = new RNGCryptoServiceProvider();
	rng.GetBytes(key);

	(if account == null)
		account = new Account { Username = Constants.APP_NAME };
	account.Properties.Add(ENCRYPTION_KEY_NAME, Convert.ToBase64String(key));
	AccountStore.Create().Save(account, Constants.APP_NAME);

	this.SafeLog(LogLevel.Debug, $"Generated configuration key: {BitConverter.ToString(key).Replace("-", "")}");
}
else
	this.SafeLog(LogLevel.Debug, $"Loaded configuration key: {BitConverter.ToString(key).Replace("-", "")}");

// Connect to Realm using the encryption key
RealmConfiguration realmConfiguration = new RealmConfiguration()
{
	EncryptionKey = key
};
realm = Realm.GetInstance(realmConfiguration);