-
-
Save chedabob/64a4cdc4a1194d815814 to your computer and use it in GitHub Desktop.
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
// Extract the public key | |
var pub_key_leaf = SecTrustCopyPublicKey(trust!) | |
let keychainTag = "X509_TAG" | |
var publicKeyData : AnyObject? | |
var putResult : OSStatus, delResult : OSStatus = noErr | |
// Params for putting the key first | |
var putKeyParams = NSMutableDictionary() | |
putKeyParams[kSecClass as String] = kSecClassKey | |
putKeyParams[kSecAttrApplicationTag as String] = keychainTag | |
putKeyParams[kSecValueRef as String] = (pub_key_leaf) | |
putKeyParams[kSecReturnData as String] = kCFBooleanTrue // Request the key's data to be returned too | |
// Params for deleting the data | |
var delKeyParams = NSMutableDictionary() | |
delKeyParams[kSecClass as String] = kSecClassKey | |
delKeyParams[kSecAttrApplicationTag as String] = keychainTag | |
delKeyParams[kSecReturnData as String] = kCFBooleanTrue | |
// Put the key | |
putResult = SecItemAdd(putKeyParams, &publicKeyData) | |
// Delete the key | |
delResult = SecItemDelete(delKeyParams) | |
if ((putResult != errSecSuccess) || (delResult != errSecSuccess)) | |
{ | |
publicKeyData = nil; | |
} | |
var keyString = (publicKeyData as! NSData).base64EncodedDataWithOptions(NSDataBase64EncodingOptions()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment