Appendix / Checksum Mechanism

Checksum Mechanism

The following example shows how the CheckMacValue mechanism is generated.

The following is an example of a query string to be encrypted

				
					RtnCode=1&RtnMsg=&IA_Allow_No=1909181313013546&IA_Invoice_No=UV11100019&IA_Date=2019-09-18 13:13:23&IIS_Remain_Allowance_Amt=0
				
			

The checksum works as follows

(1) The query string to be be sorted alphabetically (A-Z) and linked with an ampersand (&).

				
					IA_Allow_No=1909181313013546&IA_Date=2019-09-18 13:13:23&IA_Invoice_No=UV11100019&IIS_Remain_Allowance_Amt=0&RtnCode=1&RtnMsg=
				
			
(2) The query string will be sandwiched by HashKey in the front and HashIV at the bottom.
				
					HashKey=ejCk326UnaZWKisg&IA_Allow_No=1909181313013546&IA_Date=2019-09-18 13:13:23&IA_Invoice_No=UV11100019&IIS_Remain_Allowance_Amt=0&RtnCode=1&RtnMsg=&HashIV=q9jcZX8Ib9LM8wYk
				
			
(3) The entire string will go through URL encoding.
				
					HashKey%3DejCk326UnaZWKisg%26IA_Allow_No%3D1909181313013546%26IA_Date%3D2019-09-18+13%3A13%3A23%26IA_Invoice_No%3DUV11100019%26IIS_Remain_Allowance_Amt%3D0%26RtnCode%3D1%26RtnMsg%3D%26HashIV%3Dq9jcZX8Ib9LM8wYk
				
			

❗ Special Note:

If using PHP, use urlencode() (RFC 1866) and use str_replace() to replace the characters according to the urlencode conversion table.

(4) Switched to lowercase
				
					hashkey%3dejck326unazwkisg%26ia_allow_no%3d1909181313013546%26ia_date%3d2019-09-18+13%3a13%3a23%26ia_invoice_no%3duv11100019%26iis_remain_allowance_amt%3d0%26rtncode%3d1%26rtnmsg%3d%26hashiv%3dq9jczx8ib9lm8wyk
				
			
❗ Special Note: Use strtolower() if you are using PHP.

(5) The string is then encrypted using MD5 to generate a hash value

				
					50a276e71dae26343013958b405eeea0
				
			
(6) It is then converted into upper case to generate a CheckMacValue
				
					50A276E71DAE26343013958B405EEEA0
				
			

❗ Special Note:

(1) Please use MD5 encryption to generate hash values.
(2) Please make sure that the the converted results after UrlEncode function in your language corresponds to the “.NET Encoding (ecpay)” value in the URLENCODE CONVERSION TABLE. If there are any unsupported characters, please use the character replacement function so the results will pass the checksum test.
For example: PHP urlencode function will encode ! Into %21, which is not accepted according to the “.NET encoding (ecpay)” rules, so the %21 will have to be converted back into ! With str_replace function after the PHP urlencode function. Here’s a PHP conversion example:

  • $sMacValue = str_replace(‘%2d’, ‘-‘, $sMacValue);
  • $sMacValue = str_replace(‘%5f’, ‘_’, $sMacValue);
  • $sMacValue = str_replace(‘%2e’, ‘.’, $sMacValue);
  • $sMacValue = str_replace(‘%21’, ‘!’, $sMacValue);
  • $sMacValue = str_replace(‘%2a’, ‘*’, $sMacValue);
  • $sMacValue = str_replace(‘%28’, ‘(‘, $sMacValue);
  • $sMacValue = str_replace(‘%29’, ‘)’, $sMacValue);

For conversion functions in other programming languages, please refer to the relevant encoding conversion rules.

Program example

Copyright © Green World FinTech Service Co., Ltd. All rights reserved.

Green World