static SafeSecIdentityHandle ImportIdentity(byte[] data, string password) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (string.IsNullOrEmpty(password)) // SecPKCS12Import() doesn't allow empty passwords. { throw new ArgumentException(nameof(password)); } Initialize(); using (var pwstring = CFString.Create(password)) using (var optionDict = CFDictionary.FromObjectAndKey(pwstring.Handle, ImportExportPassphase.Handle)) { var result = ImportPkcs12(data, optionDict, out var array); if (result != SecStatusCode.Success) { throw new InvalidOperationException(result.ToString()); } return(new SafeSecIdentityHandle(array [0].GetValue(ImportItemIdentity.Handle))); } }
public static SecIdentity Import(byte[] data, string password) { if (data == null) { throw new ArgumentNullException("data"); } if (string.IsNullOrEmpty(password)) // SecPKCS12Import() doesn't allow empty passwords. { throw new ArgumentException("password"); } using (var pwstring = CFString.Create(password)) using (var options = CFDictionary.FromObjectAndKey(pwstring.Handle, ImportExportPassphase.Handle)) { CFDictionary [] array; SecStatusCode result = SecImportExport.ImportPkcs12(data, options, out array); if (result != SecStatusCode.Success) { throw new InvalidOperationException(result.ToString()); } return(new SecIdentity(array [0].GetValue(ImportItemIdentity.Handle))); } }
static CFDictionary CreateImportOptions(CFString password, ImportOptions options = null) { if (options == null) { return(CFDictionary.FromObjectAndKey(password.Handle, ImportExportPassphase.Handle)); } var items = new List <Tuple <IntPtr, IntPtr> > (); items.Add(new Tuple <IntPtr, IntPtr> (ImportExportPassphase.Handle, password.Handle)); #if !MONOTOUCH if (options.KeyChain != null) { items.Add(new Tuple <IntPtr, IntPtr> (ImportExportKeychain.Handle, options.KeyChain.Handle)); } if (options.Access != null) { items.Add(new Tuple <IntPtr, IntPtr> (ImportExportAccess.Handle, options.Access.Handle)); } #endif return(CFDictionary.FromKeysAndObjects(items)); }
public SecRecord(SecKind secKind) { var kind = SecClass.FromSecKind(secKind); queryDict = CFDictionary.FromObjectAndKey(kind, SecClassKey); }