银联卡整个pdol电子钱包扣费的过程

 

初始化MFRC531........................成功

开始运行应用程序.........................

HA1=0xF7C3BC1D808E04732ADF679965CCC34CA7AE3441

 

寻卡

读卡号

选择卡

复位

总目录

错误次数:00

支付目录:31 50 41 59 2e 53 59 53 2e 44 44 46 30 31

 

 ***发送*** Apdu= hex is:00 a4 04 00 0e 31 50 41 59 2e 53 59 53 2e 44 44 46 30 31

                                                00 A4 04 00 0E 32 50 41 59 2E 53 59 53 2E 44 44 46 30 31 00

 ++++++ 接收成功 ++++++

   File:..\COS\APDU.c, Line:923, Function:iso7816_SendReceive

 $$$接收$$$ Apdu= hex is:6f 1e 84 0e 31 50 41 59 2e 53 59 53 2e 44 44 46 30 31 a5 0c 88 01 01 5f 2d 02 7a 68 9f 11 01 01

90 00

//***************** Tlv Unpack Test *****************

++++++++++

Tag:84

Len:14

Val:

31 50 41 59 2E 53 59 53 2E 44 44 46 30 31

专用文件(DF)名称

++++++++++

Tag:88

Len:1

Val:

01

短文件标识符(SFI)

++++++++++

Tag:5F2D

Len:2

Val:

7A 68

首选语言

++++++++++

Tag:9F11

Len:1

Val:

01

发卡行代码表索引

++++++++++

Tag:90

Len:0

Val:

发卡行公钥证书

 

 SelectFile_1PAY_SYS_DDF01 iRetCode=1

   File:..\COS\APDU.c, Line:1257, Function:getUnionPayCardNumber

 ***发送*** Apdu= hex is:00 b2 01 0c 00

 

 ++++++ 接收成功 ++++++

   File:..\COS\APDU.c, Line:923, Function:iso7816_SendReceive

 $$$接收$$$ Apdu= hex is:70 1b 61 19 4f 08 a0 00 00 03 33 01 01 01 50 0a 50 42 4f 43 20 44 45 42 49 54 87 01 01 90 00

//***************** Tlv Unpack Test *****************

++++++++++

Tag:4F

Len:8

Val:

A0 00 00 03 33 01 01 01

应用标识符(AID)

++++++++++

Tag:50

Len:10

Val:

50 42 4F 43 20 44 45 42 49 54

应用标签

++++++++++

Tag:87

Len:1

Val:

01

应用优先级权指示符

++++++++++

Tag:90

Len:0

Val:

发卡行公钥证书

iso7816_ReadRecord iRetCode=1

   File:..\COS\APDU.c, Line:1263, Function:getUnionPayCardNumber

 ***发送*** Apdu= hex is:00 a4 04 00 08 a0 00 00 03 33 01 01 01

 

 ++++++ 接收成功 ++++++

   File:..\COS\APDU.c, Line:923, Function:iso7816_SendReceive

 $$$接收$$$ Apdu= hex is:6f 4c 84 08 a0 00 00 03 33 01 01 01 a5 40 50 0a 50 42 4f 43 20 44 45 42 49 54 87 01 01 9f 38 18 9f 66 04 9f 02 06 9f 03 06 9f 1a 02 95 05 5f 2a 02 9a 03 9c 01 9f 37 04 5f 2d 02 7a 68 9f 11 01 01 9f 12 0a 50 42 4f 43 20 44 45 42 49 54 90 00

//***************** Tlv Unpack Test *****************

++++++++++

Tag:84

Len:8

Val:

A0 00 00 03 33 01 01 01

专用文件(DF)名称

++++++++++

Tag:50

Len:10

Val:

50 42 4F 43 20

44 45 42 49 54

应用标签

++++++++++

Tag:87

Len:1

Val:

01

应用优先级权指示符

++++++++++

Tag:9F38

Len:24

Val:

9F 66 04 9F 02 06 9F 03 06 9F 1A 02 95 05 5F 2A 02 9A 03 9C 01 9F 37 04

/*

9F 66 04 9F 02 06 9F 03 06 9F 1A 02 95 05 5F 2A 02 9A 03 9C 01 9F 37 04 9F 21 03  工商银行

9F 66 04 9F 02 06 9F 03 06 9F 1A 02 95 05 5F 2A 02 9A 03 9C 01 9F 37 04

9F 66 04 9F 02 06 9F 37 04 5F 2A 02 DF 60 01 pboc3.0

*/

密文版本01

DF 60 01 9F 66 04 9F 02 06 9F 03 06 9F 1A 02 95 05 5F 2A 02 9A 03 9C 01 9F 37 04

密文版本17

DF 60 01 9F 66 04 9F 02 06 9F 37 04 5F 2A 02

处理选项数据对象列表PDOL

++++++++++

Tag:5F2D

Len:2

Val:

7A 68

首选语言

++++++++++

Tag:9F11

Len:1

Val:

01

发卡行代码表索引

++++++++++

Tag:9F12

Len:10

Val:

50 42 4F 43 20 44 45 42 49 54

应用首选名称

++++++++++

Tag:90

Len:0

Val:

发卡行公钥证书

iso7816_SelectFile iRetCode=1

   File:..\COS\APDU.c, Line:1273, Function:getUnionPayCardNumber

 ***发送*** Apdu= hex is:00 b2 01 0c 00

 

 ++++++ 接收成功 ++++++

   File:..\COS\APDU.c, Line:923, Function:iso7816_SendReceive

 $$$接收$$$ Apdu= hex is:70 15 57 13 62 23 22 60 16 48 61 76 d1 80 12 20 14 16 94 00 00 00 0f 90 00

//***************** Tlv Unpack Test *****************

++++++++++

Tag:57

Len:19

Val:

62 23 22 60 16 48 61 76 D1 80 12 20 14 16 94 00 00 00 0F

 

 pTLVEntity->au1Value= hex is:62 23 22 60 16 48 61 76 d1 80 12 20 14 16 94 00 00 00 0f

 

 e[32m银行卡号e[0m=6223226016486176   File:..\COS\APDU.c, Line:224, Function:getOneTagData磁条2等效数据

++++++++++

Tag:90

Len:0

Val:

发卡行公钥证书

iso7816_SelectFile iRetCode=1

   File:..\COS\APDU.c, Line:1280, Function:getUnionPayCardNumberLLUHN_IsValid iRetCode=1

   File:..\COS\APDU.c, Line:1286, Function:getUnionPayCardNumber

 ***发送*** Apdu= hex is:80 ca 9f 79 00

 

 ++++++ 接收成功 ++++++

   File:..\COS\APDU.c, Line:923, Function:iso7816_SendReceive

 $$$接收$$$ Apdu= hex is:9f 79 06 00 00 00 00 86 58 90 00

//***************** Tlv Unpack Test *****************

++++++++++

Tag:9F79

Len:6

Val:

00 00 00 00 86 58

电子现金余额(EC Balance)

++++++++++

Tag:90

Len:0

Val:

发卡行公钥证书

 

 e[31mERR:e[0m 电子钱包余额:086.58元   File:..\COS\APDU.c, Line:1096, Function:iso7816_Read_EC_Balance

 e[31mERR:e[0m iTagCount=9   File:..\COS\APDU.c, Line:

451, Function:initPDOL

 e[31mERR:e[0m i = 0 o_tag=9f66 o_len=4 9f 66   File:..\COS\APDU.c, Line:499, Function:build_empty_pdol_data_block

 e[31mERR:e[0m i = 1 o_tag=9f02 o_len=6 9f 02   File:..\COS\APDU.c, Line:499, Function:build_empty_pdol_data_block

 e[31mERR:e[0m i = 2 o_tag=9f03 o_len=6 9f 03   File:..\COS\APDU.c, Line:499, Function:build_empty_pdol_data_block

 e[31mERR:e[0m i = 3 o_tag=9f1a o_len=2 9f 1a   File:..\COS\APDU.c, Line:499, Function:build_empty_pdol_data_block

 e[31mERR:e[0m i = 4 o_tag=0095 o_len=5 95 00   File:..\COS\APDU.c, Line:499, Function:build_empty_pdol_data_block

 e[31mERR:e[0m i = 5 o_tag=5f2a o_len=2 5f 2a   File:..\COS\APDU.c, Line:499, Function:build_empty_pdol_data_block

 e[31mERR:e[0m i = 6 o_tag=009a o_len=3 9a 00   File:..\COS\APDU.c, Line:499, Function:build_empty_pdol_data_block

 e[31mERR:e[0m i = 7 o_tag=009c o_len=1 9c 00   File:..\COS\APDU.c, Line:499, Function:build_empty_pdol_data_block

 e[31mERR:e[0m i = 8 o_tag=9f37 o_len=4 9f 37   File:..\COS\APDU.c, Line:499, Function:build_empty_pdol_data_block

 ***发送*** Apdu= hex is:

80 a8 00 00 23 83 21 20 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 01 56 00 00 00 00 00 01 56 14 05 30 60 11 22 33 44

80 A8 00 00 23 83 21 B6 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 01 56 00 00 00 00 00 01 56 11 12 09 00 64 51 D2 07 00

 

 ++++++ 接收成功 ++++++

   File:..\COS\APDU.c, Line:923, Function:iso7816_SendReceive

 $$$接收$$$ Apdu= hex is:77 4d 82 02 7c 00 94 0c 10 05 07 01 18 01 01 00 30 01 01 00 9f 36 02 0d e4 9f 26 08 65 71 37 7d 0c 6b 78 5e 9f 10 0a 07 01 01 03 90 00 00 01 0a 01 57 13 62 23 22 60 16 48 61 76 d1 80 12 20 14 16 94 00 00 00 0f 5f 34 01 00 9f 6c 02 00 00 90 00

//***************** Tlv Unpack Test *****************

++++++++++

Tag:82

Len:2

Val:

7C 00

应用交互特征(AIP)

++++++++++

Tag:94

Len:12

Val:

10 05 07 01 18 01 01 00 30 01 01 00

应用文件定位器(AFL)

++++++++++

Tag:9F36

Len:2

Val:

0D E4

应用交易计数器(ATC)

++++++++++

Tag:9F26

Len:8

Val:

65 71 37 7D 0C 6B 78 5E

应用密文(AC)

++++++++++

Tag:9F10

Len:10

Val:

07 01 01 03

90 00 00 01 0A 01

发卡行应用数据

++++++++++

Tag:57

Len:19

Val:

62 23 22 60 16 48 61 76 D1 80 12 20 14 16 94 00 00 00 0F

 

 pTLVEntity->au1Value= hex is:62 23 22 60 16 48 61 76 d1 80 12 20 14 16 94 00 00 00 0f

 

 e[32m银行卡号e[0m=6223226016486176   File:..\COS\APDU.c, Line:224, Function:getOneTagData磁条2等效数据

++++++++++

Tag:5F34

Len:1

Val:

00

应用主帐号序列号

++++++++++

Tag:9F6C

Len:2

Val:

00 00

** Unkown error code **

++++++++++

Tag:90

Len:0

Val:

发卡行公钥证书

 

 ***发送*** Apdu= hex is:00 b2 05 14 00

 

 ++++++ 接收成功 ++++++

   File:..\COS\APDU.c, Line:923, Function:iso7816_SendReceive

 $$$接收$$$ Apdu= hex is:70 40 5f 24 03 18 01 15 5a 08 62 23 22 60 16 48 61 76 9f 07 02 ff 00 8e 0c 00 00 00 00 00 00 00 00 1e 03 1f 00 9f 0d 05 d8 60 3c a8 00 9f 0e 05 00 10 80 00 00 9f 0f 05 d8 68 3c f8 00 5f 28 02 01 56 90 00

//***************** Tlv Unpack Test *****************

++++++++++

Tag:5F24

Len:3

Val:

18 01 15

应用失效日期

++++++++++

Tag:5A

Len:8

Val:

62 23 22 60 16 48 61 76

应用主账号(PAN)

++++++++++

Tag:9F07

Len:2

Val:

FF 00

应用用途控制(AUC)

++++++++++

Tag:8E

Len:12

Val:

00 00 00 00 00 00 00 00 1E 03 1F 00

持卡人验证方法(CVM)列表

++++++++++

Tag:9F0D

Len:5

Val:

D8 60 3C A8 00

发卡行行为代码(IAC) - 缺省

++++++++++

Tag:9F0E

Len:5

Val:

00 10 80 00 00

发卡行行为代码(IAC) - 拒绝

++++++++++

Tag:9F0F

Len:5

Val:

D8 68 3C F8 00

发卡行行为代码(IAC) - 联机

++++++++++

Tag:5F28

Len:2

Val:

01 56 onenote

发卡行国家代码

++++++++++

Tag:90

Len:0

Val:

发卡行公钥证书

 

 ***发送*** Apdu= hex is:00 b2 06 14 00

 ++++++ 接收成功 ++++++

   File:..\COS\APDU.c, Line:923, Function:iso7816_SendReceive

 $$$接收$$$ Apdu= hex is:70 81 c5 9f 46 81 b0 2e 2b 9d c0 51 54 e9 77 09 44 8f 40 fe 96 4d 3a 22 f9 8f 95 72 d4 6b a3 be 7a e6 d8 f0 1c 4a 58 ac 7b ab 4c d0 e2 1e 4e 86 b1 c0 6e 50 15 1c 92 56 08 85 18 99 2b 71 e5 0f fe 86 e1 f9 8e e7 58 22 49 a6 f2 97 81 bf 2e 89 24 a6 9e 20 95 72 28 07 bc f6 6b 00 f1 a2 9d 2e 1e 0a 8d 42 5c 9a ce 5f 32 57 23 12 b6 30 83 72 65 cc 56 e1 bf 38 f3 7b 0f 88 a6 c8 2e d7 d1 ef 49 4e ca 9c 65 7c 6c 05 4f 1f da 55 62 d3 38 f7 2f 0b 10 96 84 45 94 f4 1e bc 27 e2 6a f4 6a 8f 28 bb 5f ba 62 8c 9a eb c9 fa 37 fd 61 de 02 83 c4 f6 09 bd 62 b2 ed 9f 47 01 03 9f 48 0a 81 24 e9 72 a0 02 d7 89 00 5d 90 00

//***************** Tlv Unpack Test *****************

++++++++++

Tag:9F46

Len:176

Val:

2E 2B 9D C0 51 54 E9 77 09 44 8F 40 FE 96 4D 3A 22 F9 8F 95 72 D4 6B A3 BE 7A E6 D8 F0 1C 4A 58 AC 7B AB 4C D0 E2 1E 4E

86 B1 C0 6E 50 15 1C 92 56 08 85 18 99 2B 71 E5 0F FE 86 E1 F9 8E E7 58 22 49 A6 F2 97 81 BF 2E 89 24 A6 9E 20 95 72 28

07 BC F6 6B 00 F1 A2 9D 2E 1E 0A 8D 42 5C 9A CE 5F 32 57 23 12 B6 30 83 72 65 CC 56 E1 BF 38 F3 7B 0F 88 A6 C8 2E D7 D1

EF 49 4E CA 9C 65 7C 6C 05 4F 1F DA 55 62 D3 38 F7 2F 0B 10 96 84 45 94 F4 1E BC 27 E2 6A F4 6A 8F 28 BB 5F BA 62 8C 9A

EB C9 FA 37 FD 61 DE 02 83 C4 F6 09 BD 62 B2 ED

IC卡公钥证书

++++++++++

Tag:9F47

Len:1

Val:

03

IC卡公钥指数

++++++++++

Tag:9F48

Len:10

Val:

81 24 E9 72 A0 02 D7 89 00 5D

IC卡公钥余数

++++++++++

Tag:90

Len:0

Val:

发卡行公钥证书

 

 ***发送*** Apdu= hex is:00 b2 07 14 00

 

 

 ++++++ 接收成功 ++++++

   File:..\COS\APDU.c, Line:923, Function:iso7816_SendReceive

 $$$接收$$$ Apdu= hex is:70 81 cc 93 81 b0 19 ab 5f b9 78 72 e7 48 15 fb 0c 65 f4 67 ad aa e8 11 d0 76 25 ec 80 ee d2 5c 51 69 70 78 e4 7f a9 bc 27 45 34 6b f7 ad b6 4b b0 72 b7 49 84 5c 2c 64 5a 0f a3 0b 57 90 7c d6 be 40 19 78 75 76 db e4 4f e2 0e c9 cb 51 55 50 95 a0 db d6 cc e5 6e 90 20 7f 82 18 99 2a 24 e4 3b dc 68 58 5d 7a 98 1f e1 e6 03 4c 16 db f5 df d8 c9 27 21 fc df a4 32 f8 fe 91 70 9c 71 88 2f ca 98 3b c1 77 75 c1 cc 5a e5 c7 89 03 ca 5b 3f 52 56 d3 cb 92 a2 00 78 dc a5 ca 0e 75 dd 5b 6e 75 2a 21 07 31 51 3a 05 ff a1 37 5c 88 12 72 b7 15 1c 2a 2d e8 86 9f 49 03 9f 37 04 5f 25 03 13 01 15 9f 4a 01 82 9f 74 06 45 43 43 30 30 31 90 00

//***************** Tlv Unpack Test *****************

++++++++++

Tag:93

 NI

Len:176

Val:

19 AB 5F B9 78 72 E7 48 15 FB 0C 65 F4 67 AD AA E8 11 D0 76 25 EC 80 EE D2 5C 51 69 70 78 E4 7F A9 BC 27 45 34 6B F7 AD

B6 4B B0 72 B7 49 84 5C 2C 64 5A 0F A3 0B 57 90 7C D6 BE 40 19 78 75 76 DB E4 4F E2 0E C9 CB 51 55 50 95 A0 DB D6 CC E5

6E 90 20 7F 82 18 99 2A 24 E4 3B DC 68 58 5D 7A 98 1F E1 E6 03 4C 16 DB F5 DF D8 C9 27 21 FC DF A4 32 F8 FE 91 70 9C 71

88 2F CA 98 3B C1 77 75 C1 CC 5A E5 C7 89 03 CA 5B 3F 52 56 D3 CB 92 A2 00 78 DC A5 CA 0E 75 DD 5B 6E 75 2A 21 07 31 51

3A 05 FF A1 37 5C 88 12 72 B7 15 1C 2A 2D E8 86

签名的静态应用数据(SAD)

++++++++++

Tag:9F49

Len:3

Val:

9F 37 04

动态数据认证数据对象列表(DDOL)

++++++++++

Tag:5F25

Len:3

Val:

13 01 15

应用生效日期

++++++++++

Tag:9F4A

Len:1

Val:

82

静态数据认证标签列表

++++++++++

Tag:9F74

Len:6

Val:

45 43 43 30 30

31

 

 放不下 u16ValueSizeMax=3 < pTLVEntity->u2Length=6   File:..\COS\APDU.c, Line:174, Function:FillTagData电子现金发卡行授权码(EC Issuer Authorization Code)

++++++++++

Tag:90

Len:0

Val:

发卡行公钥证书

 

 ***发送*** Apdu= hex is:00 b2 01 1c 00

 

 ++++++ 接收成功 ++++++

   File:..\COS\APDU.c, Line:923, Function:iso7816_SendReceive

 $$$接收$$$ Apdu= hex is:70 81 e5 90 81 b0 39 4b ec aa d8 f9 06 ef 29 11 6b 21 74 13 14 49 50 c9 f8 fb 13 f9 23 f3 d6 0b bf e3 4f 11 18 b6 d7 d9 c4 e3 8f 78 30 f2 1a ac 74 41 e2 2d 19 b4 d6 f6 ca 27 f7 8b 10 8a 80 d4 ad e0 3e b1 17 ae 97 ed 00 0c 3a 47 d9 48 8f 4d 0f dc 31 d4 7e 2a a7 b4 01 50 b8 ce a5 a2 5c b2 08 b4 92 77 1c 07 f6 2a c1 2f 1a d6 e0 9a 66 1f ab ce c7 15 f8 f1 cf 05 a2 7c 21 8a b5 05 48 f2 8e fd 67 71 d0 a1 22 88 b2 8a 66 30 da 19 13 b0 c9 9b ea b4 89 3f da 0b c8 f8 71 7f 11 4b 59 6e e3 b0 b5 53 60 18 66 ae 3b 79 c9 60 43 5b 5e 91 85 7f de 1c f3 80 92 24 60 8a 48 5b 4a a2 11 ac 21 e3 b5 ea 0b c3 77 24 9b 53 bc f7 5d eb da eb b5 54 28 48 bb da b4 52 14 ff db ab 9f 32 01 03 8f 01 03 5f 30 02 02 20 90 00

//***************** Tlv Unpack Test *****************

++++++++++

Tag:90

Len:176NCA

Val:

39 4B EC AA D8 F9 06 EF 29 11 6B 21 74 13 14 49 50 C9 F8 FB 13 F9 23 F3 D6 0B BF E3 4F 11 18 B6 D7 D9 C4 E3 8F 78 30 F2

1A AC 74 41 E2 2D 19 B4 D6 F6 CA 27 F7 8B 10 8A 80 D4 AD E0 3E B1 17 AE 97 ED 00 0C 3A 47 D9 48 8F 4D 0F DC 31 D4 7E 2A

A7 B4 01 50

B8 CE A5 A2 5C B2 08 B4 92 77 1C 07 F6 2A C1 2F 1A D6 E0 9A 66 1F AB CE C7 15 F8 F1 CF 05 A2 7C 21 8A B5 05

48 F2 8E FD 67 71 D0 A1 22 88 B2 8A 66 30 DA 19 13 B0 C9 9B EA B4 89 3F DA 0B C8 F8 71 7F 11 4B 59 6E E3 B0 B5 53 60 18

66 AE 3B 79 C9 60 43 5B 5E 91 85 7F DE 1C F3 80

发卡行公钥证书

++++++++++

Tag:92

Len:36NINCA +36

Val:

60 8A 48 5B 4A A2 11 AC 21 E3 B5 EA 0B C3 77 24 9B 53 BC F7 5D EB DA EB B5 54 28 48 BB DA B4 52 14 FF DB AB

发卡行公钥余数

++++++++++

Tag:9F32

Len:1

Val:

03

发卡行公钥指数

++++++++++

Tag:8F

Len:1

Val:

03

CA公钥索引(PKI)

++++++++++

Tag:5F30

Len:2

Val:

02 20

服务码

++++++++++

Tag:90

Len:0

Val:

发卡行公钥证书

 

 ***发送*** Apdu= hex is:00 b2 01 34 00

 ++++++ 接收成功 ++++++

   File:..\COS\APDU.c, Line:923, Function:iso7816_SendReceive

 $$$接收$$$ Apdu= hex is:70 81 9d 9f 4b 81 90 66 b1 9f 50 c2 ef 25 44 6d 73 9f 2d 3f 5f 7a 0e 6e 3e 4e a3 5c 94 38 29 8e 54 2b a2 a8 2d 04 27 1f 2b b7 e2 84 2e b9 0f 0c bd 3f 40 1f 00 5d 20 9f 00 e7 6f 1d f3 83 8e c1 20 2f 6c 56 0f f4 7a b1 44 e3 ac 1e 35 db 6b 57 2b d6 b7 f0 69 a7 48 de 48 b3 40 df 50 6d 5b 45 d4 b8 c9 26 30 df 77 1a f3 b9 af c3 24 cb 93 96 8d 91 fa fc fe 25 29 11 ec 7d 29 bc 1d 00 12 4a 65 e7 c4 27 cd bb 54 cf cc 65 10 1e 6f 48 4d e4 1e a7 f4 e5 f4 c7 90 9f 5d 06 00 00 00 00 86 57 90 00

//***************** Tlv Unpack Test *****************

++++++++++

Tag:9F4B

Len:144

Val:

66 B1 9F 50 C2 EF 25 44 6D 73 9F 2D 3F 5F 7A 0E 6E 3E 4E

A3 5C 94 38 29 8E 54 2B A2 A8 2D 04 27 1F 2B B7 E2 84 2E B9 0F

0C BD 3F 40 1F 00 5D 20 9F 00 E7 6F 1D F3 83 8E C1 20 2F 6C 56 0F F4 7A B1 44 E3 AC 1E 35 DB 6B 57 2B D6 B7 F0 69 A7 48

DE 48 B3 40 DF 50 6D 5B 45 D4 B8 C9 26 30 DF 77 1A F3 B9 AF C3 24 CB 93 96 8D 91 FA FC FE 25 29 11 EC 7D 29 BC 1D 00 12

4A 65 E7 C4 27 CD BB 54 CF CC 65 10 1E 6F 48 4D E4 1E A7 F4 E5 F4 C7 90

签名的动态应用数据

++++++++++

Tag:9F5D 电子钱包余额

Len:6

Val:

00 00 00 00 86 57

** Unkown error code **

++++++++++

Tag:90

Len:0

Val:

发卡行公钥证书

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package br.com.paysmart; import java.util.List; import javax.smartcardio.*; import java.util.*; import java.text.SimpleDateFormat; public class paySmartTest { private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray(); public static String toHexString(byte[] buf) { char[] chars = new char[2 * buf.length]; for (int i = 0; i < buf.length; ++i) { chars[2 * i] = HEX_CHARS[(buf[i] & 0xF0) >>> 4]; chars[2 * i + 1] = HEX_CHARS[buf[i] & 0x0F]; } return new String(chars); } public static byte[] hexStringToByteArray(String s) { s = s.replaceAll("\\W+",""); int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16)); } return data; } public static byte[] concat( byte[]...arrays ) { // Determine the length of the result array int totalLength = 0; for (int i = 0; i < arrays.length; i++) { totalLength += arrays[i].length; } // create the result array byte[] result = new byte[totalLength]; // copy the source arrays into the result array int currentIndex = 0; for (int i = 0; i < arrays.length; i++) { System.arraycopy(arrays[i], 0, result, currentIndex, arrays[i].length); currentIndex += arrays[i].length; } return result; } public static byte[] getCurrentDateAsByteArray( String sFormat ) { SimpleDateFormat sdfDateFormatted = new SimpleDateFormat( sFormat ); Date now = new Date(); String sDate = sdfDateFormatted.format(now); return hexStringToByteArray ( sDate ); } public static byte[] extractTLVFromBuffer( int iTag, byte[] buf ) { //@todo: check size, check 77, etc int i; byte[] bufExtracted = buf; TLV tlvBuf = new TLV( buf, 0 ); if ( iTag <= 0xFF ) { //System.out.println("iTag= "+ iTag + " tlvBuf.type= " + tlvBuf.type + " buf= "+ toHexString( buf ) ); if ( tlvBuf.type == iTag ) { //System.out.println("Found tag = "+ iTag + " " + toHexString( tlvBuf.getValue() ) ); return tlvBuf.getValue(); } else { /* TLV tlvNext = tlvBuf.next; if ( tlvNext != null ) System.out.println( "next = " + toHexString( tlvNext.getDERData() ) ); else System.out.println( "next = NULL" ); while ( tlvNext != null ) { System.out.println("traversing next, looking for "+ iTag ); return extractTLVFromBuffer( iTag, tlvBuf.next.getDERData() ); } */ return extractTLVFromBuffer( iTag, tlvBuf.getValue() ); } } // lookup for iTag else { //@todo double tags /* byte bTag1 = (byte) ( iTag & 0x00FF ); byte bTag2 = (byte) (( iTag & 0xFF00 ) >> 2 ); */ } return buf; } public static String TLVListToString( byte[] bufTLV ) { String sList = ""; int iOffset = 0; int iTLV= 0; System.out.println("[TLVListToString]"); while ( iOffset < bufTLV.length ) { TLV tlvCurrent = new TLV( bufTLV, iOffset ); iTLV++; System.out.println(" TLV[" + iTLV + "].tag = " + tlvCurrent.type ); System.out.println(" TLV[" + iTLV + "].size = " + tlvCurrent.length ); System.out.println(" TLV[" + iTLV + "].value = " + toHexString(tlvCurrent.getValue() ) ); iOffset+= tlvCurrent.getDERData().length; //System.out.println(" TLV["+iTLV+"].DER = " + toHexString(tlvCurrent.getDERData() ) ); System.out.println( iOffset ); System.out.println(); sList += toHexString( tlvCurrent.getValue() ) + "\n"; } return sList; } public static String printAPDU( ResponseAPDU apdu ) { String sAux = apdu.toString() + " data=" + toHexString( apdu.getData() ); return sAux; } public static void main( String[] args ) { try { boolean boolEverythingAsTLV = true; int i; Random RandomNumberGenerator = new Random(); System.out.println("_______________________________________________________"); System.out.println("paySmart EMV Minimalist Terminal v1.0"); System.out.println("www.paySmart.com.br"); System.out.println("_______________________________________________________"); System.out.println(""); for (i=0; i<args.length; i++) System.out.println( "Param " + i + ": "+args[i] ); System.out.println(); if ( args.length < 2 ) { System.out.println(""); System.out.println("usage: paySmartTest #reader AID [Host Port]"); System.out.println(" example1> paySmartTest 0 A0000005551010"); System.out.println(" example2> paySmartTest 1 A000000555E010"); System.out.println(" example3> paySmartTest 1 A0000000041010"); System.out.println(" example4> paySmartTest 1 A0000000041010 10.2.1.1 887"); System.out.println(""); System.out.println("#ERROR# Invalid Params"); System.exit(1); // throw new Exception( "Invalid params" ); } TerminalFactory factory = TerminalFactory.getDefault(); List<CardTerminal> terminals = null; // Display the list of terminals try { terminals = factory.terminals().list(); System.out.println("Smart card readers: "); System.out.println( terminals ); } catch(Exception e) { System.out.println("#ERROR# No readers found"); System.exit(2); //throw new Exception( "No readers found" ); } int iReader=0; // Use the first terminal try { iReader = Integer.parseInt( args[0] ); } catch( Exception e ) { System.out.println("#ERROR# Invalid reader index format '"+args[0]+"'" ); System.exit(3);// throw new Exception( "Invalid reader index '"+args[0]+"'" ); } if ( iReader >= terminals.size() ) { System.out.println("#ERROR# Invalid reader index '"+args[0]+"'. Last valid index is " + (terminals.size()-1) ); System.exit(3); // throw new Exception( "Invalid reader index '"+iReader+"'. Last valid index is "+(terminals.size()-1) ); } CardTerminal terminal = terminals.get( iReader ); // Connect with the card Card card = null; CardChannel channel = null; try { card = terminal.connect("*"); System.out.println(" card: " + card ); channel = card.getBasicChannel(); System.out.println(" ATR=" + toHexString( card.getATR().getBytes() ) ); System.out.println( "" ); } catch( Exception e ) { System.out.println("#ERROR# Cannot connect to card"); System.exit(4); // throw new Exception( "Cannot connect to card" ); } // Send Select Application command //String sAID = "A000000555E010"; // MAIS ACEITO //String sAID = "A0 00 00 05 55 10 10"; String sAID = args[1]; byte[] bufAID = hexStringToByteArray( sAID ); System.out.println( "SELECT (AID = " + toHexString( bufAID ) + ")" ); ResponseAPDU answer = channel.transmit(new CommandAPDU(0x00, 0xA4, 0x04, 0x00, bufAID )); System.out.println( " FCI = "+ toHexString( answer.getData() ) ); System.out.println( "" ); if ( answer.getSW() != 0x9000 ) { System.out.println("#ERROR# Invalid AID '"+sAID+"'" ); System.exit(5); //throw new Exception( "Invalid AID '"+sAID+"'" ); } //Open MEL Application byte[] bufMEL = {(byte) 0x83, 0x00 }; System.out.println( "MEL (MEL = " + toHexString( bufMEL ) + ")" ); answer = channel.transmit( new CommandAPDU(0xBE, 0x12, 0x00, 0x00, bufMEL, 0x00 ) ); System.out.println( " " + printAPDU( answer ) ); //Send GPO byte[] bufPDOL = {(byte) 0x83, 0x00 }; System.out.println( "GPO (PDOL = " + toHexString( bufPDOL ) + ")" ); answer = channel.transmit( new CommandAPDU(0x80, 0xA8, 0x00, 0x00, bufPDOL ) ); System.out.println( " " + printAPDU( answer ) ); byte[] bufAIP = extractTLVFromBuffer( 0x82, answer.getData() ); //byte[] bufAFL = extractTLVFromBuffer( 0x94, answer.getData() ); System.out.println( " AIP = " + toHexString( bufAIP ) ); //System.out.println( " AFL = " + toHexString( bufAIP ) ); System.out.println( "" ); //Send ReadRecord 2 System.out.println( "READ RECORD (SFI=1, REC=2)" ); answer = channel.transmit( new CommandAPDU(0x00, 0xB2, 0x02, 0x0C, 0x3D ) ); //fixed :-( @todo GetResponse System.out.println( printAPDU( answer ) ); byte[] bufExpiryDate = {0x17, 0x01, 0x01}; //Arrays.copyOfRange( answer.getData(), 11, 03 ); System.out.println( " ExpiryDate= " + toHexString( bufExpiryDate ) ); byte [] bufSlice = Arrays.copyOfRange( answer.getData(), 14, answer.getData().length-14 ); byte[] bufPAN = extractTLVFromBuffer( 0x5A, bufSlice ); System.out.println( " PAN = " + toHexString(bufPAN) ); byte[] bufPANSequence = { 0x00 }; // @todo extractTLVFromBuffer( 0x5F34, ... ); System.out.println( " PANSequence = " + toHexString(bufPANSequence) ); System.out.println( "" ); //Send ReadRecord 3 System.out.println( "READ RECORD (SFI=1, REC=3)" ); answer = channel.transmit( new CommandAPDU(0x00, 0xB2, 0x03, 0x0C, 0x43 ) ); //fixed :-( @todo GetResponse System.out.println( printAPDU( answer ) ); byte[] bufSlice2 = Arrays.copyOfRange( answer.getData(), 2, answer.getData().length-2 ); byte[] bufTrack2 = extractTLVFromBuffer( 0x57, bufSlice2 ); System.out.println( " Track2= " + toHexString( bufTrack2 ) ); System.out.println( ); byte[] bufAmountAuthorized = hexStringToByteArray ("00 00 00 00 00 00"); // 9F02 06 ;$0.00 (assuming currency exponent = 2) byte[] bufAmountOther = hexStringToByteArray ("00 00 00 00 00 00"); // 9F03 06 ;$0.00 (assuming currency exponent = 2) byte[] bufTermCountryCode = hexStringToByteArray ("00 76"); // 9F1A 02 ;Brazil byte[] bufTVR = hexStringToByteArray ("00 00 00 08 00"); // 95 05 ;Merchant forced transaction to go online byte[] bufTxCurrencyCode = hexStringToByteArray ("09 86"); // 5F2A 02 ;Brazilian Reals (BRL) byte[] bufTxDate = getCurrentDateAsByteArray("yyMMdd"); // 9A 03 ;04.SET.2014 byte[] bufTxType = hexStringToByteArray ("00"); // 9C 01 ;Goods & services byte[] bufUN = new byte[4]; RandomNumberGenerator.nextBytes(bufUN); // 9F37 04 ;Unpredictable Number System.out.println( " [Transaction Parameters]"); System.out.println( " AmountAuthorized= "+ toHexString( bufAmountAuthorized ) ); System.out.println( " AmountOther= "+ toHexString( bufAmountOther ) ); System.out.println( " TCC= "+ toHexString( bufTermCountryCode ) ); System.out.println( " TVR= "+ toHexString( bufTVR ) ); System.out.println( " TxDate= "+ toHexString( bufTxDate ) ); System.out.println( " TxType= "+ toHexString( bufTxType ) ); System.out.println( " UN= "+ toHexString( bufUN ) ); System.out.println( ""); byte[] bufTxData = concat ( bufAmountAuthorized, bufAmountOther, bufTermCountryCode, bufTVR, bufTxCurrencyCode, bufTxDate, bufTxType, bufUN ); System.out.println( "GenerateAC (TxData= " + toHexString( bufTxData ) + ")" ); answer = channel.transmit( new CommandAPDU( 0x80, 0xAE, 0x40, 0x00, bufTxData ) ); System.out.println( printAPDU( answer ) ); System.out.println( "" ); // get 9F27, 9F36, 9F10, 9F26 byte[] bufResponse = Arrays.copyOfRange( answer.getData(), 2, answer.getData().length ); byte[] bufBit55 = concat( hexStringToByteArray ("82 02"), bufAIP, hexStringToByteArray ("84 07"), bufAID, hexStringToByteArray ("9F1A 02"), bufTermCountryCode, hexStringToByteArray ("95 05"), bufTVR, hexStringToByteArray ("9C 01"), bufTxType, hexStringToByteArray ("9F37 04"), bufUN, bufResponse ); if ( boolEverythingAsTLV ) { bufBit55 = concat( hexStringToByteArray ("5F34 01"), bufPANSequence, hexStringToByteArray ( "5A 08"), bufPAN, //hexStringToByteArray ("5F34 01"), bufPANSequence, hexStringToByteArray ("9F02 06"), bufAmountAuthorized, hexStringToByteArray ("9F03 06"), bufAmountOther, hexStringToByteArray ("5F2A 02"), bufTxCurrencyCode, hexStringToByteArray ( "9A 03"), bufTxDate, bufBit55 ); } System.out.println( "Bit55 = "); System.out.println( toHexString( bufBit55 ) ); System.out.println( ); // Disconnect the card card.disconnect(false); /* // Send to host if ( args.length >= 4 ) { String sHost = args[2]; int iPort = Integer.parseInt( args[3] ); SendISOPacket( sHost, iPort, bufPAN, bufAmountAuthorized, bufAmountOther, bufTxCurrencyCode, bufTxDate, bufExpiryDate, bufTermCountryCode, bufTrack2, bufBit55 ); } */ System.exit(0); } catch(Exception e) { System.out.println( "#ERROR#: " + e.toString() ); System.exit(6); } } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值