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
相关产品推荐
相关产品推荐

