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;
}
}
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.