Last active
October 17, 2022 23:52
-
-
Save cardosoedgar/7b83257c2feaab0b915c1a6a9a00a2f2 to your computer and use it in GitHub Desktop.
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
// if you already have the private key | |
let publicKey = SecKeyCopyPublicKey(privateKey) | |
// if you don't have the private key | |
func getPublicKey() -> SecKey? { | |
let query: [String: Any] = [ | |
kSecClass as String: kSecClassKey, | |
kSecAttrApplicationTag as String: "com.cardosoedgar.key", | |
kSecReturnRef as String: true] | |
var keyRef: CFTypeRef? | |
let status = SecItemCopyMatching(query as CFDictionary, &keyRef) | |
guard status == errSecSuccess else { | |
return nil | |
} | |
let privateKey = keyRef as! SecKey | |
return SecKeyCopyPublicKey(privateKey) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment