微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Xamarin.iOS绑定库无法使用安全框架中的SecKey API

如何解决Xamarin.iOS绑定库无法使用安全框架中的SecKey API

我从Objective-C框架创建了一个绑定库。它可以工作,但是不能在安全性框架中使用SecKey的加密api。库将其用于api请求。 Xamarin.iOS不完全支持安全框架吗?还是绑定库使用它时不起作用?

注意:顺便说一句,我将此行添加到本机框架中用于依赖:

 <Frameworks>Foundation CFNetwork CoreFoundation Security</Frameworks>

更新1:

这是设备日志:

Trust evaluate failure: [leaf AnchorTrusted]
DemoX[10647]/1#-1 LF=22 add Error Domain=NSOsstatusErrorDomain Code=-34018 "Client has neither application-identifier nor keychain-access-groups entitlements" UserInfo={NSDescription=Client has neither application-identifier nor keychain-access-groups entitlements}
SecTaskLoadEntitlements Failed error=22 cs_flags=200,pid=10438
SecTaskcopyDebugDescription: DemoX[10039]/0#-1 LF=0
nw_protocol_boringssl_signal_connected(728) [C13.1:2][0x7fbe21309f80] TLS connected [version(0x0303) ciphersuite(TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) group(0x001d) signature_alg(0x0601) alpn(http/1.1) resumed(0) offered_ticket(0) false_started(0) ocsp_received(0) sct_received(0) connect_time(1811ms) flight_time(144ms) rtt(72ms) write_stalls(0) read_stalls(5)]    
Trust evaluate failure: [leaf AnchorTrusted]
Trust evaluate failure: [leaf AnchorTrusted TemporalValidity]

更新2:

当我使用XCode运行框架时,以下行会出现,但在我的Xamarin.iOS应用程序中不会出现

inserted <keys,kcls=0,klbl=,atag=5253415574696C5F5075624B6579,crtr=0,type=42,bsiz=0,esiz=0,sdat=2001-01-01 00:00:00 +0000,edat=2001-01-01 00:00:00+0000,agrp=A7PT8PDBPQ.com.test.app,sync=0,musr=,|otherAttr,tomb=0,rowid=9,cdat=2020-11-07 11:02:34 +0000,mdat=2020-11-07 11:02:34+0000,pdmn=ak,sha1=24BB5BBEE125D6A051E08EA2CB72469A0C62042F,v_Data=<?>,UUID=********-****-****-****-************,persistref=,clip=0> from <SecDbConnection rw open>

deleted 
<keys,bsi=,edat=2001-01-01 00:00:00
+0000,rowid=7,cdat=2020-11-07 11:01:55 
+0000,mdat=2020-11-07 11:01:55 +0000,sha1=F1A9A4EC0C5AC67D354C9D7602E118B8DF5EFAF5,accc=310C300A0C0470726F740C02616B,clip=0> from <SecDbConnection rw open>

解决方法

自从找到解决方案以来,我将回答自己的问题。问题背后的原因是SecKeyRef使用KeyChain访问来读取和写入密钥,如官方文档所述:

一个SecKeyRef实例,表示存储在 钥匙串可以安全地转换为SecKeychainItemRef进行操作 作为钥匙串物品。另一方面,如果密钥未存储在 钥匙串,将对象转换为SecKeychainItemRef并将其传递给 钥匙串服务函数返回错误。

在Xcode中具有配置文件以使用SecKeyRef并不重要,但是在Visual Studio Mac中,需要使用Entitlements.plist来启用钥匙串访问。因此,如果您的绑定库使用了SecKey API,则需要在Entitlements.plist中启用KeyChain Access并在项目中设置Apple开发者帐户。

<AppBarToggleButton x:Name="spellCheckingToggleButton" Label="Rechtschreibprüfung">
  <AppBarToggleButton.Content>
    <Image Source="/Assets/SpellChecking2.svg"></Image>
  </AppBarToggleButton.Content>
</AppBarToggleButton>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。