Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin iOS: unable save PKCS12 data in the iOS keychain

Use case:

The app imports PKCS 12 file (with cert and private key) and saves it for later use.

Current status:

I was able to use SecImportExport.ImportPkcs12 in order to get SecIdentity and SecTrust objects. Unfortunately I’m unable to assign SecIdentity and SecTrust object to SecRecord.

The code:

SecIdentity identityObject = ...;
SecTrust trustObject = ...;

SecRecord record = new SecRecord(SecKind.Identity);
record.Account = "Identity";
record.ValueData = ?   //HOW TO CONVERT SecIdentity to NSData?

var res = SecKeyChain.Add(record);
like image 366
kmalmur Avatar asked Nov 10 '22 06:11

kmalmur


1 Answers

You can use the SecRecord.SetValueRef (identityObject) which can be used to store keys (SecKey), certificates (SecCertificate) or identities.

like image 160
miguel.de.icaza Avatar answered Nov 14 '22 21:11

miguel.de.icaza