You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacOS下MAUI App无法读取系统证书的问题求助

问题:MAUI App在MacOS上无法读取本地证书

环境信息

  • 操作系统:MacOS 13.6.3
  • 开发工具:Visual Studio 2022(版本17.6.10)
  • 测试项目:MAUI App(与控制台应用对比测试)

MAUI App中读取证书的代码

foreach (StoreLocation storeLocation in (StoreLocation[])Enum.GetValues(typeof(StoreLocation)))
{
    foreach (StoreName storeName in (StoreName[])Enum.GetValues(typeof(StoreName)))
    {
        X509Store store = new X509Store(storeName, storeLocation);

        try
        {
            store.Open(OpenFlags.OpenExistingOnly);

            Console.WriteLine("Yes    {0,4}  {1}, {2}",
                store.Certificates.Count, store.Name, store.Location);

            s += $"Yes    {store.Certificates.Count}  {store.Name}, {store.Location}" + Environment.NewLine;

            foreach (var c in store.Certificates)
            {
                Console.WriteLine($"name {c.Subject}");
                s += $"name {c.Subject}" + Environment.NewLine;
            }
        }
        catch (CryptographicException)
        {
            Console.WriteLine("No           {0}, {1}",
                store.Name, store.Location);
            s += $"No {store.Name} {store.Location}" + Environment.NewLine;
        }
    }
}

MAUI App的执行输出

No AddressBook CurrentUser
No AuthRoot CurrentUser
No CA CurrentUser
Yes 0 Disallowed, CurrentUser
Yes 0 My, CurrentUser
No Root CurrentUser
No TrustedPeople CurrentUser
No TrustedPublisher CurrentUser
No AddressBook LocalMachine
No AuthRoot LocalMachine
No CA LocalMachine
No Disallowed LocalMachine
No My LocalMachine
No Root LocalMachine
No TrustedPeople LocalMachine
No TrustedPublisher LocalMachine

控制台应用的执行输出

No AddressBook, CurrentUser
No AuthRoot, CurrentUser
No CA, CurrentUser
Yes 0 Disallowed, CurrentUser
Yes 50 My, CurrentUser
Yes 0 Root, CurrentUser
No TrustedPeople, CurrentUser
No TrustedPublisher, CurrentUser
No AddressBook, LocalMachine
No AuthRoot, LocalMachine
No CA, LocalMachine
Yes 0 Disallowed, LocalMachine
Yes 4 My, LocalMachine
Yes 158 Root, LocalMachine
No TrustedPeople, LocalMachine
No TrustedPublisher, LocalMachine

疑问

使用相同的代码,控制台应用可以正常读取到本地证书,但MAUI App却无法获取到有效结果,原因是什么?

内容的提问来源于stack exchange,提问作者MaxTC

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 17:35:58