| | |
| | | public byte[] toByte() { |
| | | byte[] data = new byte[16]; |
| | | data[0] = HexUtil.hexToByte(cardType); |
| | | domainLength = domainName.length(); |
| | | // 域名卡新乡C1后有01==0,鹿邑没有01==1 |
| | | if (type == 0) { |
| | | if (domainNumber != null) { |
| | | byte[] domainNumbers = BcdUtil.strToBcd(domainNumber); |
| | | data[1] = domainNumbers[0]; |
| | | } |
| | | domainLength = domainName.length(); |
| | | data[2] = HexUtil.hexToByte(HexUtil.get10to16(domainLength)); |
| | | String portStr = String.valueOf(port); |
| | | int lenght = portStr.length(); |
| | |
| | | } |
| | | String ascii = IDN.toASCII(domainName + "," + portStr + "#"); |
| | | asciiByte = ascii.getBytes(); |
| | | if (asciiByte.length < 12) { |
| | | System.arraycopy(asciiByte, 0, data, 3, asciiByte.length); |
| | | } else { |
| | | System.arraycopy(asciiByte, 0, data, 3, 12); |
| | | } |
| | | System.arraycopy(asciiByte, 0, data, 3, Math.min(asciiByte.length, 12)); |
| | | } else { |
| | | data[1] = HexUtil.hexToByte(HexUtil.get10to16(domainLength)); |
| | | String portStr = String.valueOf(port); |
| | |
| | | } |
| | | String ascii = IDN.toASCII(domainName + "," + portStr + "#"); |
| | | asciiByte = ascii.getBytes(); |
| | | if (asciiByte.length < 13) { |
| | | System.arraycopy(asciiByte, 0, data, 1, asciiByte.length); |
| | | } else { |
| | | System.arraycopy(asciiByte, 0, data, 1, 13); |
| | | } |
| | | |
| | | |
| | | System.arraycopy(asciiByte, 0, data, 2, Math.min(asciiByte.length, 13)); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | public byte[] toBytes() { |
| | | byte[] data = new byte[16]; |
| | | if (type==0){ |
| | | if (asciiByte.length > 12) { |
| | | if (asciiByte.length - 12 < 15) { |
| | | System.arraycopy(asciiByte, 12, data, 0, asciiByte.length - 12); |
| | | } else { |
| | | System.arraycopy(asciiByte, 12, data, 0, 15); |
| | | } |
| | | } |
| | | }else { |
| | | if (asciiByte.length > 13) { |
| | | if (asciiByte.length - 13 < 15) { |
| | | System.arraycopy(asciiByte, 13, data, 0, asciiByte.length - 12); |
| | | } else { |
| | | System.arraycopy(asciiByte, 13, data, 0, 15); |
| | | } |
| | | } |
| | | int offset = (type == 0) ? 12 : 13; |
| | | |
| | | if (asciiByte.length > offset) { |
| | | System.arraycopy(asciiByte, offset, data, 0, Math.min(asciiByte.length - offset, 15)); |
| | | } |
| | | |
| | | data[15] = getByteSum(data); |
| | |
| | | public class Two extends BaseCard { |
| | | public byte[] toBytes() { |
| | | byte[] data = new byte[16]; |
| | | if (type==0){ |
| | | if (asciiByte.length > (12 + 15)) { |
| | | if (asciiByte.length - (12 + 15) < 15) { |
| | | System.arraycopy(asciiByte, 12 + 15, data, 0, asciiByte.length - (12 + 15)); |
| | | } else { |
| | | System.arraycopy(asciiByte, 12 + 15, data, 0, 15); |
| | | } |
| | | } |
| | | }else { |
| | | if (asciiByte.length > (13 + 15)) { |
| | | if (asciiByte.length - (13 + 15) < 15) { |
| | | System.arraycopy(asciiByte, 13 + 15, data, 0, asciiByte.length - (12 + 15)); |
| | | } else { |
| | | System.arraycopy(asciiByte, 13 + 15, data, 0, 15); |
| | | } |
| | | } |
| | | int offset = (type == 0) ? 27 : 28; // 12 + 15 and 13 + 15 |
| | | if (asciiByte.length > offset) { |
| | | int lengthToCopy = Math.min(asciiByte.length - offset, 15); |
| | | System.arraycopy(asciiByte, offset, data, 0, lengthToCopy); |
| | | } |
| | | |
| | | data[15] = getByteSum(data); |
| | | return data; |
| | | } |