How to delete Keychain data when app is uninstalled? [duplicate]
Asked Answered
O

2

12

I have a problem . I am saving some critical information on device Keychain for my App, but when I uninstall the App and install it again, these data is still saved. How can delete these information when the application is uninstalled? If this is not possible, how detect when the App is first Load after install it without save information in NSUserDefaults?

Thank you very much.

Offensive answered 3/1, 2014 at 12:56 Comment(7)
https://mcmap.net/q/108549/-delete-keychain-items-when-an-app-is-uninstalled/653513Subplot
Why don't you want to use NSUserDefaults to store whether or not your application is started for the first time?Wizened
you cannot do anything when the application is removed from the device, the application won't be notified about that event.Turgid
Because I am saving critical information and I don't want that someone can edit the preferences plist with any program as iExplorer. If someone change any value the consequences could be very badOffensive
@Paolpa, in that case, you should use some encryption then... e.g. AES256 is good enough to protect your critical information.Turgid
Theoretically keychain is safe enough, right?Offensive
@Paolpa, you problem is here not the safety, your original problem was about you want to delete information when the application is deleted/uninstalled; which is not possible.Turgid
L
5

This is work around , but may be will satisfy you: Store in NSUserDefaults flag, that keychain have data. If it's NO then ignore keychain.

Lavoie answered 3/1, 2014 at 13:16 Comment(5)
You should not use NSUserDefaults for sensitive data like passwords or certificates.Bruise
@orkoden, anybody have said about storing passwords in NSUserDefaults? I am not.Lavoie
@ta.speot.is, Have you minused answer in #4747904? It's the same, but shorter.Lavoie
Sorry, I misread your answer. I can't take back my downvote because I downvoted you a few hours ago, but if you make a small edit to your answer I can upvote it.Virilism
I disagree to save critical information in UserDefaults.Emoryemote
A
0

I'm not sure why you would not want to use NSUserDefaults. It seems ideal for this purpose.

Barring NSUserDefaults, you could write a file to the Documents directory and use the existence of this file as your flag.


I think I misunderstood your question. I assume the whole time you would use the keychain to store the secure value.

Use a flag in NSUserDefaults to signal that you need to delete the keychain on first launch.


As a real alternative to Keychain, use the Data Protection entitlement.

Algonquian answered 3/1, 2014 at 13:2 Comment(3)
NSUserDefault are not secure, it makes more sense to store it in a more save place like he KeyChain since the NSUserDefault are just stored as plain text.Adornment
@Adornment I updated my answer. I think you want to use Data Protection.Algonquian
Thank you Jeffery Thomas, very good alternative!Offensive

© 2022 - 2024 — McMap. All rights reserved.