c#中的ISO 8583库

时间:2018-03-24 17:30:36

标签: c# iso8583

我现在正在使用支付网关.ISO 8583消息系统。我正面临一些我在下面描述的问题: 我的二进制数据是:

$ sed -n 's/.*Array of \([^ ]*\).*/\1/p' file
MY_TYPE_T

我需要将其转换为十六进制值(8字节):

public class HeroInfo {
  private int hp;
  private float power;

  public HeroInfo() { // no-arg constructor
    super();
  }

  public HeroInfo(HeroInfo info){ // This is copy constructor
    super();
    this.hp = info.hp;
    this.power = info.power
  }

  ...
}

然后我需要转移为16个EBCDIC字符(十六进制):

0111101010111010000001000000000100001110111000001100000000000000 

然后我需要转移为16个ASCII字符(十六进制):

7A BA 04 01 0E E0 C0 00 

我的问题是如何转换这个二进制数据EBCDIC字符和ASCII字符。如果有人帮助我非常需要

1 个答案:

答案 0 :(得分:1)

this function的帮助下: 您可以先将字节数组转换为十六进制字符串,然后将其转换为EBCDIC编码,最后您可以再次使用字符的十六进制字节码:

    var hexdata = new[] { 0x7A, 0xBA, 0x04, 0x01, 0x0E, 0xE0, 0xC0, 0x00 };    
    var asciiString = string.Join("", hexdata.Select(num => num.ToString("X2")));
    var asciiBytes = asciiString.Select(ch => (byte)ch).ToArray(); // It is safe, as we cannot have any unicode characters here

    var ebcdicData = ConvertAsciiToEbcdic(asciiBytes);

    var ebcdicString = string.Join(" ", ebcdicData.Select(ch => ((byte)ch).ToString("X2")));    
    var asciiHexString = string.Join(" ", asciiBytes.Select(ch => ((byte)ch).ToString("X2")));