3

Our Swift app uses Realm (10.7.6) and it's encrypted. I'd like to open the .realm file in Realm Studio (10.1.2) but it's asking for the "128-character hex-encoded encryption key". I'm not sure where to get this.

Btw, in my test app I can open that .realm file with Realm Studio if I don't encrypt so the versions of RealmSwift and Realm Studio are compatible.

To encrypt the Realm in the app I'm using the getKey() code from the Realm docs here. The key that gets generated in that code is only 64 bytes, not 128 which is what Realm Studio is asking for. If I print(key) I get "64 bytes" in the console. If I add a breakpoint and po key it's not much better:

▿ 64 bytes
  - count : 64
  ▿ pointer : 0x0000600003a14160
    - pointerValue : 105553177166176

Where do I get the "128-character hex-encoded encryption key" that Realm Studio is asking for?


Update: As mentioned in Jay's answer below, I used Johannes Lund's answer from here to convert the Data object to a hex string. Sure enough, I could take that string and paste it into that Realm Studio window.

Sadly, as documented on the Realm site, you can't have an encrypted Realm open in multiple processes. I've been using Realm Studio to help test our collection observers but now we'll have to do that another way.

Murray Sagal
  • 8,454
  • 4
  • 47
  • 48

1 Answers1

0

The encryption key is an NSData (Data) object. You can make an NSString object of the key that represents that data as hexadecimal values. You can then use that string with Realm Studio

I generally post code based answers but there are already a lot of examples here on SO for mapping Data to a Hex String. Check out the Swift 5 answers to this question. There are a lot of other options for Swift 4 and above as well. And this one.

Jay
  • 34,438
  • 18
  • 52
  • 81