Convert message from ASCII to HEX ISO8583.net

My billing provider should receive the message in HEX and not ASCII, for example I sent 800 message and the flow was:

42 00 30 38 30 30 a2 38 00 00 00 80 80 00 04 00

00 00 00 00 00 00 39 30 30 30 30 30 30 34 30 32

31 34 33 31 31 38 31 37 33 31 31 38 31 37 33 31

31 38 30 34 30 32 31 32 33 34 35 36 37 38 39 39

38 30 30 31

Can I use the project to create a message as HEX instead of ASCII? Do I just need to convert the message before I send it (and convert it back to the return message)?

I would be grateful for your help in this matter.

+3


source to share


2 answers


You can change the formatters for fields, bitmaps, and message types.

Look at the source of the project in the Template class. You need to create your own class that extends Iso8583 and will create your own template with ASCII bitmap and message formats.



In the 0.5.1 release, you can do the following

public class AsciiIso : Iso8583
{
    private static readonly Template template;

    static AsciiIso()
    {
        template = GetDefaultIso8583Template();
        template.BitmapFormatter = Formatters.Ascii;
        template.MsgTypeFormatter = Formatters.Ascii;
    }

    public AsciiIso() : base(template)
    {
    }
}

      

+2


source


What do you mean by "HEX, not ASCII"? The HEX string is usually an ASCII-encoded string consisting of only the characters [0-9A-F].

Here is a C # extension method that converts byte arrays to strings of hexadecimal pairs representing the bytes of the original byte array:

using System;
using System.Linq;
using System.Text;

namespace Substitute.With.Your.Project.Namespace.Extensions
{
    static public class ByteUtil
    {
        /// <summary>
        /// byte[] to hex string
        /// </summary>
        /// <param name="self"></param>
        /// <returns>a string of hex digit pairs representing this byte[]</returns>
        static public string ToHexString(this byte[] self)
        {
            return self
                .AsEnumerable()
                .Aggregate(
                    new StringBuilder(),
                    (sb, value)
                        => sb.Append(
                            string.Format("{0:X2}", value)
                           )
                ).ToString();
        }
    }
}

      

Then elsewhere you are just an use

extension



using Substitute.With.Your.Project.Namespace.Extensions;

      

and call it like this

aByteArray.ToHexString();

      

(code not verified, YMMW)

0


source







All Articles