コード例 #1
0
        /// <summary>
        /// Validate Message Mac.
        /// Of course it needs a special MAC calculation algorithm that designed by
        /// your system.
        /// </summary>
        /// <param name="isoMacGenerator"></param>
        /// <returns></returns>
        public bool ValidateMac(ISOMacGenerator isoMacGenerator)
        {
            if (!FieldExits(FIELDS.F64_MAC) || GetField(FIELDS.F64_MAC).Length == 0)
            {
                return(false);
            }
            byte[] mBody = new byte[GetBody().Length - 8];
            GetBody().CopyTo(mBody, GetBody().Length - 8);
            byte[] oMac = Arrays.CopyOf(GetField(FIELDS.F64_MAC), 8);
            byte[] vMac = isoMacGenerator.Generate(mBody);

            return(oMac.SequenceEqual(vMac));
        }
        public DataElement <T> GenerateMac(ISOMacGenerator generator)
        {
            if (generator != null)
            {
                byte[] mac = generator.Generate(BuildBuffer(true));
                if (mac != null)
                {
                    SetField(FIELDS.F64_MAC, mac);
                }
                else
                {
                    throw new ISOException("MAC is null");
                }
            }

            return(this);
        }