Skip to content

Instantly share code, notes, and snippets.

@kaspermunck
Created August 10, 2016 07:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Creating encrypted Realm and attempting to catch any exception thrown.
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