Pkcs11Interop / Pkcs11Interop.X509Store

Easy to use PKCS#11 based X.509 certificate store
Apache License 2.0
31 stars 18 forks source link

Cannot Initialize Pkcs11X509Store instance "Unable to load 64-bit unmanaged library into 32-bit runtime" #16

Closed hqlovely closed 2 years ago

hqlovely commented 3 years ago

Hi, I am using Pkcs11X509Store (0.2.0.0) with .Net Framework 4.7.2 and trying to initialize the instance but I got the error "Unable to load 64-bit unmanaged library into 32-bit runtime" do you have any idea or suggestion on that ? I only wanted to load the certificate stored in my HSM.

string libPath = @"C:\Program Files\SafeNet\LunaClient\cryptoki.dll";
using (var store = new Pkcs11X509Store(libPath, new PinProvider("111111")))
{
     Pkcs11X509Certificate cert = store.Slots[0].Token.Certificates[0];
}

and here is my PinProvider Class

public class PinProvider : IPinProvider
{
    private byte[] _pin = null;

    public PinProvider(string pin)
    {
        _pin = Encoding.UTF8.GetBytes(pin);
    }

    public GetPinResult GetKeyPin(Pkcs11X509StoreInfo storeInfo, Pkcs11SlotInfo slotInfo, Pkcs11TokenInfo tokenInfo, Pkcs11X509CertificateInfo certificateInfo)
    {
        return new GetPinResult(false, false, _pin);
    }

    public GetPinResult GetTokenPin(Pkcs11X509StoreInfo storeInfo, Pkcs11SlotInfo slotInfo, Pkcs11TokenInfo tokenInfo)
    {
        return new GetPinResult(false, false, _pin);
    }
}

Update : I changed to load the dll in 32-bit I got this error "Value of attribute CKA_ALWAYS_AUTHENTICATE could not be read"

jariq commented 2 years ago

This problem should be resolved in a freshly released Pkcs11Interop.X509Store 0.3.0.