예제 #1
0
        /// <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;
            }
        }
예제 #2
0
        /// <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;
            }
        }
예제 #3
0
        /// <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);
            }
        }
예제 #4
0
        /// <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;
            }
        }