繁体   English   中英

跨应用程序钥匙串访问,在哪里配置?

[英]Cross-App Keychain Access, where to configure?

我目前正在开发多个跨平台应用程序(在iOS下),这些应用程序使用一些共享的钥匙串条目。 我目前的专案是从android开始的,在有了可用的版本后,我继续在iOS版本上进行作业。 我从较早的项目中导入了钥匙串访问代码,以访问共享的登录数据。 只有这次查询总是返回SecStatusCode.ItemNotFound。

我比较了配置文件和权利,并且看起来都一样。 一段时间后,我发疯了,我创建了一个新的空应用程序,其中仅包含钥匙串代码,与当前不工作的应用程序相同的捆绑包标识符,配置文件和权利文件,并且可以正常工作并返回我的数据。

我的问题是,除了entitlements.plist和供应配置文件之外,还有什么地方需要配置,这可能会干扰我对钥匙串条目的访问? 由于项目更大,所以我不想将所有代码复制到新项目中。 我尝试了Windows的Visual Studio 2017和Mac 2019的VS。这是一个内部/企业应用程序,它引起任何关注...

钥匙串通话:

KeyChain kc = new KeyChain("USER_DATA", "de.rlp.myCompany.Shared");
var data = kc.Find("LOGIN_DATA");

钥匙扣级:

public class KeyChain
{
    public string ServiceName { get; set; }
    public string GroupName { get; set; }

    public KeyChain(string serviceName, string groupName = null)
    {
        ServiceName = serviceName;
        GroupName = groupName;
    }

    public byte[] Find(string key)
    {
        SecStatusCode res;
        var rec = PrepareDictionary(key);
        var match = SecKeyChain.QueryAsRecord(rec, out res);
        if (res == SecStatusCode.Success) // ItemNotFound return-code here
        {
            return match.ValueData.ToArray();
        }
        else
        {
            System.Diagnostics.Debug.Write(res.ToString()); 
        }
        return null;
    }

    private SecRecord PrepareDictionary(string key)
    {
        var sr = new SecRecord(SecKind.GenericPassword)
        {
            Service = this.ServiceName,
            Generic = NSData.FromString (key),
            Account = key,
            Accessible = SecAccessible.AlwaysThisDeviceOnly
        };
        if (string.IsNullOrEmpty(GroupName))
        {
            sr.AccessGroup = GroupName;
        }
        return sr;
    }

}

权利入境

<key>keychain-access-groups</key>
<array>
    <string>$(AppIdentifierPrefix)de.rlp.myCompany.Shared</string>
</array>

您是否已将两个应用程序从权利中添加到同一个应用程序组/钥匙串组中并启用了它。

VS可能是越野车。 只需在Apple开发人员网站上检查两个应用程序的权利即可。 那可能是问题所在。

文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM