locked
C# PInvoke of CryptImportKey Fails with "Invalid type specified" RRS feed

  • Question

  • Hello Sir or Ma'am,

    I'm trying to use the CryptImportKey function to import a PFX into a Gemalto .NET IDPrime smart cart, but I'm getting a "Invalid Type Specified" (2148073482) error.  I suspect that the RSACryptoServiceProvider.ExportCspBlob(true) call is returning the keys in the wrong format.  I'm using sample code from http://www.idrix.fr/Root/Samples/PfxImporter.cs.  NOTE: I've already set the AllowPrivateExchangeKeyImport & AllowPrivateSignatureKeyImport to 0x1 for the Microsoft Base Smart Card Crypto Provider, but still no change.  I'm running Windows Server 2012, but don't think that is the issue.

    Can someone please tell me what is wrong with this code sample?


    - Rashad Rivera www.omegusprime.com


    Monday, March 23, 2015 6:23 AM

All replies

  • Hi,

    Your issue is certainly caused by the fact that you only changed the Microsoft Base CSP 64-bit registry key and your application is a 32-bit one. 

    To solve your issue, change AllowPrivateExchangeKeyImport & AllowPrivateSignatureKeyImport also under "HKLM\SOFTWARE\Wow6432Node\Microsoft\Cryptography\Defaults\Provider\Microsoft Base Smart Card Crypto Provider".

    I have update PfxImporter.cs header comment to include this remark.


    Mounir IDRASSI - IDRIX - http://www.idrix.fr

    Wednesday, August 19, 2015 10:00 AM