コード例 #1
0
        // PKI
        public string FSCAPISign(string pass, string original)
        {
            fsPKI = new KENP11CryptClass();
            var rtn = fsPKI.FSXP11Init("gclib.dll");

            if (rtn != 0)
            {
                var ErrCode = fsPKI.GetErrorCode();
                if (ErrCode == 9110)
                {
                    return("憑證卡讀取失敗( 晶片卡驅動程式未安裝 )");
                }
                else if (ErrCode == 9056)
                {
                    return("憑證卡讀取失敗( 請插入晶片卡 )");
                }
                else
                {
                    return("憑證卡讀取失敗(" + ErrCode + ")");
                }
            }

            rtn = fsPKI.FSXP11SessionOpen();
            if (rtn != 0)
            {
                fsPKI.FSXP11Final();
                return("憑證卡開啟失敗(" + fsPKI.GetErrorCode() + ")");
            }

            var serialNumber = fsPKI.FSP11_GetSerialNumber();
            var SNErrCode    = fsPKI.GetErrorCode();

            if (SNErrCode != 0)
            {
                fsPKI.FSXP11SessionClose();
                fsPKI.FSXP11Final();
                return("read card serial number fail(" + SNErrCode + ")");
            }
            serialNumber = serialNumber.Substring(0, 16);
            this.cardid  = serialNumber;

            rtn = fsPKI.FSXP11Login(pass);
            if (rtn != 0)
            {
                var varErrorCode = fsPKI.GetErrorCode();
                rtn = fsPKI.FSP11_GetRetryCounter(0x00020000);
                fsPKI.FSXP11SessionClose();
                fsPKI.FSXP11Final();
                if (varErrorCode == 9039)
                {
                    return("密碼驗證失敗:(還有" + rtn + "次機會" + ")");
                }
                else if (varErrorCode == 9043)
                {
                    return("密碼輸入錯誤已達八次,請用購買認證序號解鎖!");
                }
                else
                {
                    return("憑證卡登入失敗" + varErrorCode + ")");
                }
            }

            // Without checking makes it good, why~?

            /*rtn = fsPKI.FSP11_GetPinFlag();
             * var ErrorCode = fsPKI.GetErrorCode();
             * if (ErrorCode != 0)
             * {
             *  fsPKI.FSXP11Logout();
             *  fsPKI.FSXP11SessionClose();
             *  fsPKI.FSXP11Final();
             *  return "憑證卡讀取資料失敗(" + ErrorCode + ")";
             * }
             * else if (rtn == 9990)
             * {
             *  fsPKI.FSXP11Logout();
             *  fsPKI.FSXP11SessionClose();
             *  fsPKI.FSXP11Final();
             *  return "憑證卡讀取資料失敗(" + fsPKI.GetErrorCode() + ")";
             * }*/

            return(FSP11CheckCert(original));
        }
コード例 #2
0
ファイル: PlaySafe.cs プロジェクト: Inndy/BeanfunLogin
        // PKI
        public string FSCAPISign(string pass, string original)
        {
            fsPKI = new KENP11CryptClass();
            var rtn = fsPKI.FSXP11Init("gclib.dll");
            if (rtn != 0)
            {
                var ErrCode = fsPKI.GetErrorCode();
                if (ErrCode == 9110)
                {
                    return "憑證卡讀取失敗( 晶片卡驅動程式未安裝 )";
                }
                else if (ErrCode == 9056)
                {
                    return "憑證卡讀取失敗( 請插入晶片卡 )";
                }
                else
                {
                    return "憑證卡讀取失敗(" + ErrCode + ")";
                }
            }

            rtn = fsPKI.FSXP11SessionOpen();
            if (rtn != 0)
            {
                fsPKI.FSXP11Final();
                return "憑證卡開啟失敗(" + fsPKI.GetErrorCode() + ")";
            }

            var serialNumber = fsPKI.FSP11_GetSerialNumber();
            var SNErrCode = fsPKI.GetErrorCode();
            if (SNErrCode != 0)
            {
                fsPKI.FSXP11SessionClose();
                fsPKI.FSXP11Final();
                return "read card serial number fail(" + SNErrCode + ")";
            }
            serialNumber = serialNumber.Substring(0, 16);
            this.cardid = serialNumber;

            rtn = fsPKI.FSXP11Login(pass);
            if (rtn != 0)
            {
                var varErrorCode = fsPKI.GetErrorCode();
                rtn = fsPKI.FSP11_GetRetryCounter(0x00020000);
                fsPKI.FSXP11SessionClose();
                fsPKI.FSXP11Final();
                if (varErrorCode == 9039)
                {
                    return "密碼驗證失敗:(還有" + rtn + "次機會" + ")";
                }
                else if (varErrorCode == 9043)
                {
                    return "密碼輸入錯誤已達八次,請用購買認證序號解鎖!";
                }
                else
                {
                    return "憑證卡登入失敗" + varErrorCode + ")";
                }
            }

            // Without checking makes it good, why~?
            /*rtn = fsPKI.FSP11_GetPinFlag();
            var ErrorCode = fsPKI.GetErrorCode();
            if (ErrorCode != 0)
            {
                fsPKI.FSXP11Logout();
                fsPKI.FSXP11SessionClose();
                fsPKI.FSXP11Final();
                return "憑證卡讀取資料失敗(" + ErrorCode + ")";
            }
            else if (rtn == 9990)
            {
                fsPKI.FSXP11Logout();
                fsPKI.FSXP11SessionClose();
                fsPKI.FSXP11Final();
                return "憑證卡讀取資料失敗(" + fsPKI.GetErrorCode() + ")";
            }*/

            return FSP11CheckCert(original);
        }