locked
Using Windows.Devices.SmartCards API give 'System.UnauthorizedAccessException'

    Question

  • Hi everybody,

    In the past I used the Windows.Devices.SmartCards APIs for Windows Phone 8.1 with success (https://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.smartcards.aspx).

    Now i want to use the same APIs to connect my PC (Windows 8.1) to a SmartCardReader (e.g. ACR122) and read some data from a SmartCard.

    Unfortunately, when i use those APIs, a System.UnauthorizedAccessException is launched.

    How can i resolve it?

    Many thanks!

    This is the code:

    	private async Task getSmartCardReader()
            {
                string selector = SmartCardReader.GetDeviceSelector(SmartCardReaderKind.Generic);
    
                DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector);
    
                Debug.WriteLine("Number of devices: "+devices.Count.ToString());
    
                if (devices != null && devices.Count != 0)
                {
                    foreach (DeviceInformation s in devices)
                    {
                        try
                        {
                            Debug.WriteLine("Device Id: "+s.Id);
                            Debug.WriteLine("Device Name: " + s.Name);
                            Debug.WriteLine("Is Device Enabled: " + s.IsEnabled);
    
    			//Here is the line that launches exception
                            SmartCardReader reader = await SmartCardReader.FromIdAsync(s.Id);
    
                        }
                        catch (Exception e) {
                            Debug.WriteLine(e.StackTrace);
                        }
                    }
                }
            }


    • Edited by NicolòV Thursday, March 26, 2015 1:09 AM
    Wednesday, March 25, 2015 6:29 PM

Answers

  • Does checking "Share User Certificates" in the capabilities help at all?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by NicolòV Wednesday, April 01, 2015 2:54 PM
    Wednesday, March 25, 2015 7:41 PM
    Moderator

All replies

  • Does checking "Share User Certificates" in the capabilities help at all?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by NicolòV Wednesday, April 01, 2015 2:54 PM
    Wednesday, March 25, 2015 7:41 PM
    Moderator
  • Great! It works, but there is another problem:

    With Windows Phone 8.1 you have the SmartCardConnection class through which you can send APDU to the Smartcard

    SmartCardConnection connection = await card.ConnectAsync();

    var responseBuf = await connection.TransmitAsync(dw.DetachBuffer());


    In Windows 8.1 API there is no such class, so there is no way to send APDU to the smartcard.

    Is there any workaround?

    Friday, March 27, 2015 3:19 PM
  • No solution for that?
    Monday, March 30, 2015 7:38 AM