question

15374283 avatar image
0 Votes"
15374283 asked NicoZhu-MSFT answered

UWP can't get certificates when choose 'CurrentUser'

I wanna get certificates in a UWP project. As the following link
https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.x509certificate2ui.selectfromcollection?redirectedfrom=MSDN&view=windowsdesktop-5.0#overloads
Because UWP doesn't have the 'X509Certificate2UI', so I write UI myself. But still has a problem

the code below

X509Store store = new X509Store("MY",StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;

works well in a WPF project, the 'collection' has about 600 certificates,
but in a UWP project, 'collection' has 0 certificate.


if I change 'StoreLocation.CurrentUser' to 'StoreLocation.LocalMachine' in first line,
the results of 'collection' in WPF and UWP are the same

Don't know why? Are there some problems in my environment?

windows-uwp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

NicoZhu-MSFT avatar image
0 Votes"
NicoZhu-MSFT answered

Hello,
Welcome to Microsoft Q&A!

Please open app's appxmanifest file and find Capabilities option, check if enable Shared User Certificates option. The sharedUserCertificates capability enables an app to add and access software and hardware-based certificates in the Shared User store. For more info please refer to App capability declarations document


Thank you.



If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.