2013-08-27 2 views
3

핵심 데이터 용으로 생성 된 SQLite 파일의 보호 수준을 구성 할 수 있습니까?MagicalRecord를 이용한 핵심 데이터 암호화

레벨이 NSFileProtectionComplete이어야합니다.

아이디어가 있으십니까? 당신이 addPersistentStoreWithType:configuration:URL:options:

NSURL *storeURL = ...; 

NSError *error = nil; 
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:...]; 
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType 
               configuration:nil 
                 URL:storeURL 
                options:nil 
                 error:&error]) 
{ 
    NSLog(@"Add persistent store failed: %@", error); 
} 

를 수행 라인

+0

다음은 sqlcipher 및 magical record에 관한 질문 (http://stackoverflow.com/questions/18365375/ios-magical-record-sqlcipher)입니다. 어쩌면 이것은 적절한 해결책을 제공 할 것입니다. – casademora

답변

3

봐 그런 다음 추가,

NSDictionary *attributes = @{NSFileProtectionKey: NSFileProtectionComplete}; 
if (![[NSFileManager defaultManager] setAttributes:attributes 
             ofItemAtPath:path 
              error:&error]) { 
    NSLog(@"File protection failed: %@", error); 
} 

당신이 백그라운드에서 데이터베이스를 사용할 수 없다는 것을 유의 사용을 고려 NSFileProtectionCompleteUnlessOpen :

  • NSFileProtectionComplete : 파일이 저장됩니다. 디스크의 암호화 된 형식이며 장치가 잠겨 있거나 부팅되는 동안 읽거나 쓸 수 없습니다.
  • NSFileProtectionCompleteUnlessOpen : 파일은 디스크에 암호화 된 형식으로 저장됩니다. 장치가 잠긴 상태에서 파일을 만들 수 있지만 장치를 잠그면 장치를 잠금 해제 할 때까지 다시 열 수 없습니다. 잠금 해제 된 상태에서 파일을 열면 사용자가 장치를 잠근 경우에도 파일에 정상적으로 계속 액세스 할 수 있습니다. 파일을 작성하고 열 때 쓰거나 읽지 않을 때 성능이 저하 될 수 있습니다. 장치를 잠금 해제 할 때 파일 보호를 NSFileProtectionComplete으로 변경하면이 문제를 완화 할 수 있습니다.
+0

전체 애플 리케이션을위한 데이터 보호를 켜는 것이 훨씬 쉽고 권장됩니다 (역 접지 문제에 적응할 수 있다면). http://stackoverflow.com/questions/18326225/ fmdb 및 암호화/18414100 # 18414100 –

+0

고마워요! MagicalRecord를 사용하고 있지만 이것이 나에게 도움이되었습니다! :) –

+1

이것은 MagicalRecord로 어떻게 이루어 집니까? – lostintranslation

관련 문제