Exemplo n.º 1
0
        internal static int InterpretEnd(byte[] decodedData)
        {
            int retVal = 0;
            int index  = 0;

            try
            {
                int    len       = decodedData.Length;
                int    tagLen    = 0;
                String tagValStr = "";
                while (true)
                {
                    if (index > (len - GMPConstants.LEN_DATA_TAG))
                    {
                        break;
                    }
                    //get next tag
                    int tag = MessageBuilder.GetTag(decodedData, index, out index);

                    switch (tag)
                    {
                    case GMPCommonTags.TAG_RESP_CODE:
                        tagLen    = MessageBuilder.GetLength(decodedData, index, out index);
                        tagValStr = MessageBuilder.ByteArrayToString(decodedData, index, tagLen);
                        index    += tagLen;
                        if (!tagValStr.Equals(GMPResCodes.SUCCESS))
                        {
                            throw new Exception("İşlem başarısız");
                        }
                        break;
                    }
                }
            }
            catch { retVal = -1; }

            return(retVal);
        }
Exemplo n.º 2
0
        internal static RSAItems InterpretRSA(byte[] identityBytes)
        {
            int      index    = 0;
            RSAItems rsaItems = new RSAItems();

            rsaItems.DevInfo = new DeviceInfo();

            try
            {
                int    len       = MessageBuilder.GetLength(identityBytes, index, out index);
                int    tagLen    = 0;
                String tagValStr = "";
                while (true)
                {
                    if (index > (len - GMPConstants.LEN_DATA_TAG))
                    {
                        break;
                    }
                    //get next tag
                    int tag    = MessageBuilder.GetTag(identityBytes, index, out index);
                    int tagVal = 0;
                    switch (tag)
                    {
                    case GMPCommonTags.TAG_SEQUNCE:
                        tagLen             = MessageBuilder.GetLength(identityBytes, index, out index);
                        tagVal             = MessageBuilder.ConvertBcdToInt(identityBytes, index, tagLen);
                        index             += tagLen;
                        rsaItems.SeqNumber = tagVal;
                        break;

                    case GMPDataTags.DT_MOD_KEY:
                        tagLen           = MessageBuilder.GetLength(identityBytes, index, out index);
                        rsaItems.Modulus = MessageBuilder.GetBytesFromOffset(identityBytes, index, tagLen);
                        index           += tagLen;
                        break;

                    case GMPDataTags.DT_EXP_KEY:
                        tagLen            = MessageBuilder.GetLength(identityBytes, index, out index);
                        rsaItems.Exponent = MessageBuilder.GetBytesFromOffset(identityBytes, index, tagLen);
                        index            += tagLen;
                        break;

                    case GMPDataTags.DT_ECR_BRAND:
                        tagLen    = MessageBuilder.GetLength(identityBytes, index, out index);
                        tagValStr = MessageBuilder.ByteArrayToString(identityBytes, index, tagLen);
                        index    += tagLen;
                        rsaItems.DevInfo.DevBrand = tagValStr;
                        break;

                    case GMPDataTags.DT_ECR_MODEL:
                        tagLen    = MessageBuilder.GetLength(identityBytes, index, out index);
                        tagValStr = MessageBuilder.ByteArrayToString(identityBytes, index, tagLen);
                        index    += tagLen;
                        rsaItems.DevInfo.DevModel = tagValStr;
                        break;

                    case GMPCommonTags.TAG_RESP_CODE:
                        tagLen    = MessageBuilder.GetLength(identityBytes, index, out index);
                        tagValStr = MessageBuilder.ByteArrayToString(identityBytes, index, tagLen);
                        index    += tagLen;
                        if (!tagValStr.Equals(GMPResCodes.SUCCESS))
                        {
                            throw new Exception("İşlem başarısız");
                        }
                        break;

                    case GMPDataTags.DT_ECR_SERIAL:
                        tagLen    = MessageBuilder.GetLength(identityBytes, index, out index);
                        tagValStr = MessageBuilder.ByteArrayToString(identityBytes, index, tagLen);
                        index    += tagLen;
                        rsaItems.DevInfo.TerminalNo = tagValStr;
                        break;

                    default:
                        tagLen = MessageBuilder.GetLength(identityBytes, index, out index);
                        index += tagLen;
                        break;
                    }
                }
            }
            catch { rsaItems.SeqNumber = -1; }

            //if no response code
            //rsaItems.SeqNumber = -1;
            return(rsaItems);
        }