Opening an Encrypted Realm in Realm Studio


(michael p) #1

There is no documentation about opening Realm Studio with an encrypted realm. My realm encrypted key is this:

{ ‘0’: 89,
‘1’: 45,
‘2’: 41,
‘3’: 46,
‘4’: 5,
‘5’: 7,
‘6’: 50,
‘7’: 37,
‘8’: 52,
‘9’: 36,
‘10’: 11,
‘11’: 96,
‘12’: 5,
‘13’: 42,
‘14’: 6,
‘15’: 17,
‘16’: 13,
‘17’: 3,
‘18’: 48,
‘19’: 54,
‘20’: 17,
‘21’: 61,
‘22’: 72,
‘23’: 91,
‘24’: 27,
‘25’: 55,
‘26’: 67,
‘27’: 19,
‘28’: 77,
‘29’: 31,
‘30’: 96,
‘31’: 39,
‘32’: 57,
‘33’: 46,
‘34’: 24,
‘35’: 38,
‘36’: 64,
‘37’: 90,
‘38’: 68,
‘39’: 40,
‘40’: 39,
‘41’: 96,
‘42’: 89,
‘43’: 92,
‘44’: 98,
‘45’: 88,
‘46’: 47,
‘47’: 7,
‘48’: 8,
‘49’: 33,
‘50’: 56,
‘51’: 24,
‘52’: 84,
‘53’: 92,
‘54’: 79,
‘55’: 96,
‘56’: 15,
‘57’: 10,
‘58’: 67,
‘59’: 15,
‘60’: 13,
‘61’: 66,
‘62’: 25,
‘63’: 79 }

I have read on assorted github issues and stack overflow pages that this should be encrypted with hex encryption to use in realm studio. Who knows if this is true because there is no documentation but I can’t paste this string into an hex converter and get it to work.

The Question: how do i format my working encryption key to Realm Studio to debug my database?


(michael p) #2

Use the below recipe to hex encode the encryption key string for use in Realm Studio:

function parseHexString(str) { 
    var result = [];
    while (str.length >= 8) { 
        result.push(parseInt(str.substring(0, 8), 16));

        str = str.substring(8, str.length);
    }

    return result;
}

function createHexString(arr) {
    var result = "";
    var z;

    for (var i = 0; i < arr.length; i++) {
        var str = arr[i].toString(16);

        z = 8 - str.length + 1;
        str = Array(z).join("0") + str;

        result += str;
    }

    return result;
}

via https://stackoverflow.com/questions/14603205/how-to-convert-hex-string-into-a-bytes-array-and-a-bytes-array-in-the-hex-strin

Note: You must move the *.realm file to a public folder on your computer! You cannot open the file inside a private directory (ex: where iOS simulator stores .realm files for installed apps). If you try to do so, Realm Studio will just show a white screen and won’t ask for the encryption key.


(Kræn Hansen) #3