예제 #1
0
        internal static byte[] CreateTripleDES(RSAItems rsaItems, byte[] tripleKey)
        {
            List <byte> triplePacket = new List <byte>();

            triplePacket.AddRange(MessageBuilder.HexToByteArray(GMPDataTags.DT_ENC_KEY));
            triplePacket.AddRange(MessageBuilder.AddLength(256));
            //tripleKey = Encoding.ASCII.GetBytes("1234567890123456");
            triplePacket.AddRange(MessageBuilder.EncryptRSA(rsaItems.Modulus, rsaItems.Exponent, tripleKey));

            //KEY VALUE
            byte[] arrCheck = new byte[32];
            for (int i = 0; i < 32; i++)
            {
                arrCheck[i] = (byte)0;
            }
            arrCheck = MessageBuilder.EncryptTriple(arrCheck, arrCheck.Length, tripleKey);
            List <byte> chk = new List <byte>();

            for (int i = 0; i < 16; i++)
            {
                chk.Add(arrCheck[i]);
            }
            triplePacket.AddRange(MessageBuilder.HexToByteArray(GMPDataTags.DT_CHK_VAL));
            triplePacket.AddRange(MessageBuilder.AddLength(16));
            triplePacket.AddRange(chk.ToArray());

            return(triplePacket.ToArray());
        }
예제 #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);
        }