简体   繁体   中英

Cryptoki dll causing application to crash

I'm using cryptoki in a C# app. The problem I have is the following: I initialize cryptoki using the following code:

public static bool InitializeCryptoki(string criptokilib)
{
    if (cryptoki != null)
        throw new PdfSignException(PdfSignExceptionCode.PDF_EXCEPTION_NOT_FINALIZED);
    try
    {
        cryptoki = new Cryptoki(criptokilib);
        if (cryptoki.Initialize() == 0)
        {
            isInitialized = true;
            return true;
        }
        return false;
    }
    catch (CryptokiException ex)
    {
        Log.Log(log, LogState.ERROR, UserId, "Initialize", null, ex.Message);
        return false;
    }
}

criptokilib value is equal to "eTPKCS11.dll".

After cryptoki is initialized, I check if at least one card reader exists using the following code:

public static bool HasCardReaders
{
    get
    {
        if (cryptoki == null)
            throw new PdfSignException(PdfSignExceptionCode.PDF_EXCEPTION_NOT_INITIALIZED);
        return cryptoki.Slots.Count != 0;
    }
}
  • When running the app in debug mode from the compiler (VS 2012), an error message is displayed (no app crash) saying that no card reader has been detected.
  • When running the app outside the compiler (VS 2012) - by double clicking the exe in debug folder, my application crashes. Looking at the log files, sometimes the app crashes while initializing cryptoki, and sometimes the app crashes while checking if at least one card reader exists.

In debug mode, I discovered that cryptoki.Slots[i].Token throws error n. 224 - this error means that no token is present. Can this error cause my app to crash? Do you have any idea how to overcame this issue?

Thank you very much, Gica G.

if (cryptoki != null)

This looks wrong. That should read:

if (cryptoki == null)

It seems that upgrading to the last NCryptoki.dll resolves the issue.

However I still didn't understood why that error was causing my app to crash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM