Created
June 29, 2020 01:13
-
-
Save cardosoedgar/665c07da004734153093b4e5dafe6ab4 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
let ellipticCurveHeader = [UInt8]([0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, | |
0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, | |
0x01, 0x07, 0x03, 0x42, 0x00]) | |
let begin = "-----BEGIN PUBLIC KEY-----\n" | |
let end = "\n-----END PUBLIC KEY-----" | |
func retrivePublicKey() -> String? { | |
var error: Unmanaged<CFError>? | |
if let publicKey = getPublicKey(), | |
let keyRef = SecKeyCopyExternalRepresentation(publicKey, &error) { | |
var keyData = Data() | |
keyData.append(Data(ellipticCurveHeader)) | |
keyData.append(keyRef as Data) | |
let b64Key = keyData.base64EncodedString(options: [.lineLength64Characters, | |
.endLineWithCarriageReturn]) | |
return "\(begin)\(b64Key)\(end)" | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment