コード例 #1
0
        /// <summary>
        /// Converts low level CK_TOKEN_INFO structure to high level TokenInfo class
        /// </summary>
        /// <param name="slotId">PKCS#11 handle of slot</param>
        /// <param name="ck_token_info">Low level CK_TOKEN_INFO structure</param>
        internal TokenInfo(uint slotId, LowLevelAPI.CK_TOKEN_INFO ck_token_info)
        {
            _slotId             = slotId;
            _label              = ConvertUtils.BytesToUtf8String(ck_token_info.Label, true);
            _manufacturerId     = ConvertUtils.BytesToUtf8String(ck_token_info.ManufacturerId, true);
            _model              = ConvertUtils.BytesToUtf8String(ck_token_info.Model, true);
            _serialNumber       = ConvertUtils.BytesToUtf8String(ck_token_info.SerialNumber, true);
            _tokenFlags         = new TokenFlags(ck_token_info.Flags);
            _maxSessionCount    = ck_token_info.MaxSessionCount;
            _sessionCount       = ck_token_info.SessionCount;
            _maxRwSessionCount  = ck_token_info.MaxRwSessionCount;
            _rwSessionCount     = ck_token_info.RwSessionCount;
            _maxPinLen          = ck_token_info.MaxPinLen;
            _minPinLen          = ck_token_info.MinPinLen;
            _totalPublicMemory  = ck_token_info.TotalPublicMemory;
            _freePublicMemory   = ck_token_info.FreePublicMemory;
            _totalPrivateMemory = ck_token_info.TotalPrivateMemory;
            _freePrivateMemory  = ck_token_info.FreePrivateMemory;
            _hardwareVersion    = ConvertUtils.CkVersionToString(ck_token_info.HardwareVersion);
            _firmwareVersion    = ConvertUtils.CkVersionToString(ck_token_info.FirmwareVersion);
            _utcTimeString      = ConvertUtils.BytesToUtf8String(ck_token_info.UtcTime, true);

            try
            {
                _utcTime = ConvertUtils.UtcTimeStringToDateTime(_utcTimeString);
            }
            catch
            {
                _utcTime = null;
            }
        }
コード例 #2
0
        /// <summary>
        /// Obtains information about a particular token in the system.
        /// </summary>
        /// <returns>Token information</returns>
        public TokenInfo GetTokenInfo()
        {
            LowLevelAPI.CK_TOKEN_INFO tokenInfo = new LowLevelAPI.CK_TOKEN_INFO();
            CKR rv = _p11.C_GetTokenInfo(_slotId, ref tokenInfo);

            if (rv != CKR.CKR_OK)
            {
                throw new Pkcs11Exception("C_GetTokenInfo", rv);
            }

            return(new TokenInfo(_slotId, tokenInfo));
        }