none
RSACryptoServiceProvider accessing Smart card issue on Win7 64 (.NET 4.5.1) RRS feed

  • Question

  • I have a program written in .NET 4.5.1 that uses RSACryptoServiceProvider to sign content using a smart card. It all works great on Windows 8.1 64-bit, Server 2012 64-bit and Windows 7 SP1 32-bit. However, on Windows 7 SP1 64-bit, it throws "The requested key container does not exist on the smart card" exception when initializing RSACryptoServiceProvider. I tried that on two Win7-64 computers running .NET 4.5.2 with same results (I've tested .NET 4.5.2 on Win8-64 and Win7SP1-32, and they still work, so it's not a .NET version issue).

    The thing is, there is an other program that uses some other way to communicate with the same CSP (I assume it uses an older Windows API library, could be CAPICOM or CryptoAPI), and it works fine on Win7SP1-64 and Win8-64. So the CSP drivers are fine on these Win7-64 computers because other methods can access and use them. That means that there is something inherently wrong in the combination of Windows 7 SP1 64-bit and RSACryptoServiceProvider. Does anyone have an idea about how to fix this issue?
    • Edited by ewzer Saturday, August 15, 2015 6:34 PM
    Friday, August 14, 2015 6:39 PM

All replies

  • Hi ewzer,

    >> However, on Windows 7 SP1 64-bit, it throws "The requested key container does not exist on the smart card" exception when initializing RSACryptoServiceProvider

    Do you have any code to show us?  Please also make sure your Win7 64 is a clean environment. I wonder if there is any other library or third-party product have effects.

    I would suggest you provide a simplified sample about this issue, It would be better to help us to figure out the root cause.

    Best regards,

    Kristin

     


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, August 17, 2015 3:13 AM
  • This is what I do:

    X509Certificate2 Certificate = getCertificate();
    
    Oid oid = new Oid("1.3.14.3.2.26");
    
    RSACryptoServiceProvider csp = (RSACryptoServiceProvider)Certificate.PrivateKey;
    RSAPKCS1SignatureFormatter RSA15Formatter = new RSAPKCS1SignatureFormatter(csp);
                   RSA15Formatter.SetHashAlgorithm(oid.FriendlyName); //("SHA1");
    
    SHA1Managed sha = new SHA1Managed();
    byte[] HashToSign = sha.ComputeHash(data);
    byte[] Signature = RSA15Formatter.CreateSignature(HashToSign);

    Throws The requested key container does not exist on the smart card exception on three computers running Windows 7 SP1 64 bits (haven't tried other w7sp1-64).

    Certificate is on a smart card. Tried two smart cards.

    Some computers had .NET Framework 4.5.1, some had 4.5.2.

    However, an other program (not .NET based) manages to access the certificate on the smart card and generate signatures. So smart card drivers are fine.

    Same thing done on other versions of Windows works flawlessly (Win7 SP1 32, Win8.1 64, Win2012 64).

    Unfortunately, I am not sure if there are any third party libraries. I mean, it doesn't look so. There are lots of updates installed (Windows is up-to-date).


    When looking for The requested key container does not exist on the smart card on google, I found that it seems like some people get this error after having installed some hotfixes to solve other issues. Unfortunately, I don't know the names of the hotfixes because these people were discussing Server versions of Windows.

    Tuesday, August 18, 2015 10:24 AM
  • Hi ewzer,

    I am trying to involve someone to further look at this issue. There might be some time delay. Appreciate your patience and thanks for your understanding.

    Since this issue also related to Smart Card,  I would suggest you repost this issue in Smart Device Development >  Visual Studio Smart Device Development - Native C++ Project   forum for some possible solution.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, August 20, 2015 1:56 AM