Question: From NSData to SecKeyRef in swift 2

Question

From NSData to SecKeyRef in swift 2

Answers 1
Added at 2016-12-28 22:12
Tags
Question

I have a public/private key pair generated with RSACryptor.swift I am able to convert my public key into a base64 string to be stored on my server.

I want to retrieve the public key on an other iOS device and use it to encrypt a message.

I am able to convert the base64 key to an NSData

let decodedData = NSData(base64EncodedString: publicKeyBase64!, options:NSDataBase64DecodingOptions(rawValue: 0))

But I can't find how to convert it into a SecKeyRef so I can use it easily.

Answers I found were in Objectiv-C and outdated.

Thanks for your help !

Answers
nr: #1 dodano: 2016-12-30 00:12

I think to obtain your SecKeyRef you need to retrieve it from a keychain. So you maybe need to obtain a SecKeychainItemRef, which need to be created from a key chain.

For that, you can import your key to your keychain with SecItemImport:

Converts an external representation of a keychain item or items into SecKeychainItem objects and optionally imports them into a specified keychain.

Source Show
◀ Wstecz