Created
March 15, 2021 23:23
-
-
Save mkaraoz/2e22f17f5c0a5366938f3c1e7a5d92ed 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
| func sign(text2sign : String) throws -> Data { | |
| var error: Unmanaged<CFError>? | |
| let privateKey = try! retrievePrivateKey() | |
| let algorithm: SecKeyAlgorithm = .ecdsaSignatureMessageX962SHA512 | |
| guard SecKeyIsAlgorithmSupported(privateKey, .sign, algorithm) else { | |
| throw error!.takeRetainedValue() as Error | |
| } | |
| let data2sign = text2sign.data(using: .utf8)! | |
| // create the signature | |
| guard let signature = SecKeyCreateSignature(privateKey, algorithm, data2sign as CFData, &error) as Data? else { | |
| throw error!.takeRetainedValue() as Error | |
| } | |
| print("Signature: " + signature.base64EncodedString()) | |
| return signature; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment