Last active
June 5, 2018 17:45
-
-
Save scottcarter/356a3ac66be048216ac75df42da94959 to your computer and use it in GitHub Desktop.
Log or delete keychain items for app
This file contains hidden or 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
import Foundation | |
// Log and/or delete keychain items for app. | |
// | |
// Credit to: | |
// https://bootstragram.com/blog/deleting-keychain-items/ | |
// | |
public class KeychainDebug: NSObject { | |
@objc public class func iterateKeychainItems(log: Bool, delete: Bool) { | |
let secItemClasses = [ | |
kSecClassGenericPassword, | |
kSecClassInternetPassword, | |
kSecClassCertificate, | |
kSecClassKey, | |
kSecClassIdentity | |
] | |
if (log) { | |
for secItemClass in secItemClasses { | |
let query: [String: Any] = [ | |
kSecReturnAttributes as String: kCFBooleanTrue, | |
kSecMatchLimit as String: kSecMatchLimitAll, | |
kSecClass as String: secItemClass | |
] | |
var result: AnyObject? | |
let status = SecItemCopyMatching(query as CFDictionary, &result) | |
if status == noErr { | |
print(result as Any) | |
} | |
} | |
print("AppUsageMetadata.iterateKeychainItems ended.") | |
} | |
if (delete) { | |
for secItemClass in secItemClasses { | |
let dictionary = [kSecClass as String:secItemClass] | |
SecItemDelete(dictionary as CFDictionary) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment