Created
August 10, 2016 07:43
-
-
Save kaspermunck/9b1dcbf07773b22e109eefd552200e00 to your computer and use it in GitHub Desktop.
Creating encrypted Realm and attempting to catch any exception thrown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var configuration = Realm.Configuration.defaultConfiguration | |
let encryptionKey = NSMutableData(length: 64)! | |
SecRandomCopyBytes(kSecRandomDefault, encryptionKey.length, UnsafeMutablePointer<UInt8>(encryptionKey.mutableBytes)) | |
configuration.encryptionKey = encryptionKey | |
let filename = "private.realm" | |
let fileURL = configuration.fileURL?.URLByAppendingPathComponent(filename) | |
configuration.fileURL = fileURL | |
var realm: Realm! | |
do { | |
realm = try Realm(configuration: configuration) | |
} | |
catch let error { | |
// handle exception | |
} | |
// Throws `libc++abi.dylib: terminating with uncaught exception of type realm::RealmFileException: Unable to open a realm at path '.../private.realm': Realm file decryption failed.` when wrong encryption key is used. Expected it would be caught. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment