1. Data preparation:
IC card application key mdkac: F23BF4AE92B554C116139D4F67322667
card number: 6214988660100000304
card number: 00 the
ATC: 0001 ARC
: 00
's aqdt: 00000000000000000000000001560000000800015616051800412AB4B67D00000103A00000
2.pan generated by the last two last card number of the card 14 + = 8866010000030400 i.e.
PAN 3. Scatter factor acquisition card PAN + (PAN XOR FFFFFFFFFFFFFFFF) Panyz=88660100000304007799FEFFFFFCFBFF
4. Use mdkac to encrypt the card dispersion factor with SM4 to obtain the card dispersion key keyZ:
016F6E76BD8E6FB4A17C28C4B05E03A8 0x00, that is:
atc1='00'||'00'||'00'||'00'||'00'||'00'||ATC||'00'||'00'||'00'|| '00'||'00'||'00'
Then atc2=FFFE obtained by XORing atc and FFFF, and then atcK=atc1+atc2=0000000000000001000000000000FFFE after
dispersion 6. Then use the card dispersion key keyZ to disperse the atc factor AtcK performs SM4 encryption to obtain the process key skac=9ECF9220F32AE56187D3C2444967FC0E
7. Use the process key skac to perform PBOC-SM4-MAC calculation on the transaction data aqdt to obtain the MAC of the transaction data, namely ARQC:
179E0D01A7D1791D
The calculation process code is as follows (the code is not complete, just the process):
// The first step, first get the card dispersion factor, PAN+PAN XOR FFFFFFFFFFFFFFFF String panyz = pan + xor(pan, "FFFFFFFFFFFFFFFF");// 32-bit card scatter factor // The second step, use mdkac to encrypt the pan dispersion factor with SM4 to obtain the card dispersion key Z String keyZ = sm4Encrpty(mkdac, panyz); // Step 3: Disperse ATC to get the ATC dispersion factor, 1. 12 0's on the left, 12 0's on the right, add atc in the middle; 2. atc and 4 F do xor; 3.1+2 get the atc dispersion factor String atcyz = ""; for (int i = 1; i <= 6; i++) { atcyz += "00"; } atcyz += atc; for (int i = 1; i <= 6; i++) { atcyz += "00"; } atcyz += xor(atc, "FFFF");// atc dispersion factor // Step 4: Perform SM4 encryption on the atc dispersion factor by the card dispersion key Z to obtain the process key SKAC String skac = sm4Encrpty(keyZ, atcyz);// Process distributed key SKAC // Step 5: Use the process key SKAC to perform Mac calculation on the data involved in the calculation through the PBOC-3DES algorithm to obtain ARQC PbocMacAnsiX9_9 pmac = new PbocMacAnsiX9_9(); String iv = "00000000000000000000000000000000"; String arqc = pmac.PBOC_SM4_MAC(aqdt, skac, 0, iv);
8. Generate ARPC:
a. Convert arc to 3030, and then add 0 to 16 bits to the left; that is: x=3030000000000000
b. XOR the ARQC obtained above with x to get x_y=27AE0D01A7D1791D
c. Then add x_y to the left by 0 to 32 bits is: y=27AE0D01A7D1791D0000000000000000
d. Then use the process key to SM4 encrypt y to get ARPC:DC16134D6FF5CF97 The
code is as follows (incomplete):
//The first step: convert arc 3030 first String arcbcd = HexBinary.encode(arc.getBytes()); int arcLen = arcbcd.length(); //Step 2: splice arc to 16 bits for(int i=1;i<=8-arcLen/2;i++){ arcbcd += "00"; } //The third step: arqc and arcbcd perform xor: arqc⊕arcbcd to get y String arpcY = xor(arqc, arcbcd); //Step 4: Assemble the y and 0 obtained in the third step into 32-bit data String fordata= arpcY; int fordataLen = fordata.length(); for(int i=1 ;i<=16-fordataLen/2;i++){ fordata += "00"; } //Step 5: ARPC performs 3DES encryption on the data obtained in the fourth step by the key SKAC to obtain arpc result = sm4Encrpty(skac, fordata);