/// <summary> /// Loads and initializes PCKS#11 library /// </summary> /// <param name="libraryPath">Library name or path</param> /// <param name="appType">Type of application that will be using PKCS#11 library</param> public Pkcs11(string libraryPath, AppType appType) { _p11 = new LowLevelAPI40.Pkcs11(libraryPath); try { CK_C_INITIALIZE_ARGS initArgs = null; if (appType == AppType.MultiThreaded) { initArgs = new CK_C_INITIALIZE_ARGS(); initArgs.Flags = CKF.CKF_OS_LOCKING_OK; } CKR rv = _p11.C_Initialize(initArgs); if ((rv != CKR.CKR_OK) && (rv != CKR.CKR_CRYPTOKI_ALREADY_INITIALIZED)) { throw new Pkcs11Exception("C_Initialize", rv); } } catch { _p11.Dispose(); _p11 = null; throw; } }
/// <summary> /// Loads and initializes PCKS#11 library /// </summary> /// <param name="libraryPath">Library name or path</param> /// <param name="useOsLocking">Flag indicating whether PKCS#11 library can use the native operation system threading model for locking. Should be set to true in all multithreaded applications.</param> /// <param name="useGetFunctionList">Flag indicating whether cryptoki function pointers should be acquired via C_GetFunctionList (true) or via platform native function (false)</param> public Pkcs11(string libraryPath, bool useOsLocking, bool useGetFunctionList) { _p11 = new LowLevelAPI40.Pkcs11(libraryPath, useGetFunctionList); try { CK_C_INITIALIZE_ARGS initArgs = null; if (useOsLocking) { initArgs = new CK_C_INITIALIZE_ARGS(); initArgs.Flags = CKF.CKF_OS_LOCKING_OK; } CKR rv = _p11.C_Initialize(initArgs); if ((rv != CKR.CKR_OK) && (rv != CKR.CKR_CRYPTOKI_ALREADY_INITIALIZED)) { throw new Pkcs11Exception("C_Initialize", rv); } } catch { _p11.Dispose(); _p11 = null; throw; } }
/// <summary> /// Initializes PCKS#11 library /// </summary> /// <param name="appType">Type of application that will be using PKCS#11 library</param> protected void Initialize(AppType appType) { _logger.Debug("Pkcs11({0})::Initialize", _libraryPath); CK_C_INITIALIZE_ARGS initArgs = null; if (appType == AppType.MultiThreaded) { initArgs = new CK_C_INITIALIZE_ARGS(); initArgs.Flags = CKF.CKF_OS_LOCKING_OK; } CKR rv = _p11.C_Initialize(initArgs); if ((rv != CKR.CKR_OK) && (rv != CKR.CKR_CRYPTOKI_ALREADY_INITIALIZED)) { throw new Pkcs11Exception("C_Initialize", rv); } }
/// <summary> /// Loads and initializes PCKS#11 library /// </summary> /// <param name="libraryPath">Library name or path</param> /// <param name="useOsLocking">Flag indicating whether PKCS#11 library can use the native operation system threading model for locking. Should be set to true in all multithreaded applications.</param> public Pkcs11(string libraryPath, bool useOsLocking) { _p11 = new LowLevelAPI40.Pkcs11(libraryPath); try { CK_C_INITIALIZE_ARGS initArgs = null; if (useOsLocking) { initArgs = new CK_C_INITIALIZE_ARGS(); initArgs.Flags = CKF.CKF_OS_LOCKING_OK; } CKR rv = _p11.C_Initialize(initArgs); if ((rv != CKR.CKR_OK) && (rv != CKR.CKR_CRYPTOKI_ALREADY_INITIALIZED)) throw new Pkcs11Exception("C_Initialize", rv); } catch { _p11.Dispose(); _p11 = null; throw; } }