realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.78k stars 574 forks source link

Error: Realm at path 'path/to/realm' already opened with a different encryption key. #2331

Closed kenkotch closed 5 years ago

kenkotch commented 5 years ago

Goals

read and write to encrypted realm

Expected Results

can encrypt, read and write

Actual Results

on android: Error: Realm at path 'path/to/realm' already opened with a different encryption key. (when trying to write) on ios: Unable to open realm at path '': Realm file decryption failed Path:. (when building)

iOS: Unable to open a realm at path '/Users/iguana/Library/Developer/CoreSimulator/Devices/116618B3-440A-4852-A412-B81CC062E752/data/Containers/Data/Application/504E3B95-597C-480B-A27A-F97136CC6E94/Documents/standardObject.realm': Realm file decryption failed Path:.

StandardObject.js:52:47 loadModuleImplementation require.js:331:6 index.js:1 loadModuleImplementation require.js:331:6 index.js:8 loadModuleImplementation require.js:331:6 Login.js:21 loadModuleImplementation require.js:331:6 RouterLogin.js:6 loadModuleImplementation require.js:331:6 App.js:4 loadModuleImplementation require.js:331:6 index.js:6 loadModuleImplementation require.js:331:6 guardedLoadModule require.js:197:45 global code :0 ![Simulator Screen Shot - iPhone X - 2019-04-10 at 15 35 59](https://user-images.githubusercontent.com/4110008/55915217-62b15b80-5ba6-11e9-94fe-6d9d1053227d.png)

Andriod: ![Screenshot_1554926299](https://user-images.githubusercontent.com/4110008/55909255-c16fd880-5b98-11e9-9389-789f4b03e26e.png) ## Steps to Reproduce on ios, fails on build on android fails on write to realm both are solved when I remove the encryptionKey ## Code Sample ``` const string = 'N60LgDmG4CuwC9Gb/qdgBvjR0bfRjN4NzPfRwmFj960//+EDlTSGpYwA1V83XDepAT+Dv/wFZL1cqvuIAZjbzw==' const encryptionKey = base64js.toByteArray(string) const standardObjectSchema = { path: 'standardObject.realm', schema: [standardObject, locationObject], schemaVersion: 0, encryptionKey } export const newStandardObject = new Realm(standardObjectSchema) ``` ## Version of Realm and Tooling - Realm JS SDK Version: ? "realm": "^2.26.0" - Node or React Native: ? "react": "16.8.3" "react-native": "0.59.3" - Client OS & Version: ? iOS: 12 Android: 9 - Which debugger for React Native: ?/None Flipper
kenkotch commented 5 years ago

just made a new proj w/ realm. same issue: https://github.com/kenkotch/realmEncryptionTest

kenkotch commented 5 years ago

~~I handled the issue, though I would still like to know why the solution works. Instead of adding the encryptionKey directly in standardObjectSchema, when I mount my first component where I import newStandardObject in componentDidMount, I add: newStandardObject.encryptionKey = base64js.toByteArray(string)~~ nope. im wrong. that does not work. still getting the same error

rajivshah3 commented 5 years ago

Could this be related to https://github.com/realm/realm-core/issues/3267?

kenkotch commented 5 years ago

It may be. That project is long gone so I'm not actively looking into anymore