Delphi writes Chinese characters to IC card

To write Chinese characters or special characters into the CPU card, you need to create a transparent file first, and then use the APDU command to modify the file, but the data field of the APDU command does not accept Chinese characters or special characters, so you need to write the Chinese characters to be written. Convert to hexadecimal bytecode. When reading, it is also necessary to convert the hexadecimal data into Chinese characters. Three functions can be provided here for reference:

//--------------------This function can convert Chinese characters into hexadecimal strings and output --------------- -----------------------

function ChineseToHex(Chinese:String):String;

begin
result: = InttoHex (word (Chinese [1]), 2) + InttoHex (word (Chinese [2]), 2);
than;

//--------------------This function can convert 4 hexadecimal strings into one Chinese character output------------ --------------------------

function HextoChinese(HexStr:String):String;
var
hi,lo:integer;
begin
    hi:=strtoint('$'+leftstr(HexStr,2));
    lo:=strtoint('$'+rightstr(HexStr,2));
    result:=widestring(char(hi)+char(lo));
end;

//--------------------This function can convert Chinese characters or characters into hexadecimal strings and output ------------- -------------------------

function ChartoHex(CharStr:String):String;

begin
     if ord(CharStr[1])<128 then
      result:=inttohex(strtoint(inttostr(ord(CharStr[1]))),2)
     else
      result:=InttoHex(ord(CharStr[1]),2)+InttoHex(ord(CharStr[2]),2);
end;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325346715&siteId=291194637