Пример #1
0
        private string FSP11CheckCert(string original)
        {
            var count = fsPKI.FSXP11GetObjectList(0);

            if (fsPKI.GetErrorCode() != 0)
            {
                fsPKI.FSXP11Logout();
                fsPKI.FSXP11SessionClose();
                fsPKI.FSXP11Final();
                return("Error on funtcion FSXP11GetObjectList, error code=" + fsPKI.GetErrorCode());
            }

            var CertLabel = "";

            for (var i = 0; i < count; i++)
            {
                if (fsPKI.FSXP11GetObjectListObjectType(i) == 0x00000011)
                {
                    CertLabel = fsPKI.FSXP11GetObjectListLabel(i);
                    if (CertLabel == "PlaySAFE")
                    {
                        break;
                    }
                    else
                    {
                        CertLabel = "";
                    }
                }
                if (fsPKI.GetErrorCode() != 0)
                {
                    fsPKI.FSXP11Logout();
                    fsPKI.FSXP11SessionClose();
                    fsPKI.FSXP11Final();
                    return("憑證存取失敗,請您關閉程式後重新再試(" + fsPKI.GetErrorCode() + ")");
                }
            }

            if (CertLabel != "PlaySAFE")
            {
                fsPKI.FSXP11Logout();
                fsPKI.FSXP11SessionClose();
                fsPKI.FSXP11Final();
                return("找不到指定物件 Label[PlaySAFE]");
            }

            return(SignatureData(original));
        }
Пример #2
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));
        }
Пример #3
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);
        }