commit bbf0cb2fb94aba21d4760c240c93ff5f0624034e Author: Cheney Date: Tue Jun 29 11:32:24 2021 +0800 init files diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f0593a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +/.idea/ +/target/ +*.b64 +*.bin +*.iml +*.cer +/doc/ +*.log +/logs/ +*.sunyard.main.version +/public/ diff --git a/DProto/4D41.xml b/DProto/4D41.xml new file mode 100644 index 0000000..420cbee --- /dev/null +++ b/DProto/4D41.xml @@ -0,0 +1,116 @@ + + + + + 4D41 + + + + + P + + + + + + + + + + + + + + + + + + + 0 + + + + 1 + + + + X+K+27 位的索引号 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 索引号,具体要求组成见每 2 章节。 + + + + 需要 MAC 的数据(HEX 格式),n=4096 注:数据长度应该为 8 或 16 的整数倍,如果不是 8 或 16 的整数倍,系统默认在数据后面填充 0x00 组成 8 或 16 的整数倍。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为“X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + 4D42 + + + + + + + + + + + + + + + + + + 所计算出的MAC。有MAC返回标识决定,默认8H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + diff --git a/DProto/4D43.xml b/DProto/4D43.xml new file mode 100644 index 0000000..79fdf86 --- /dev/null +++ b/DProto/4D43.xml @@ -0,0 +1,123 @@ + + + + + + 4D43 + + + + + P + + + + + + + + + + + + + + + + + + 0 + + + + 1 + + + + X+K+27 位的索引号 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 索引号,具体要求组成见每 2 章节。 + + + + 所计算出的MAC。有MAC返回标识决定,默认8H + + + + 需要 MAC 的数据(HEX 格式),n=4096 注:数据长度应该为 8 或 16 的整数倍,如果不是 8 或 16 的整数倍,系统默认在数据后面填充 0x00 组成 8 或 16 的整数倍。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为“X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + + 4D44 + + + + + + + + + + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/60.xml b/DProto/60.xml new file mode 100644 index 0000000..e18dc4b --- /dev/null +++ b/DProto/60.xml @@ -0,0 +1,87 @@ + + + + + + 60 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + 可选项。最大长度为 32个字符。 + + + + + + + + 61 + + + + + + + + + + + + + + + + + + + + LMK14-15 加密下的密钥. + 密钥方案为S + + + 密钥明文的 MAC 值(X9.19)。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + diff --git a/DProto/61.xml b/DProto/61.xml new file mode 100644 index 0000000..7c092bb --- /dev/null +++ b/DProto/61.xml @@ -0,0 +1,93 @@ + + + + + 61 + + + + + IC 卡内存放的角色信息密文(LMK14-15) + 密钥方案X。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + 62 + + + + + + + + + + + + + + + + + + + + 1:系统管理员 + 2:密钥管理员. + 3: 配置管理员 + + + + 1:管理员1 + 2:管理员2 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + diff --git a/DProto/62.xml b/DProto/62.xml new file mode 100644 index 0000000..a361e31 --- /dev/null +++ b/DProto/62.xml @@ -0,0 +1,120 @@ + + + + + + 62 + + + + 密钥类型 + + + LMK加密下的应用密钥 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + 取值P(可选,没有此选项,默认为算法为IDEA,输出格式0) + + + + + + + + + + + + + + + 加押数据的字节长度 + + + 加押数据 + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + 可选项。最大长度为 32个字符。 + + + + + + + + 63 + + + + + + + + + + + + + + + + 密押,默认为8H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/63.xml b/DProto/63.xml new file mode 100644 index 0000000..91a95cb --- /dev/null +++ b/DProto/63.xml @@ -0,0 +1,129 @@ + + + + + + 63 + + + + 密钥类型 + + + LMK加密下的应用密钥 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + 取值P(可选,没有此选项,默认为算法为IDEA,输出格式0) + + + + + + + + + + + + + + + 需要验证的密押 + + + + 加押数据的字节长度 + + + 加押数据 + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + 可选项。最大长度为 32个字符。 + + + + + + + + 64 + + + + + + + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/64.xml b/DProto/64.xml new file mode 100644 index 0000000..2ab2b1b --- /dev/null +++ b/DProto/64.xml @@ -0,0 +1,134 @@ + + + + + + 64 + + + + 密钥类型 + + + LMK加密下的应用密钥 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + 加解密时,数据长度必须为分组长度 + + + + + + + 取值P(可选,没有此选项,默认为算法为IDEA,输出格式0) + + + + + + + + + + + + 数据的字节长度 + + + 数据 + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + 可选项。最大长度为 32个字符。 + + + + + + + + 65 + + + + + + + + + + + + + + + + 返回原数据长度 + + + 数据 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/65.xml b/DProto/65.xml new file mode 100644 index 0000000..36aff99 --- /dev/null +++ b/DProto/65.xml @@ -0,0 +1,127 @@ + + + + + + 65 + + + + 密钥类型 + + + LMK加密下的应用密钥 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + LMK加密下的应用密钥 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + 取值P(可选,没有此选项,默认为算法为IDEA,输出格式0) + + + + + + + + + + + + 密文数据长度 + + + 密文数据 + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + 可选项。最大长度为 32个字符。 + + + + + + + + 66 + + + + + + + + + + + + + + + + 密文数据长度 + + + 密文数据 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/66.xml b/DProto/66.xml new file mode 100644 index 0000000..25f1d39 --- /dev/null +++ b/DProto/66.xml @@ -0,0 +1,116 @@ + + + + + + 66 + + + + LMK(06-07)加密下的ZPK + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + + + + + + + 取值P(可选,没有此选项,默认为算法为3DES) + + + + + + + + + PIN数据 + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + 可选项。最大长度为 32个字符。 + + + + + + + + 67 + + + + + + + + + + + + + PIN数据 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + diff --git a/DProto/67.xml b/DProto/67.xml new file mode 100644 index 0000000..d3e3254 --- /dev/null +++ b/DProto/67.xml @@ -0,0 +1,101 @@ + + + + + + 67 + + + + LMK(06-07)加密下的ZPK + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + LMK(06-07)加密下的ZPK + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + 取值P(可选,没有此选项,默认为算法为3DES) + + + + + + + + + PIN密文 + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + 可选项。最大长度为 32个字符。 + + + + + + + + 68 + + + + + + + + + + + + + PIN密文 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + diff --git a/DProto/68.xml b/DProto/68.xml new file mode 100644 index 0000000..4ae9209 --- /dev/null +++ b/DProto/68.xml @@ -0,0 +1,161 @@ + + + + + + 68 + + + + LMK对(36-37)下加密的DEK。 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + 密文数据的字节长度 + + + 密文数据(强填充) + + + + + + + + + + + + + + + 公钥的长度(DER) + + + 公钥的DER编码 + + + 取值P(可选,没有此选项,默认为算法为SM4) + + + + + + + + + 取值Q(可选,没有此选项,默认为算法为ECB) + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 69 + + + + + + + + + + + + + + + + + + + 公钥加密的密文长度 + + + + 公钥加密的密文的DER编码 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/69.xml b/DProto/69.xml new file mode 100644 index 0000000..a268c62 --- /dev/null +++ b/DProto/69.xml @@ -0,0 +1,195 @@ + + + + + + 69 + + + + + + + + + + + + + + + + 数字为存储私钥的索引,除了 + 全 9 表示使用由命令中提供的密钥。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号。 + + + 私钥密文的长度 + 可选项,当私钥标记为全9时显示此域 + + + LMK加密的私钥 + 可选项,当私钥标记为全9时显示此域 + + + 公钥加密的密文长度 + + + 公钥加密的密文的DER编码 + + + LMK对(36-37)下加密的DEK。 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + + 取值P(可选,没有此选项,默认为算法为SM4) + + + + + + + + + 取值Q(可选,没有此选项,默认为算法为ECB) + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + 可选项。最大长度为 32个字符。 + + + + + + + + 6A + + + + + + + + + + + + + + + + + + + + 密文数据的字节长度 + + + + 密文数据(强填充) + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/6A.xml b/DProto/6A.xml new file mode 100644 index 0000000..6178b8b --- /dev/null +++ b/DProto/6A.xml @@ -0,0 +1,164 @@ + + + + + + 6A + + + + + + + + + + + + + + + + + + + 根据证书模式,需要输入内容项的长度 n + + + + + 可选项,只针对“证书模式”为 0时有。 + + + + 可选项,只针对“证书模式”为 1时有。 + + + + LMK 下加密密钥的方案。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 6B + + + + + + + + + + + + + + + + + + + 公钥加密的密钥密文长度 + + + + 公钥加密的密钥密文的 BASE64 编码 + + + + 如果是 'L' ,lmk 32 个字节长,否则 lmk 64 个字节长。 + + + + 对称密钥的密文,由 LMK30-31 保护。 + + + + 密钥校验值 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/6B.xml b/DProto/6B.xml new file mode 100644 index 0000000..a67bb3c --- /dev/null +++ b/DProto/6B.xml @@ -0,0 +1,164 @@ + + + + + + 6B + + + + + + + + + + + + + 根据证书模式,需要输入内容项的长度 n + + + + + 可选项,只针对“证书模式”为 0时有。 + + + + 可选项,只针对“证书模式”为 1时有。 + + + + 公钥加密的密钥密文长度 + + + + 公钥加密的密钥密文的 BASE64 编码 + + + + LMK 下加密密钥的方案。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 6C + + + + + + + + + + + + + + + + + + + + + + + + 如果是 'L' ,lmk 32 个字节长,否则 lmk 64 个字节长。 + + + + 对称密钥的密文,由 LMK30-31 保护。 + + + + 密钥校验值 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/6C.xml b/DProto/6C.xml new file mode 100644 index 0000000..6bd757e --- /dev/null +++ b/DProto/6C.xml @@ -0,0 +1,145 @@ + + + + + + 6C + + + + + + + + + + + + + 根据证书模式,需要输入内容项的长度 n + + + + + 可选项,只针对“证书模式”为 0时有。 + + + + 可选项,只针对“证书模式”为 1时有。 + + + + 数据长度 + + + + 签名数据内容 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 6D + + + + + + + + + + + + + + + + + + + 签名长度 + + + + 数字签名(BASE64) + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/6D.xml b/DProto/6D.xml new file mode 100644 index 0000000..b61b4eb --- /dev/null +++ b/DProto/6D.xml @@ -0,0 +1,161 @@ + + + + + + 6D + + + + + + + + + + + + + + 根据证书模式,需要输入内容项的长度 n + + + + + 可选项,只针对“证书模式”为 0时有。 + + + + 可选项,只针对“证书模式”为 1时有。 + + + + 可选项,只针对“证书模式”为2 时有。 + + + + 数据长度 + + + + 签名数据内容 + + + + + 签名长度 + + + + 签名 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 6E + + + + + + + + + + + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/6E.xml b/DProto/6E.xml new file mode 100644 index 0000000..d0c8458 --- /dev/null +++ b/DProto/6E.xml @@ -0,0 +1,93 @@ + + + + + + 6E + + + + + + + + + + + + + DN 长度 n + + + + Subject + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 6F + + + + + + + + + + + + 签名长度 + + + + SN + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/71.xml b/DProto/71.xml new file mode 100644 index 0000000..131c2ee --- /dev/null +++ b/DProto/71.xml @@ -0,0 +1,95 @@ + + + + + + 71 + + + + + + + + + LMK30-31下加密的密钥 + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 72 + + + + + + + + + + + + + + + + + + + 公钥加密的密文长度 + + + + 公钥加密的密文的DER编码 + + + + + + + + + \ No newline at end of file diff --git a/DProto/72.xml b/DProto/72.xml new file mode 100644 index 0000000..786f291 --- /dev/null +++ b/DProto/72.xml @@ -0,0 +1,156 @@ + + + + + + 72 + + + + + 公钥长度 + + + + 公钥的 DER 编码 + + + + LMK 下加密密钥的方案。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 73 + + + + + + + + + + + + + + + + + + + 公钥加密的密钥密文长度 + + + + + 公钥加密的密钥密文的 DER 编码 + + + + + 如果是 'L' ,lmk 32 个字节长,否则 lmk 64 个字节长。 + + + + 对称密钥的密文,由 LMK30-31 保护。 + + + + 密钥校验值 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/73.xml b/DProto/73.xml new file mode 100644 index 0000000..c5ce149 --- /dev/null +++ b/DProto/73.xml @@ -0,0 +1,158 @@ + + + + + + 73 + + + + + + 数字为存储私钥的索引,除了 + 全 9 表示使用由命令中提供的密钥。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号。 + + + + 当私钥标记为全 9 时使用该区域的值 + + + + 当私钥标记为全 9 时使用该区域的值 + + + + + + + + LMK 下加密密钥的方案。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 74 + + + + + + + + + + + + + + + + + + + 如果是 'L' ,lmk 32 个字节长,否则 lmk 64 个字节长。 + + + + 对称密钥的密文,由 LMK30-31 保护。 + + + + 密钥校验值 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/74.xml b/DProto/74.xml new file mode 100644 index 0000000..62fe391 --- /dev/null +++ b/DProto/74.xml @@ -0,0 +1,188 @@ + + + + + + 74 + + + + + + + + + + + 可选项,只对“签名数据类型”为 0 时有效。 + + + + 最大为 64(必须是 4 的整数倍),只对“签名数据类型”为 1 时有效 + + + + + 可选项,只对“签名数据类型”为 1 时有效。 + + + + 可选项,只对“签名数据类型”为 1 时有效。 + + + + + 可选项,只对“签名数据类型”为 1 时有效。 + + + + 可选项,只对“签名数据类型”为 1 时有效。 + + + + 可选项,只对“签名数据类型”为 1 时有效。 + + + + 数字为存储私钥的索引,除了 + 全 9 表示使用由命令中提供的密钥。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号。 + + + + 可选项,当私钥标记为全 9 时显示此域 + + + + 可选项,当私钥标记为全 9 时显示此域 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 75 + + + + + + + + + + + + + + + + + + + + + + + 签名的字节长度 + + + + 签名的 DER 编码 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/75.xml b/DProto/75.xml new file mode 100644 index 0000000..21e856e --- /dev/null +++ b/DProto/75.xml @@ -0,0 +1,164 @@ + + + + + + 75 + + + + + 签名的字节长度 + + + + 计算的签名(DER) + + + + + + + + + + + 可选项,只对“签名数据类型”为 0 时有效。 + + + + + + 最大为 64(必须是 4 的整数倍),只对“签名数据类型”为 1 时有效 + + + + + 可选项,只对“签名数据类型”为 1 时有效。 + + + + 可选项,只对“签名数据类型”为 1 时有效。 + + + + 可选项,只对“签名数据类型”为 1 时有效。 + + + + 公钥的长度(DER) + + + + 公钥的 DER 编码 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 76 + + + + + + + + + + + + + + + + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/76.xml b/DProto/76.xml new file mode 100644 index 0000000..ad84f6d --- /dev/null +++ b/DProto/76.xml @@ -0,0 +1,145 @@ + + + + + + 76 + + + + + + + + + + + + + + 消息长度。 + + + + 二进制的消息块 + + + + + 最大为 64(必须是 4 的整数倍),只对“消息块号”为 0、1 时有效 + + + + + 可选项,只对“消息块号”为 0、1 时有效。 + + + + + 公钥的长度(DER) + + + + 公钥的 DER 编码 + + + + 只对“消息块号”为 2、3 时有效 + + + + 只对“消息块号”为 2、3 时有效 + + + + + + + + + + 77 + + + + + + + + + + + + + + + 只对“消息块号”为 2、1 时有效 + + + + 只对“消息块号”为 2、1 时有效 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/77.xml b/DProto/77.xml new file mode 100644 index 0000000..8df6db0 --- /dev/null +++ b/DProto/77.xml @@ -0,0 +1,121 @@ + + + + + + 77 + + + + + + + + + + + + + + + + + + + 公钥的长度(DER) + + + + 公钥的 DER 编码 + + + + 数据长度 + + + + 数据 + + + + + + + + + + + 78 + + + + + + + + + + + + + + + + + + 公钥加密的密文长度 + + + + 公钥加密的密文的 DER 编码(对于 RSA 算法,数据类 + 型为 BIT). + + + + + + + + + diff --git a/DProto/78.xml b/DProto/78.xml new file mode 100644 index 0000000..7f72fad --- /dev/null +++ b/DProto/78.xml @@ -0,0 +1,155 @@ + + + + + + 78 + + + + + + + + + + + + + + + + + + + 数字为存储私钥的索引,除了 + 全 9 表示使用由命令中提供的密钥。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号。 + + + + 可选项,当私钥标记为全 9 时显示此域 + + + + 可选项,当私钥标记为全 9 时显示此域 + + + + 密文数据长度 + + + + 密文数据(DER 编码) + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 79 + + + + + + + + + + + + + + + + + + + 解密出的明文长度 + + + + 公钥加密的密文的 DER 编码(对于 RSA 算法,数据类 + 型为 BIT). + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/79.xml b/DProto/79.xml new file mode 100644 index 0000000..f905172 --- /dev/null +++ b/DProto/79.xml @@ -0,0 +1,136 @@ + + + + + + 79 + + + + + + + + + + + + + + + + + + + 数字为存储私钥的索引,除了 + 全 9 表示使用由命令中提供的密钥。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号。 + + + + 私钥的长度(DER) + + + + 私钥值 + + + + 数据长度 + + + + 数据 + + + + + + + + + + + 7A + + + + + + + + + + + + + + + + + + 密文长度 + + + + 密文的 DER 编码(对于 RSA 算法,数据类型为 BIT). + + + + + + + + + diff --git a/DProto/7A.xml b/DProto/7A.xml new file mode 100644 index 0000000..806954e --- /dev/null +++ b/DProto/7A.xml @@ -0,0 +1,120 @@ + + + + + + 7A + + + + + + + + + + + + + + + + + + + 公钥的长度(DER) + + + + 公钥的 DER 编码 + + + + 数据长度 + + + + 数据 + + + + + + + + + + + 7B + + + + + + + + + + + + + + + + + + 明文长度 + + + + 明文 + + + + + + + + + diff --git a/DProto/7B.xml b/DProto/7B.xml new file mode 100644 index 0000000..b2a8deb --- /dev/null +++ b/DProto/7B.xml @@ -0,0 +1,161 @@ + + + + + + 7B + + + + + + + + + + + 指示用于哈希证书数据的哈希算法的标识 + + + + + + + + + 可选项,只对“签名数据类型”为 0 时有效。 + + + + 可选项,只对“签名数据类型”为 1 时有效。 + + + + 可选项,只对“签名数据类型”为 1 时有效。 + + + + privateKeyTag len="27" cn="指示私钥位置的标记"> + 数字为存储私钥的索引,除了 + 全 9 表示使用由命令中提供的密钥。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号。 + + + + 可选项,当私钥标记为全 9 时显示此域 + + + + 可选项,当私钥标记为全 9 时显示此域 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + 7C + + + + + + + + + + + + + + + + + + 签名的字节长度 + + + + 签名的 DER 编码 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/7C.xml b/DProto/7C.xml new file mode 100644 index 0000000..b9e327c --- /dev/null +++ b/DProto/7C.xml @@ -0,0 +1,164 @@ + + + + + + 7C + + + + + 签名的字节长度 + + + + 计算的签名(DER) + + + + + + + + + + + 指示用于哈希证书数据的哈希算法的标识 + + + + + + + + + 可选项,只对“签名数据类型”为 0 时有效。 + + + + 可选项,只对“签名数据类型”为 1 时有效。 + + + + 可选项,只对“签名数据类型”为 1 时有效。 + + + + 公钥的长度(DER) + + + + 公钥的 DER 编码 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 7D + + + + + + + + + + + + + + + + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/7D.xml b/DProto/7D.xml new file mode 100644 index 0000000..92312ed --- /dev/null +++ b/DProto/7D.xml @@ -0,0 +1,127 @@ + + + + + + 7D + + + + + + + + + + + + + + + + + + + 消息长度。 + + + 二进制的消息块 + + + + 只对“消息块号”为 2、3 时有效 + + + + 只对“消息块号”为 2、3 时有效 + + + + + + + + + + 7E + + + + + + + + + + + + + + + 只对“消息块号”为 2、1 时有效 + + + + 只对“消息块号”为 2、1 时有效 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/7E.xml b/DProto/7E.xml new file mode 100644 index 0000000..9ea918a --- /dev/null +++ b/DProto/7E.xml @@ -0,0 +1,86 @@ + + + + + + 7E + + + + + + + + + + + 证书长度 + + + + 证书 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 7F + + + + + + + + + + + 公钥的字节长度 + + + + 公钥 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/80.xml b/DProto/80.xml new file mode 100644 index 0000000..407fa45 --- /dev/null +++ b/DProto/80.xml @@ -0,0 +1,119 @@ + + + + + + 80 + + + + + 证书序列号的长度 + + + + X509证书序号 + + + + 数据长度 + + + + 数据 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 81 + + + + + + + + + + + + + + + + + + + + 签名的字节长度 + + + + 签名的 DER 编码 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/8003.xml b/DProto/8003.xml new file mode 100644 index 0000000..f28d44c --- /dev/null +++ b/DProto/8003.xml @@ -0,0 +1,128 @@ + + + + + + 8003 + + + + + + + + + + + 若上面的标志为1,则此域为证书DN,若为0,则此域为两个字节的证书索引; + + + + 待签名数据长度 + + + + 待签名数据 + + + + + + + + + + + 8004 + + + + + + + + + + + + + + + + + + + + + + + 签名的字节长度 + + + + 签名的 DER 编码 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/8004.xml b/DProto/8004.xml new file mode 100644 index 0000000..539e388 --- /dev/null +++ b/DProto/8004.xml @@ -0,0 +1,176 @@ + + + + + + 8004 + + + + + + + + + + + + 若上面的标志为1,则此域为证书DN,若为0,则此域为两个字节的证书索引;若为2,该域不存在 + + + + 标志为2 时存在 + + + + 标志为2 时存在 + + + + + 待签名数据长度 + + + + 待签名数据 + + + + 签名的字节长度 + + + + 签名的 DER 编码 + + + + + + + + + + + + + + + + + 8005 + + + + + + + + + + + + + + + + + + + + 信息长度 + + + + 若发送报文返回证书信息标志位为0,则返回一段垃圾数据,可以不用管 + 若发送报文返回证书信息标志位为1,则返回 CERT_INFO 结构的证书数据 + + + + + + + + + diff --git a/DProto/8005.xml b/DProto/8005.xml new file mode 100644 index 0000000..1eeb19f --- /dev/null +++ b/DProto/8005.xml @@ -0,0 +1,101 @@ + + + + + + 8005 + + + + + X509证书序号 + + + + + + + + 数据长度 + + + + 数据 + + + + + + + + + + + 8006 + + + + + + + + + + + + + + + + + + + + 签名的字节长度 + + + + 签名的 DER 编码 + + + + + + + + + diff --git a/DProto/8006.xml b/DProto/8006.xml new file mode 100644 index 0000000..3c6a4b2 --- /dev/null +++ b/DProto/8006.xml @@ -0,0 +1,130 @@ + + + + + + 8006 + + + + + + + + + 待签名数据长度 + + + + 待签名数据 + + + + + 已签名数据长度 + + + + 已签名数据 + + + + + + + + + + + + + + + + + + 8007 + + + + + + + + + + + + + + + + + + + + 信息长度 + + + + 若发送报文返回证书信息标志位为0,则返回已签名数据, + 若发送报文返回证书信息标志位为1,则返回 CERT_INFO 结构的证书数据 + + + + + + + + + diff --git a/DProto/8012.xml b/DProto/8012.xml new file mode 100644 index 0000000..d3a2adf --- /dev/null +++ b/DProto/8012.xml @@ -0,0 +1,155 @@ + + + + + + 8012 + + + + + 待签名数据长度 + + + + 待签名数据 + + + + + 已签名数据长度 + + + + 已签名数据 + + + + + + + + + + + + + 标志为0002 时存在 + + + + 标志为0002 时存在 + + + + + + + + + + + 8013 + + + + + + + + + + + + + + + + + + + + 信息长度 + + + + 若发送报文返回证书信息标志位为0,则返回已签名数据, + 若发送报文返回证书信息标志位为1,则返回CERT_INFO结构的证书数据 + + + + + + diff --git a/DProto/8016.xml b/DProto/8016.xml new file mode 100644 index 0000000..32a8186 --- /dev/null +++ b/DProto/8016.xml @@ -0,0 +1,97 @@ + + + + + + 8016 + + + + + + + + + + + + + 8017 + + + + + + + + + + + + + + + + + + + + + + + 证书信息的字节长度 + + + + 证书信息 + + + + + + + + diff --git a/DProto/8017.xml b/DProto/8017.xml new file mode 100644 index 0000000..cb57ee7 --- /dev/null +++ b/DProto/8017.xml @@ -0,0 +1,99 @@ + + + + + + 8017 + + + + 用户编号 + + + + + + + + + + + + 8018 + + + + + + + + + + + + + + + + + + + + + + + 证书的字节长度 + + + + 证书 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/8018.xml b/DProto/8018.xml new file mode 100644 index 0000000..e9cf04e --- /dev/null +++ b/DProto/8018.xml @@ -0,0 +1,93 @@ + + + + + + 8018 + + + + + X509证书序号 + + + + 数据长度 + + + + 数据 + + + + + + + + + + + 8006 + + + + + + + + + + + + + + + + + + + + 签名的字节长度 + + + + 签名的 DER 编码 + + + + + + + + + \ No newline at end of file diff --git a/DProto/8019.xml b/DProto/8019.xml new file mode 100644 index 0000000..2f01c74 --- /dev/null +++ b/DProto/8019.xml @@ -0,0 +1,105 @@ + + + + + + 8019 + + + + + X509证书序号 + + + + 已签名数据长度 + + + + 已签名数据 + + + + + + + + + + + + + + + + + + 8007 + + + + + + + + + + + + + + + + + + + + 信息长度 + + + + 若发送报文返回证书信息标志位为0,则返回已签名数据, + 若发送报文返回证书信息标志位为1,则返回CERT_INFO结构的证书数据 + + + + + + + + + \ No newline at end of file diff --git a/DProto/8024.xml b/DProto/8024.xml new file mode 100644 index 0000000..5b84a1f --- /dev/null +++ b/DProto/8024.xml @@ -0,0 +1,104 @@ + + + + + + 8024 + + + + + 密钥对应的索引号。 + + + + + + + + 数据长度 + + + + 数据 + + + + + + + + + + + 8025 + + + + + + + + + + + + + + + + + + + + 签名的字节长度 + + + + 签名的 DER 编码 + + + + + + + + + diff --git a/DProto/8025.xml b/DProto/8025.xml new file mode 100644 index 0000000..864e473 --- /dev/null +++ b/DProto/8025.xml @@ -0,0 +1,130 @@ + + + + + + 8025 + + + + + + + + + 待签名数据长度 + + + + 待签名数据 + + + + + 已签名数据长度 + + + + 已签名数据 + + + + + + + + + + + + + + + + + + 8026 + + + + + + + + + + + + + + + + + + + + 信息长度 + + + + 若发送报文返回证书信息标志位为0,则返回已签名数据, + 若发送报文返回证书信息标志位为1,则返回 CERT_INFO 结构的证书数据 + + + + + + + + + diff --git a/DProto/8026.xml b/DProto/8026.xml new file mode 100644 index 0000000..b2277a7 --- /dev/null +++ b/DProto/8026.xml @@ -0,0 +1,105 @@ + + + + + + 8026 + + + + + 证书序列号的长度 + + + + X509证书序号 + + + + ‘p’:为p时传入数据为SM3-HASH值 + + + + 待签名数据的HASH标志位存在时存在 + + + + 待签名数据长度。签名数据类型志位存在时不存在 + + + + 待签名数据内容。签名数据类型志位存在时不存在 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 8027 + + + + + + + + + + + + + + 符合PKCS7标准的签名结果 + + + + + + + + + diff --git a/DProto/81.xml b/DProto/81.xml new file mode 100644 index 0000000..aeb5ffd --- /dev/null +++ b/DProto/81.xml @@ -0,0 +1,121 @@ + + + + + + 81 + + + + + 证书序列号的长度 + + + + X509证书序号 + + + + + 数据长度。 + + + + 签名数据内容 + + + + 签名的字节长度 + + + + 计算的签名(DER) + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 82 + + + + + + + + + + + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/82.xml b/DProto/82.xml new file mode 100644 index 0000000..6a1f178 --- /dev/null +++ b/DProto/82.xml @@ -0,0 +1,136 @@ + + + + + + 82 + + + + + 输入的数据长度,十六进制值表示。如:“0021”表示输入数据为21字节。密钥长度由散列算法决定。 + 散列摘要长度L <= Key_Length <= 散列数据块。 + + + + 秘钥数据 + + + + 指示用于哈希证书数据的哈希算法的类型 + + + + + + + + + + + 输入的散列上下文信息长度;如果是第一个散列报文,则值送0000,后面数据将不存在。 + + + + 输入的散列上下文信息,加密机输出,原文传入 + + + + 消息长度 + + + + 二进制的消息块 + + + + + + + + + + 83 + + + + + + + + + + + + 上下文信息的长度,原始数据过大分包计算时需要传入上下文信息。 + + + + 如果数据分包,则下次请求需要无更改传入此上下文信息。 + + + + 输出的数据长度,十六进制值表示。如:“0021”表示输入数据为21字节。 + + + + 当调用成功时,返回散列值,长度由散列算法确定: + + + + + + + + + \ No newline at end of file diff --git a/DProto/83.xml b/DProto/83.xml new file mode 100644 index 0000000..8c2d195 --- /dev/null +++ b/DProto/83.xml @@ -0,0 +1,127 @@ + + + + + + 83 + + + + + + + + + + + + + + + + + + + + + + + + + + + + 应用主密钥密钥类型 + + + + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号,‘K’为传入索引标志; + + + + 用于分散主密钥生成卡片密钥 + + + + 用于进一步分散卡片密钥生成会话密钥,VISA卡,卡片密钥与会话密钥相同。 + + + + 待验证ARQC,同时参与ARPC生成 + + + + 模式为0/1时存在,用于计算ARQC并校验的数据长度 + + + + 用于计算ARQC并校验的数据 + + + + 模式为1/2时存在,作用于ARQC,然后用于计算ARPC + + + + + + + + 84 + + + + + + + + + + + + + + 模式为1/2,输出AQPC + + + + + + + + + \ No newline at end of file diff --git a/DProto/93.xml b/DProto/93.xml new file mode 100644 index 0000000..c15db28 --- /dev/null +++ b/DProto/93.xml @@ -0,0 +1,109 @@ + + + + + + 93 + + + + + + + + + + + + + + + + + + + + + + + + + + 94 + + + + + + + + + + + + + + + + + + + 设备编号 + + + + 签名长度 + + + + 密钥 + + + + + + + + + \ No newline at end of file diff --git a/DProto/94.xml b/DProto/94.xml new file mode 100644 index 0000000..3302d93 --- /dev/null +++ b/DProto/94.xml @@ -0,0 +1,131 @@ + + + + + + 94 + + + + 公钥长度 + + + DER 编码的公钥 + + + 附加信息长度 + + + 附加信息 + + + + 密钥方案 + + + + + + + + + + + 95 + + + + + + + + + + + + + + + + + + + 密钥长度 + + + + 密钥 + + + + + 如果是 'Z' , 16 个字节长 + 如果是 'X,U,S' , 32 个字节长 + 如果是 'Y,T' , 48 个字节长 + + + + LMK 对 16-17 下加密的 TAK + + + + 用 TAK 加密 64 位 0 的结果。是 16H 还是 6H 取决于 KCV + 的类型选项。 当 LMK 的密钥方案为 S 时,默认或 KCV + 类型为 0 时,输出 32H 的 KCV + + + + + + + + + diff --git a/DProto/95.xml b/DProto/95.xml new file mode 100644 index 0000000..1c0a84c --- /dev/null +++ b/DProto/95.xml @@ -0,0 +1,147 @@ + + + + + + 95 + + + + + + + + + + 公钥加密后的密钥的长度 + + 公钥加密后的密钥 + + + LMK 下加密密钥的方案。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + 96 + + + + + + + + + + + + + + + + + + + 如果是 'L' ,lmk 32 个字节长,否则 lmk 64 个字节长。 + + + + 对称密钥的密文,由 LMK30-31 保护。 + + + + 密钥校验值 + + + + 附加信息长度 + + + + 附加信息 + + + + + + + + + \ No newline at end of file diff --git a/DProto/96.xml b/DProto/96.xml new file mode 100644 index 0000000..79d2a9a --- /dev/null +++ b/DProto/96.xml @@ -0,0 +1,113 @@ + + + + + + 96 + + + + + + + + + + + + + + + + + + + 97 + + + + + + + + + + + + + + + + + + + 合成密钥 + + + + 密钥校验值 + + + + 附加信息长度 + + + + 附加信息 + + + + + + + + + \ No newline at end of file diff --git a/DProto/A0.xml b/DProto/A0.xml new file mode 100644 index 0000000..b9e2e4d --- /dev/null +++ b/DProto/A0.xml @@ -0,0 +1,170 @@ + + + + + + A0 + + + + + + + + + + + 密钥类型 + + + + 密钥长度/LMK 下加密密钥的方案。 + + + + 仅当模式为 1 时才显示该 ZMK 域 + + + + 加密输出密钥的密钥方案。仅当模式为 1 时才显示该域 + + + + N + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + A1 + + + + + + + + + + + + + + + + 如果是 'Z' ,lmk 16 个字节长 + 如果是 'X,U,S' ,lmk 32 个字节长 + 如果是 'Y,T' ,lmk 48 个字节长 + + + + LMK 加密下的密钥。 + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + ZMK 加密下的密钥。 + + + + 密钥校验值。当存在 ZMK 密钥时,以 ZMK 保护新密钥 + 的方案为基准,否则以 LMK 保护新密钥的方案为基准。 + 当保护新密钥的密钥方案为 S 时,输出 32H, KCV 计 + 算算法为 SM4,否则,输出 16H,KCV 计算算法为 + DES/3DES + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/A2.xml b/DProto/A2.xml new file mode 100644 index 0000000..06210de --- /dev/null +++ b/DProto/A2.xml @@ -0,0 +1,118 @@ + + + + + + A2 + + + + 密钥类型 + + + + 密钥长度/LMK 下加密密钥的方案。 + + + + 业务标识 + + + + ; 分隔多个打印域 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + A3 + + + + + + + + + + + + + + + + + + + + 如果是 'Z' ,lmk 16 个字节长 + 如果是 'X,U,S' ,lmk 32 个字节长 + 如果是 'Y,T' ,lmk 48 个字节长 + + + + LMK 加密下的密钥。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/A4.xml b/DProto/A4.xml new file mode 100644 index 0000000..c37c8fd --- /dev/null +++ b/DProto/A4.xml @@ -0,0 +1,124 @@ + + + + + + A4 + + + + 2到9 + + + + 查看密钥类型表。 + + + + LMK下加密密钥的方案 + + + + 所有成分 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + A5 + + + + + + + + + + + + + + + + + + + 如果是 'Z' ,lmk 16 个字节长 + 如果是 'X,U,S' ,lmk 32 个字节长 + 如果是 'Y,T' ,lmk 48 个字节长 + + + + LMK 加密下的密钥。 + + + + 密钥校验值。密钥方案为S时,此载为32H。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/A6.xml b/DProto/A6.xml new file mode 100644 index 0000000..2ccb7d1 --- /dev/null +++ b/DProto/A6.xml @@ -0,0 +1,139 @@ + + + + + + A6 + + + + + 密钥类型 + + + + ZMK。 + 27 位的索引号: 16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + ZMK 加密下的密钥。 + + + + 加密输出密钥的密钥方案。 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + A7 + + + + + + + + + + + + + + + + + + + + 如果是 'Z' ,lmk 16 个字节长 + 如果是 'X,U,S' ,lmk 32 个字节长 + 如果是 'Y,T' ,lmk 48 个字节长 + + + + LMK 加密下的密钥。 + + + + 密钥校验值。当 LMK 保护密钥的方案为‘S’,KCV 为 + 32H,算法为 SM4,否则 KCV 为 16H,算法为 DES/3DES + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/A8.xml b/DProto/A8.xml new file mode 100644 index 0000000..da11321 --- /dev/null +++ b/DProto/A8.xml @@ -0,0 +1,134 @@ + + + + + + A8 + + + + + 查看密钥类型表 + + + + ZMK。 + 27 位的索引号: 16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + LMK 加密的密钥。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 加密输出密钥的密钥方案 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + A9 + + + + + + + + + + + + + + + + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + ZMK 加密下的密钥。 + + + + 密钥校验值。当 ZMK 保护密钥的方案为‘S’,KCV 为 + 32H,算法为 SM4,否则 KCV 为 16H,算法为 DES/3DES + 密钥校验值,当密钥方案为 S 时输出 32H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/AA.xml b/DProto/AA.xml new file mode 100644 index 0000000..342b466 --- /dev/null +++ b/DProto/AA.xml @@ -0,0 +1,119 @@ + + + + + + AA + + + + + 密钥类型 + + + + LMK 下加密密钥的方案 + + + + 两个明文分量异或合成 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + AB + + + + + + + + + + + + + + 如果是 'X,U,S' ,lmk 32 个字节长 + 如果是 'Y,T' ,lmk 48 个字节长 + + + + LMK 加密下的密钥。 + + + + 密钥校验值。当保护新密钥的密钥方案为 S 时, + 输出 32H, KCV 计算算法为 SM4,否则,输出 + 16H,KCV 计算算法为 DES/3DES + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/AB.xml b/DProto/AB.xml new file mode 100644 index 0000000..6d6e873 --- /dev/null +++ b/DProto/AB.xml @@ -0,0 +1,101 @@ + + + + + AB + + + + + 密钥类型(固定为002)。 + + + + LMK下加密密钥的方案。 + + + + 取值P,默认算法由密钥方案决定 + + + + + + + + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + AC + + + + + + + + + + + + + + + + + + 密钥明文的校验值 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + diff --git a/DProto/AE.xml b/DProto/AE.xml new file mode 100644 index 0000000..b37e5db --- /dev/null +++ b/DProto/AE.xml @@ -0,0 +1,124 @@ + + + + + + AE + + + + + LMK 对(14-15)下加密的当前 TMK、 TPK 或 PVK + + + + LMK 对(14-15)下加密的存储 TMK、 TPK 或 PVK + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。TMK 下加密密钥的方案。 + + + + 可选项。LMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + AF + + + + + + + + + + + + + + + + 如果是 'Z' , 16 个字节长 + 如果是 'X,U,S' , 32 个字节长 + 如果是 'Y,T' , 48 个字节长 + + + + 当前密钥下加密的存储密钥 + + + + 用 ZPK 加密 64 位 0 的结果。是 16H 还是 6H 取决于 KCV + 的类型选项。 + 当输出的 ZMK 加密的 ZPK 密钥方案为 S 时,KCV 选项 + 为 0 是,输入出 32H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/AG.xml b/DProto/AG.xml new file mode 100644 index 0000000..b6c4400 --- /dev/null +++ b/DProto/AG.xml @@ -0,0 +1,137 @@ + + + + + + AG + + + + + LMK 对(14-15)下加密的 TMK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + LMK 对(16-17)下加密的 TAK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。TMK 下加密密钥的方案 + + + + 可选项。LMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + AH + + + + + + + + + + + + + + + + + + 如果是 'Z' , 16 个字节长 + 如果是 'X,U,S' , 32 个字节长 + 如果是 'Y,T' , 48 个字节长 + + + + 转换后的 TAK;TMK 下加密。 + + + + 用 TAK 加密 64 位 0 的结果。是 16H 还是 6H 取决于 KCV + 的类型选项。当 TMK 的密钥方案为 S 时,默认或 KCV + 类型为 0 时,输出 32H 的 KCV + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/B0.xml b/DProto/B0.xml new file mode 100644 index 0000000..bbf40b5 --- /dev/null +++ b/DProto/B0.xml @@ -0,0 +1,95 @@ + + + + + + B0 + + + + + 密钥类型 + + + + LMK 加密下的密钥。 + + + + 密钥长度/LMK 下加密密钥的方案 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + B1 + + + + + + + + + + + + + + + + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + LMK 加密下的密钥。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/BA.xml b/DProto/BA.xml new file mode 100644 index 0000000..6e60d75 --- /dev/null +++ b/DProto/BA.xml @@ -0,0 +1,94 @@ + + + + + 加密一个文本PIN的明文。注意:HSM必须处于授权状态。 + + + BA + + + + + + + + + + + + 左对齐的形式的文本PIN,后面附加字符“X’F”直至已加密PIN的长度。其值在安全配置“CS”命令中设置(范围为5至13)。例如:PIN:123456,此字段应该为06123456FFFFFFFF(8字节分组算法) + + + + 账号中去除校验位的最右12位。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + BB + + + + + + + + + + + + + LMK 对(02-03)下加密的 PIN + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/BY.xml b/DProto/BY.xml new file mode 100644 index 0000000..cb55bfd --- /dev/null +++ b/DProto/BY.xml @@ -0,0 +1,135 @@ + + + + + + BY + + + + + + LMK 对(04-05)下加密的 ZMKi。 + + + + ZMKi 下加密的 ZMK + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。LMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + BZ + + + + + + + + + + + + + + + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + ZMK 加密下的ZPK。 + + + + 密钥校验值。是 16H 还是 6H 取决于 KCV 的类型选项。 + 当输出的 ZMK 密钥方案为 S 时,KCV 选项为 0 是,输 + 入出 32H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/CA.xml b/DProto/CA.xml new file mode 100644 index 0000000..aa30f91 --- /dev/null +++ b/DProto/CA.xml @@ -0,0 +1,182 @@ + + + + + + CA + + + + + 当前加密 PIN 块的 ZPK;LMK 对(06-07)下加密。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 将要加密 PIN 块的 ZPK;LMK 对(06-07)下加密。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 取值 P(可选) + + + + + + + + + + + + + + + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 值为“12”。强制 + 12 + + + + 源 ZPK 下加密的源 PIN 块 + + + + 源 PIN 块的格式代码。 + 01:带主帐号的 ANSI9.8 格式 + 02: Docutel ATM; + 03: Diebold and IBM ATM,; + 04: Plus Network; + 05: ISO9564-1-1 格式,1NP..PR...R + 06:不带主帐号的 ANSI9.8 格式 + + + + 目的 PIN 块的格式代码。 + 01:带主帐号的 ANSI9.8 格式 + 02: Docutel ATM; + 03: Diebold and IBM ATM,; + 04: Plus Network; + 05: ISO9564-1-1 格式,1NP..PR...R + 06:不带主帐号的 ANSI9.8 格式 + + + + 账号中去除校验位的最右 12 位 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + CB + + + + + + + + + + + + + + + + + + + + + + 所返回 PIN 的长度 + + + + 目的 ZPK 下加密的目的 PIN 块 + + + + 格式代码与收到的命令消息中的值相同。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/CB.xml b/DProto/CB.xml new file mode 100644 index 0000000..65ffce3 --- /dev/null +++ b/DProto/CB.xml @@ -0,0 +1,213 @@ + + + + + + CB + + + + + 查看密钥类型表 + + + + 查看密钥类型表 + + + + 当前加密PIN块的密钥;LMK加密的密文。 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + + 将要加密PIN块的密钥;LMK加密的密文。 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + + 取值P(可选,没有此选项,默认为算法为3DES) + + + + + + + + + + + + + + + + + + 源密钥加密的源PIN块,源算法3DES时16H,源算法SM4时32H。 + + + + + + + + + + + + + + + + + + + + + + + + + + 账号中去除校验位的最右12位。 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + CC + + + + + + + + + + + + + + + + + + + + + 所返回PIN的长度。 + + + + 目的秘钥下加密的目的PIN块。 + + + + 格式代码与收到的命令消息中的值相同。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + \ No newline at end of file diff --git a/DProto/CC.xml b/DProto/CC.xml new file mode 100644 index 0000000..7d26d19 --- /dev/null +++ b/DProto/CC.xml @@ -0,0 +1,188 @@ + + + + + + CC + + + + + 当前加密 PIN 块的 ZPK;LMK 对(06-07)下加密。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 将要加密 PIN 块的 ZPK;LMK 对(06-07)下加密。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 取值 P(可选) + + + + + + + + + + + + + + + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 值为“12”。强制 + 12 + + + + 源 ZPK 下加密的源 PIN 块 + + + + 源 PIN 块的格式代码。 + 01:带主帐号的 ANSI9.8 格式 + 02: Docutel ATM; + 03: Diebold and IBM ATM,; + 04: Plus Network; + 05: ISO9564-1-1 格式,1NP..PR...R + 06:不带主帐号的 ANSI9.8 格式 + + + + 目的 PIN 块的格式代码。 + 01:带主帐号的 ANSI9.8 格式 + 02: Docutel ATM; + 03: Diebold and IBM ATM,; + 04: Plus Network; + 05: ISO9564-1-1 格式,1NP..PR...R + 06:不带主帐号的 ANSI9.8 格式 + + + + 账号中去除校验位的最右 12 位 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + CD + + + + + + + + + + + + + + + + + + + + + 所返回 PIN 的长度 + + + + 目的 ZPK 下加密的目的 PIN 块 + + + + 格式代码与收到的命令消息中的值相同。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/DE.xml b/DProto/DE.xml new file mode 100644 index 0000000..2636834 --- /dev/null +++ b/DProto/DE.xml @@ -0,0 +1,103 @@ + + + + + DE + + + + + LMK对(14-15)下加密的PVK;用于生成offset。 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + + 需要offset的PIN;LMK对(02-03)下加密。 + + + + + + + 账号中去除校验位的最右12位。 + + + + 将十六进制转换为十进制的转换表。 + + + + 用户定义的、包含十六进制字符和字符“N”的数据,用来指示HSM插入账号最后5位的位置。 + + + + + + + + + DF + + + + + + + + + + + + + + + + + + + + + + 所返回PIN的长度。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + diff --git a/DProto/E0.xml b/DProto/E0.xml new file mode 100644 index 0000000..9fc26a8 --- /dev/null +++ b/DProto/E0.xml @@ -0,0 +1,401 @@ + + + + + + E0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + LMK30-31 对下保护的 ZEK + LMK32-33 对下保护的 TEK + + + + + + + + + + + + + + + + + + 仅当消息块号为 0,3 时有此域 + + + + + + + + 仅当消息块号为 0,3 时有此域 + Pad character 为4H (以 XXYY 表示来进行说 + 明),其中XX为第一个字节的填充字符,之后的其 + 他所有需要填充的字节都填充为 YY。 + + + + + + + + + + 仅当消息块号为 0,3 时有此域 + Pad character 为4H (以 XXYY 表示来进行说 + 明),其中XX为第一个字节的填充字符,之后的其 + 他所有需要填充的字节都填充为 YY。 + + + + + + + + + 初始值,仅当密钥加密模式为 2,3,4 时有此域。 + 当密钥模式为 0,1 时,该域为 16H + 当密钥模式为 2,3,4,5,6,7 时,该域为 32H + + + + 将要作 MAC的消息长度(若消息类型为二进制,则为 + 随后域长度;若消息类型为扩展十六进制,则为随后 + 域长度的一半)。 + + + + 二进制或扩展十六进制形式的消息块。 + + + + + + + + + + E1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + 将要作 MAC的消息长度(若消息类型为二进制,则为 + 随后域长度;若消息类型为扩展十六进制,则为随后 + 域长度的一半)。 + + + + 二进制或扩展十六进制形式的消息块。 + + + + 在 CBC, OFB, CFB, PCBC模式下,当数据块为“first + block 或 middle block”时,命令输出的 IV 域为下 + 一个数据块输入的IV域(IV数据格式固定为Expanded + Hex-16 字节)。当数据块为“only block 或 last + block”时,输出不包含 IV 数据域 + + + + + + + + diff --git a/DProto/E1.xml b/DProto/E1.xml new file mode 100644 index 0000000..bf4fed1 --- /dev/null +++ b/DProto/E1.xml @@ -0,0 +1,399 @@ + + + + + + E1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + LMK30-31 对下保护的 ZEK + LMK32-33 对下保护的 TEK + + + + + + + + + + + + + + + + + + 仅当消息块号为 0,3 时有此域 + + + + + + + + 仅当消息块号为 0,3 时有此域 + Pad character 为4H (以 XXYY 表示来进行说 + 明),其中XX为第一个字节的填充字符,之后的其 + 他所有需要填充的字节都填充为 YY。 + + + + + + + + + + 仅当消息块号为 0,3 时有此域 + Pad character 为4H (以 XXYY 表示来进行说 + 明),其中XX为第一个字节的填充字符,之后的其 + 他所有需要填充的字节都填充为 YY。 + + + + + + + + + 初始值,仅当密钥加密模式为 2,3,4 时有此域。 + 当密钥模式为 0,1 时,该域为 16H + 当密钥模式为 2,3,4,5,6,7 时,该域为 32H + + + + 将要作 MAC的消息长度(若消息类型为二进制,则为 + 随后域长度;若消息类型为扩展十六进制,则为随后 + 域长度的一半)。 + + + + 二进制或扩展十六进制形式的消息块。 + + + + + + + + + + E2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + 将要作 MAC的消息长度(若消息类型为二进制,则为 + 随后域长度;若消息类型为扩展十六进制,则为随后 + 域长度的一半)。 + + + + 二进制或扩展十六进制形式的消息块。 + + + + 在 CBC, OFB, CFB, PCBC模式下,当数据块为“first + block 或 middle block”时,命令输出的 IV 域为下 + 一个数据块输入的IV域(IV数据格式固定为Expanded + Hex-16 字节)。当数据块为“only block 或 last + block”时,输出不包含 IV 数据域 + + + + + + + + diff --git a/DProto/E2.xml b/DProto/E2.xml new file mode 100644 index 0000000..8746a1b --- /dev/null +++ b/DProto/E2.xml @@ -0,0 +1,119 @@ + + + + + + E2 + + + + + + + + + + + RSA 算法,算法长度 0320-2048 + SM2 算法,算法长度固定为 0256 + + + + 可选,存在,则固定值为‘P’ + + + + 存储标志存在时存在,27位数字,以此索引存储生成的密钥 + + + + 存储标志存在时存在,密钥生效时间 + + + + 存储标志存在时存在,密钥失效时间 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + E3 + + + + + + + + + + + + + + 私钥的密文长度 + + + + LMK 加密下的私钥(LMK34-35) + + + + 公钥长度(DER) + + + + 公钥的 DER 编码 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/E4.xml b/DProto/E4.xml new file mode 100644 index 0000000..4a3efbb --- /dev/null +++ b/DProto/E4.xml @@ -0,0 +1,107 @@ + + + + + + E4 + + + + ECC的NID + 415:prime256v1 + 715:secp384r1 + + + 可选,存在,则固定值为‘P’ + + + 存储标志存在时存在,4位数字,以此索引存储生成的密钥。0001-9998 + + + 存储标志存在时存在,密钥生效时间 + + + 存储标志存在时存在,密钥失效时间 + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + E5 + + + + + + + + + + + + + + + 私钥的密文长度 + + + + LMK 加密下的私钥(LMK34-35) + + + + 公钥长度(DER) + + + + 公钥的 DER 编码 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/FA.xml b/DProto/FA.xml new file mode 100644 index 0000000..45207be --- /dev/null +++ b/DProto/FA.xml @@ -0,0 +1,142 @@ + + + + + + FA + + + + + LMK 对(04-05)加密的 ZMK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + ZMK 下加密的 ZPK + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + FB + + + + + + + + + + + + + + + + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + 转换后的 ZPK;由 LMK06-07 对加密 + + + + 用 ZPK 加密 64 位 0 的结果。是 16H 还是 6H 取决于 KCV + 的类型选项。 + 当输出的 ZMK 加密的 ZPK 密钥方案为 S 时,KCV 选项 + 为 0 是,输入出 32H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/FC.xml b/DProto/FC.xml new file mode 100644 index 0000000..85c18c1 --- /dev/null +++ b/DProto/FC.xml @@ -0,0 +1,134 @@ + + + + + + FC + + + + + LMK 对(04-05)下加密的 ZMK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + ZMK 下加密的 TMK、 TPK 或 PVK。 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。LMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + FD + + + + + + + + + + + + + + + + + 如果是 'Z' , 16 个字节长 + 如果是 'X,U,S' , 32 个字节长 + 如果是 'Y,T' , 48 个字节长 + + + + 转换后的 TMK、 TPK 或 PVK; LMK 对(14-15)下 + 加密 + + + + 用 ZPK 加密 64 位 0 的结果。是 16H 还是 6H 取决于 KCV + 的类型选项。 + 当输出的 ZMK 加密的 ZPK 密钥方案为 S 时,KCV 选项 + 为 0 是,输入出 32H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/FE.xml b/DProto/FE.xml new file mode 100644 index 0000000..eaa49e3 --- /dev/null +++ b/DProto/FE.xml @@ -0,0 +1,138 @@ + + + + + + FE + + + + + LMK 对(04-05)下加密的 ZMK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + LMK 对(14-15)下加密的 TMK、TPK 或 PVK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。LMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + FF + + + + + + + + + + + + + + + + + + 如果是 'Z' , 16 个字节长 + 如果是 'X,U,S' , 32 个字节长 + 如果是 'Y,T' , 48 个字节长 + + + + 转换后的 TMK、TPK 或 PVK;ZMK 下加密。 + + + + 用 ZPK 加密 64 位 0 的结果。是 16H 还是 6H 取决于 KCV + 的类型选项。 + 当输出的 ZMK 加密的 ZPK 密钥方案为 S 时,KCV 选项 + 为 0 是,输入出 32H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/FI.xml b/DProto/FI.xml new file mode 100644 index 0000000..98268d9 --- /dev/null +++ b/DProto/FI.xml @@ -0,0 +1,201 @@ + + + + + + FI + + + + + + + + + + + + LMK 对(04-05)加密的 ZMK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + FJ + + + + + + + + + + + + + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + 转换后的 ZPK;由 LMK06-07 对加密 + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + 转换后的 ZPK;由 LMK06-07 对加密 + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + 转换后的 ZPK;由 LMK06-07 对加密 + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + 转换后的 ZPK;由 LMK06-07 对加密 + + + + 用 ZPK 加密 64 位 0 的结果。是 16H 还是 6H 取决于 KCV + 的类型选项。 + 当输出的 ZMK 加密的 ZPK 密钥方案为 S 时,KCV 选项 + 为 0 是,输入出 32H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/FK.xml b/DProto/FK.xml new file mode 100644 index 0000000..2edd381 --- /dev/null +++ b/DProto/FK.xml @@ -0,0 +1,179 @@ + + + + + + FK + + + + + + + + + + + + LMK 对(04-05)加密的 ZMK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + ZMK 下加密的 ZEK 或 ZAK + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + FL + + + + + + + + + + + + + + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + LMK30-31对下加密的ZEK。(仅当标志位为0时才有该域) + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + LMK26-27对下加密的ZAK。(仅当标志位为1时才有该域) + + + + 用ZEK或ZAK加密64位0的结果。是16H还是6H取决于KCV的类型选项。 + 当输入可选项的LMK密钥方案为S时,KCV选项为0是,输入出32H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/FM.xml b/DProto/FM.xml new file mode 100644 index 0000000..36c2a43 --- /dev/null +++ b/DProto/FM.xml @@ -0,0 +1,184 @@ + + + + + + FM + + + + + + + + + + + + LMK 对(04-05)加密的 ZMK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + LMK 下加密的 ZEK 或 ZAK。 + ZEK=LMK30-31,ZAK=LMK26-27 + (标志位为 0 时为 ZEK,1 为 ZAK) + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + FN + + + + + + + + + + + + + + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + 转换后的 ZPK;由 LMK06-07 对加密 + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + 转换后的 ZPK;由 LMK06-07 对加密 + + + + 用 ZPK 加密 64 位 0 的结果。是 16H 还是 6H 取决于 KCV + 的类型选项。 + 当输出的 ZMK 加密的 ZPK 密钥方案为 S 时,KCV 选项 + 为 0 是,输入出 32H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/GC.xml b/DProto/GC.xml new file mode 100644 index 0000000..d7daa76 --- /dev/null +++ b/DProto/GC.xml @@ -0,0 +1,144 @@ + + + + + + GC + + + + + LMK 对(04-05)加密的 ZMK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + LMK 对(06-07)下加密的 ZPK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + GD + + + + + + + + + + + + + + + + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + 转换后的 ZPK;由 LMK06-07 对加密 + + + + 用 ZPK 加密 64 位 0 的结果。是 16H 还是 6H 取决于 KCV + 的类型选项。 + 当输出的 ZMK 加密的 ZPK 密钥方案为 S 时,KCV 选项 + 为 0 是,输入出 32H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/GY.xml b/DProto/GY.xml new file mode 100644 index 0000000..5bbc7c5 --- /dev/null +++ b/DProto/GY.xml @@ -0,0 +1,140 @@ + + + + + + GY + + + + 成分数量 + + + + 所有成分 + + + + 业务标识 + + + + + + + + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + GZ + + + + + + + + + + + + + + + + + + + + 如果是 'Z' ,lmk 16 个字节长 + 如果是 'X,U,S' ,lmk 32 个字节长 + 如果是 'Y,T' ,lmk 48 个字节长 + + + + LMK 加密下的密钥。 + + + + 用ZMK加密64位0的结果。是16H还是6H取决于KCV的类型选项。 + 当输出的ZMK密钥方案为S时,KCV选项为0是,输入出32H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/HA.xml b/DProto/HA.xml new file mode 100644 index 0000000..ce7c713 --- /dev/null +++ b/DProto/HA.xml @@ -0,0 +1,144 @@ + + + + + + HA + + + + + LMK 对(14-15)下加密的 TMK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + N + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。TMK 下加密密钥的方案。 + + + + 可选项。LMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + HB + + + + + + + + + + + + + + + + + 如果是 'Z' , 16 个字节长 + 如果是 'X,U,S' , 32 个字节长 + 如果是 'Y,T' , 48 个字节长 + + + + TMK 下加密的随机的 TAK + + + + 如果是 'Z' , 16 个字节长 + 如果是 'X,U,S' , 32 个字节长 + 如果是 'Y,T' , 48 个字节长 + + + + LMK 对 16-17 下加密的密钥 + + + + 用 TAK 加密 64 位 0 的结果。是 16H 还是 6H 取决于 KCV + 的类型选项。 当 TMK 的密钥方案为 S 时,默认或 KCV + 类型为 0 时,输出 32H 的 KCV + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/HC.xml b/DProto/HC.xml new file mode 100644 index 0000000..65ae08e --- /dev/null +++ b/DProto/HC.xml @@ -0,0 +1,144 @@ + + + + + + HC + + + + + LMK 对(14-15)下加密的 TMK、TPK 或 PVK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。TMK 下加密密钥的方案。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + HD + + + + + + + + + + + + + + + + + 如果是 'Z' , 16 个字节长 + 如果是 'X,U,S' , 32 个字节长 + 如果是 'Y,T' , 48 个字节长 + + + + 当前的TMK (TPK或PVK)下加密的新密钥。 + + + + 如果是 'Z' , 16 个字节长 + 如果是 'X,U,S' , 32 个字节长 + 如果是 'Y,T' , 48 个字节长 + + + + LMK下加密的新密钥。 + + + + 用 ZPK 加密 64 位 0 的结果。是 16H 还是 6H 取决于 KCV + 的类型选项。 + 当输出的 ZMK 加密的 ZPK 密钥方案为 S 时,KCV 选项 + 为 0 是,输入出 32H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/HI.xml b/DProto/HI.xml new file mode 100644 index 0000000..921955c --- /dev/null +++ b/DProto/HI.xml @@ -0,0 +1,69 @@ + + + + + + HI + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + HJ + + + + + + + + + + + 百分比状态 + + + + 百分比状态 + + + + 单位 MB + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/HV.xml b/DProto/HV.xml new file mode 100644 index 0000000..8df2a60 --- /dev/null +++ b/DProto/HV.xml @@ -0,0 +1,75 @@ + + + + + + HV + + + + + 授权响应码 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + HW + + + + + + + + + + + 设备生产厂商名称 + + + + 设备型号 + + + + 设备型号 + + + + 设备内部软件版本号 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/IA.xml b/DProto/IA.xml new file mode 100644 index 0000000..2ae1c7c --- /dev/null +++ b/DProto/IA.xml @@ -0,0 +1,142 @@ + + + + + + IA + + + + + LMK 对(04-05)加密的 ZMK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + IB + + + + + + + + + + + + + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + ZMK 加密下的ZPK。 + + + + 如果是 'Z' ,lmk 16 个字节长 + 如果是 'X,U,S' ,lmk 32 个字节长 + 如果是 'Y,T' ,lmk 48 个字节长 + + + + LMK 加密下的ZPK。 + + + + 用 ZPK 加密 64 位 0 的结果。是 16H 还是 6H 取决于 KCV + 的类型选项。 + 当输出的 ZMK 加密的 ZPK 密钥方案为 S 时,KCV 选项 + 为 0 是,输入出 32H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/JA.xml b/DProto/JA.xml new file mode 100644 index 0000000..1780c6b --- /dev/null +++ b/DProto/JA.xml @@ -0,0 +1,102 @@ + + + + + + JA + + + + + 账号中去除校验位的最右 12 位 + + + + 可选项。范围为 04 到 12。如果没有该域,则生成一 + 个 4 位的 PIN。 + + + + 取值 P(可选) + + + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + JB + + + + + + + + + + + + + + LMK 对(02-03)下加密的导出 PINBLOCK。(PINBLOCK + 格式默认为 01 格式) + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/JC.xml b/DProto/JC.xml new file mode 100644 index 0000000..ca8f0a4 --- /dev/null +++ b/DProto/JC.xml @@ -0,0 +1,161 @@ + + + + + + JC + + + + + 当前加密 PIN 块的 ZPK;LMK 对(06-07)下加密。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 取值 P(可选) + + + + + + + + + + + + + + + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 源 ZPK 下加密的源 PIN 块 + + + + 源 PIN 块的格式代码。 + 01:带主帐号的 ANSI9.8 格式 + 02: Docutel ATM; + 03: Diebold and IBM ATM,; + 04: Plus Network; + 05: ISO9564-1-1 格式,1NP..PR...R + 06:不带主帐号的 ANSI9.8 格式 + + + + 账号中去除校验位的最右 12 位 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + JD + + + + + + + + + + + + + + + + + + + + + LMK 对(02-03)下加密的 PIN + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/JE.xml b/DProto/JE.xml new file mode 100644 index 0000000..2d4ed88 --- /dev/null +++ b/DProto/JE.xml @@ -0,0 +1,161 @@ + + + + + + JE + + + + + 当前加密 PIN 块的 ZPK;LMK 对(06-07)下加密。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 取值 P(可选) + + + + + + + + + + + + + + + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 源 ZPK 下加密的源 PIN 块 + + + + 源 PIN 块的格式代码。 + 01:带主帐号的 ANSI9.8 格式 + 02: Docutel ATM; + 03: Diebold and IBM ATM,; + 04: Plus Network; + 05: ISO9564-1-1 格式,1NP..PR...R + 06:不带主帐号的 ANSI9.8 格式 + + + + 账号中去除校验位的最右 12 位 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + JF + + + + + + + + + + + + + + + + + + + + + LMK 对(02-03)下加密的 PIN + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/JG.xml b/DProto/JG.xml new file mode 100644 index 0000000..6b25505 --- /dev/null +++ b/DProto/JG.xml @@ -0,0 +1,162 @@ + + + + + + JG + + + + + 当前加密 PIN 块的 ZPK;LMK 对(06-07)下加密。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 取值 P(可选) + + + + + + + + + + + + + + + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 源 ZPK 下加密的源 PIN 块 + + + + 源 PIN 块的格式代码。 + 01:带主帐号的 ANSI9.8 格式 + 02: Docutel ATM; + 03: Diebold and IBM ATM,; + 04: Plus Network; + 05: ISO9564-1-1 格式,1NP..PR...R + 06:不带主帐号的 ANSI9.8 格式 + + + + 账号中去除校验位的最右 12 位 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + JH + + + + + + + + + + + + + + + + + + + + + LMK 对(02-03)下加密的 PIN + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/LB.xml b/DProto/LB.xml new file mode 100644 index 0000000..dbd9b72 --- /dev/null +++ b/DProto/LB.xml @@ -0,0 +1,113 @@ + + + + + + LB + + + + + 值为“K”。 + + + + 指示用户密钥存储区的27位地址。 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + + 被加密的密钥 + + + + 取值P(可选项) + + + + CheckValue校验值,仅“校验标志”为P时此值显示。 + + + + YYYYMMDD + + + + YYYYMMDD + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + + LC + + + + + + + + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/LF.xml b/DProto/LF.xml new file mode 100644 index 0000000..368a05d --- /dev/null +++ b/DProto/LF.xml @@ -0,0 +1,105 @@ + + + + + + LF + + + + + 值为“K”。 + + + + 指示用户密钥存储区的27位地址。 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + + LG + + + + + + + + + + + + + + 如果是 'Z' ,key 16 个字节长 + 如果是 'X,U,S' ,key 32 个字节长 + 如果是 'Y,T' ,key 48 个字节长 + + + + 被加密的密钥 + + + + S-32H,else-16H(目前仅3.07_B目标代码生效) + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/LG.xml b/DProto/LG.xml new file mode 100644 index 0000000..67731bb --- /dev/null +++ b/DProto/LG.xml @@ -0,0 +1,112 @@ + + + + + + LG + + + + + 值为“K”。 + + + + 指示用户密钥存储区的27位地址。 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + + 被加密的密钥 + + + + 取值P(可选项) + + + + CheckValue校验值,仅“校验标志”为P时此值显示。 + + + + YYYYMMDD + + + + YYYYMMDD + + + + YYYYMMDD + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + + LH + + + + + + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/MA.xml b/DProto/MA.xml new file mode 100644 index 0000000..841c197 --- /dev/null +++ b/DProto/MA.xml @@ -0,0 +1,150 @@ + + + + + + MA + + + + + 取值 P(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 生成MAC的数据,n=1024 + 注:数据长度应该为8的整数倍,如果不是8的整数倍,系统默认在数据后面填充0x00组成8的整数倍。 + + + + + + + + + + + + MB + + + + + + + + + + + + + + + + + 所计算出的MAC。有MAC返回标识决定,默认8H + + + + + + + + diff --git a/DProto/MAXF.xml b/DProto/MAXF.xml new file mode 100644 index 0000000..d1f9af9 --- /dev/null +++ b/DProto/MAXF.xml @@ -0,0 +1,101 @@ + + + + + + MA + + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 取值P(可选) + + + + IV标识存在时存在 + 计算MAC的IV值,默认为8字节0x00 + + + + LMK对(16-17)下加密的TAK。 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + + 生成MAC的数据,n=1024 + 注:数据长度应该为8的整数倍,如果不是8的整数倍,系统默认在数据后面填充0x00组成8的整数倍。 + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为“X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + + MB + + + + + + + + + + + + + + + + + 所计算出的MAC。有MAC返回标识决定,默认8H + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/MC.xml b/DProto/MC.xml new file mode 100644 index 0000000..4fc4dd7 --- /dev/null +++ b/DProto/MC.xml @@ -0,0 +1,138 @@ + + + + + + MC + + + + + 取值 P(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 8H或16H或32H + + + + 生成MAC的数据,n=1024 + 注:数据长度应该为8的整数倍,如果不是8的整数倍,系统默认在数据后面填充0x00组成8的整数倍。 + + + + + + + + + + + MD + + + + + + + + + + + + + + + + + + + + + diff --git a/DProto/MF.xml b/DProto/MF.xml new file mode 100644 index 0000000..f2b6f06 --- /dev/null +++ b/DProto/MF.xml @@ -0,0 +1,137 @@ + + + + + + MF + + + + + LMK 对(04-05)下加密的 ZMK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + ZMK 下加密的 TAK。 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。LMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + MG + + + + + + + + + + + + + + + + + + + + 如果是 'Z' , 16 个字节长 + 如果是 'X,U,S' , 32 个字节长 + 如果是 'Y,T' , 48 个字节长 + + + + LMK 对 16-17 下加密的 TAK + + + + 用 TAK 加密 64 位 0 的结果。是 16H 还是 6H 取决于 KCV + 的类型选项。 当 LMK 的密钥方案为 S 时,默认或 KCV + 类型为 0 时,输出 32H 的 KCV + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/MG.xml b/DProto/MG.xml new file mode 100644 index 0000000..772875c --- /dev/null +++ b/DProto/MG.xml @@ -0,0 +1,137 @@ + + + + + + MG + + + + + LMK 对(04-05)下加密的 ZMK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + LMK 对(16-17)下加密的 TAK。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示后面的三个域,则该域必须显示。 + 值为“;”。 + 如果命令不需要一个可选域,则用一个有效值或 0 填 + 充。 + + + + 可选项。ZMK 下加密密钥的方案。 + + + + 可选项。LMK 下加密密钥的方案。 + + + + 可选项。密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + MH + + + + + + + + + + + + + + + + + + 如果是 'Z' , 16 个字节长 + 如果是 'X,U,S' , 32 个字节长 + 如果是 'Y,T' , 48 个字节长 + + + + ZMK 下加密的 TAK + + + + 用 TAK 加密 64 位 0 的结果。是 16H 还是 6H 取决于 KCV + 的类型选项。当 ZMK 的密钥方案为 S 时,默认或 KCV + 类型为 0 时,输出 32H 的 KCV + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/MS.xml b/DProto/MS.xml new file mode 100644 index 0000000..1ec41a0 --- /dev/null +++ b/DProto/MS.xml @@ -0,0 +1,183 @@ + + + + + + MS + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 当消息块号为2或3时显示 + + + + 将要作 MAC的消息长度(若消息类型为二进制,则为 + 随后域长度;若消息类型为扩展十六进制,则为随后 + 域长度的一半)。 + + + + 二进制或扩展十六进制形式的消息块。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + + MT + + + + + + + + + + + + + + + + + + + + + 当消息块号为“1”或“2”时,作为下一块的IV。 + 当消息块号为“0”或“3”时,用于消息认证。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/MU.xml b/DProto/MU.xml new file mode 100644 index 0000000..d0c9f1e --- /dev/null +++ b/DProto/MU.xml @@ -0,0 +1,141 @@ + + + + + + MU + + + + + 0:仅一块 1:第一块 2:中间块 3:最后块 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 当消息块号为2或3时显示 + + + + 将要作MAC的消息长度(若消息类型为二进制,则为随后域长度;若消息类型为扩展十六进制,则为随后域长度的一半)。 + + + + 生成MAC的数据,n=2048 + + + + + + + + + + + MV + + + + + + + + + + + + + + + + + 所计算出的MAC。有MAC返回标识决定,默认16H/32H + + + + + + + + diff --git a/DProto/NE.xml b/DProto/NE.xml new file mode 100644 index 0000000..4122f2f --- /dev/null +++ b/DProto/NE.xml @@ -0,0 +1,133 @@ + + + + + + NE + + + + 密钥类型 + + + + 密钥长度/LMK 下加密密钥的方案。 + + + + 业务标识 + + + + ; 分隔多个打印域 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + NF + + + + + + + + + + + + + + + + + + + + 如果是 'Z' ,lmk 16 个字节长 + 如果是 'X,U,S' ,lmk 32 个字节长 + 如果是 'Y,T' ,lmk 48 个字节长 + + + + LMK 加密下的密钥。 + + + + 密钥校验值。当 LMK 保护密钥的方案为‘S’,KCV 为 + 32H,算法为 SM4,否则 KCV 为 16H,算法为 DES/3DES + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/NG.xml b/DProto/NG.xml new file mode 100644 index 0000000..db7685b --- /dev/null +++ b/DProto/NG.xml @@ -0,0 +1,101 @@ + + + + + 解密一个已加密的PIN。注意:此命令仅当设置时已选择才有效。 HSM必须处于授权状态。 + + + NG + + + + + + + + + + + + LMK对(02-03)下加密的PIN。 + + + + 账号中去除校验位的最右12位。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + NH + + + + + + + + + + + + + + 左对齐的、明文形式的文本PIN,后面附加字符“X’F”直至已加密PIN的长度。 + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/OC.xml b/DProto/OC.xml new file mode 100644 index 0000000..65df8ac --- /dev/null +++ b/DProto/OC.xml @@ -0,0 +1,113 @@ + + + + + + OC + + + + + ; 分隔多个打印域 + + + + 值为“|”。 + + + + ZMK 下加密密钥的方案。 + + + + ZMK 下加密密钥的方案。 + + + + 密钥校验值计算方式。 + 0-KCV 向后兼容。 + 1-KCV 6H。 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + OD + + + + + + + + + + + + + + + + + 如果是 'Z' ,zmk 16 个字节长 + 如果是 'X,U,S' ,zmk 32 个字节长 + 如果是 'Y,T' ,zmk 48 个字节长 + + + + LMK对04-05变种下加密的ZMK成份。 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/PA.xml b/DProto/PA.xml new file mode 100644 index 0000000..04e73f1 --- /dev/null +++ b/DProto/PA.xml @@ -0,0 +1,84 @@ + + + + + + PA + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + PB + + + + + + + + + + + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/PE.xml b/DProto/PE.xml new file mode 100644 index 0000000..c5a5eda --- /dev/null +++ b/DProto/PE.xml @@ -0,0 +1,119 @@ + + + + + + PE + + + + A:“two-up”格式中的第一个信封。 + B:“two-up”格式中的第二个信封。 + C:1步格式。 + + + + 账号中去除校验位的最右 12 位 + + + + 取值 P(可选) + + + + + + + + + + + + LMK 对(02-03)下加密的导出 PINBLOCK。(PINBLOCK + 格式默认为 01 格式) + + + + 范围为04到12。 + + + + ; 分隔多个打印域 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + PF + + + + + + + + + + + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/Q1.xml b/DProto/Q1.xml new file mode 100644 index 0000000..125eb9c --- /dev/null +++ b/DProto/Q1.xml @@ -0,0 +1,167 @@ + + + + + + Q1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 如果源密钥为外部送入,则为LMK加密,否则为HSM用户密钥存储区。 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 数据长度(所有报文数据不大于8192,除了其他数据域长度都可以用来存放数据) + + + + 数据 + + + + 当使用CBC,CFB或OFB模式时使用的初始向量长度 + 可选项,当加密模式为CBC,CFB或OFB时才显示此项 + + + + 初始向量数据 + 可选项,当加密模式为CBC,CFB或OFB时才显示此项 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为“X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + Q2 + + + + + + + + + + + + + + + + + + 密钥加密的密文数据 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/Q2.xml b/DProto/Q2.xml new file mode 100644 index 0000000..e2e0c6f --- /dev/null +++ b/DProto/Q2.xml @@ -0,0 +1,167 @@ + + + + + + Q2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 如果源密钥为外部送入,则为LMK加密,否则为HSM用户密钥存储区。 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 源秘钥加密的密文数据长度 + + + + 源密钥加密的密文数据 + + + + 当使用CBC,CFB或OFB模式时使用的初始向量长度 + 可选项,当加密模式为CBC,CFB或OFB时才显示此项 + + + + 初始向量数据 + 可选项,当加密模式为CBC,CFB或OFB时才显示此项 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为“X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + Q3 + + + + + + + + + + + + + + + + + + 解密后的明文数据 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/QN.xml b/DProto/QN.xml new file mode 100644 index 0000000..3a7211c --- /dev/null +++ b/DProto/QN.xml @@ -0,0 +1,61 @@ + + + + + + QN + + + + + 0256 + + + + + + + + + + + + + + + + + + QO + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DProto/QQ.xml b/DProto/QQ.xml new file mode 100644 index 0000000..f6ff567 --- /dev/null +++ b/DProto/QQ.xml @@ -0,0 +1,100 @@ + + + + + + QQ + + + + 数字为存储私钥的索引,除了 + 全 9 表示使用由命令中提供的密钥。 + 27 位的索引号:16 位机构号+3 位密钥类型+8 位密钥 + 索引号。 + + + + + + + + + + QR + + + + + + + + + + + + + + + + + + + + + + + 公钥的字节长度 + + + + 公钥 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/QX.xml b/DProto/QX.xml new file mode 100644 index 0000000..faa507e --- /dev/null +++ b/DProto/QX.xml @@ -0,0 +1,97 @@ + + + + + + QX + + + + 密钥对应的索引号 + + + + + + + + + + QY + + + + + + + + + + + + + + + + + + + + + + + 公钥的字节长度 + + + + 公钥 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + diff --git a/DProto/TC.xml b/DProto/TC.xml new file mode 100644 index 0000000..c10aa72 --- /dev/null +++ b/DProto/TC.xml @@ -0,0 +1,96 @@ + + + + + + TC + + + + A - 双联-1 + B - 双联-2 + C - 单联 + + + + 密钥 + + + + ; 分隔多个打印域 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + TD + + + + + + + + + + + + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + \ No newline at end of file diff --git a/DProto/Y0.xml b/DProto/Y0.xml new file mode 100644 index 0000000..cccd31f --- /dev/null +++ b/DProto/Y0.xml @@ -0,0 +1,175 @@ + + + + + Y0 + + + + + 查看密钥类型表 + + + + + + + + + + + + + + + 查看秘钥类型表 + + + + + + + + + + + + + + + + + + + + + + + + 如果源密钥为外部送入,则为LMK加密,否则为HSM用户密钥存储区。 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + + 如果源密钥为外部送入,则为LMK加密,否则为HSM用户密钥存储区。 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + + 源秘钥加密的密文数据长度 + + + + 源密钥加密的密文数据 + + + + 当使用CBC,CFB或OFB模式时使用的初始向量长度 + 可选项,当加密模式为CBC,CFB或OFB时才显示此项 + + + + 初始向量数据 + 可选项,当加密模式为CBC,CFB或OFB时才显示此项 + + + + N + 取值N(可选) + 当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为“X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + Y1 + + + + + + + + + + + + + + 目的密钥加密的密文数据 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + diff --git a/DProto/Y8.xml b/DProto/Y8.xml new file mode 100644 index 0000000..63f3642 --- /dev/null +++ b/DProto/Y8.xml @@ -0,0 +1,68 @@ + + + + + Y8 + + + + 最大长度为999 字节 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 + “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + Y9 + + + + + + + + + + + + + + + + 可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + diff --git a/DProto/YA.xml b/DProto/YA.xml new file mode 100644 index 0000000..f36c7d1 --- /dev/null +++ b/DProto/YA.xml @@ -0,0 +1,127 @@ + + + + + + YA + + + + + LMK下加密的密钥。 + K: 指示密钥存储在用户密钥存储区 + 1A: Z, X, U, Y, T. 用于密钥及K索引模式下的密钥标识 + 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + + + + + + + + + + + + 指定对根密钥分散的次数(1-3次) + + 分散因子是 16/32/48 + + + + + + + + + + + + + + 可选项。密钥校验值计算方式。 + + + + + + + + 取值 N(可选)当选定此标识时,表示密钥加密方案采用默认方式 + + + + 可选项。如果显示消息尾域,则该域必须显示。值为“X’19”。 + 19 + + + + 可选项。最大长度为 32个字符。 + + + + + + + + + + + YB + + + + + + + + + + + + + + 被保护密钥lmk加密输出 + + + + 密钥校验值 + + + + + + + + + \ No newline at end of file diff --git a/DProto/base.xml b/DProto/base.xml new file mode 100644 index 0000000..7b7210e --- /dev/null +++ b/DProto/base.xml @@ -0,0 +1,62 @@ + + + + racal 指令体系 sunyard 实现 + + + +
+ 该消息头随后即被无变化地返回给主机。 + 通常填充为异步通信的包序号。 +
+ + +
+ + + +
+ 该消息头随后即被无变化地返回给主机。 + 通常填充为异步通信的包序号。 +
+ + +
+ + +
+ + diff --git a/README.md b/README.md new file mode 100644 index 0000000..203bdce --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# sydapi4j + +加密机 java 接口,基于 jna。 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..c7e7547 --- /dev/null +++ b/pom.xml @@ -0,0 +1,307 @@ + + 4.0.0 + + com.sunyard + sydapi4j + 1.0.201809191421 + jar + + sydapi4j + http://maven.apache.org + + + 3.4.2 + UTF-8 + 1.2.31 + UTF-8 + + + + + junit + junit + 3.8.1 + test + + + + org.jetbrains.kotlin + kotlin-test + ${kotlin.version} + test + + + + + org.slf4j + slf4j-api + 1.7.10 + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.9.1 + + + org.apache.logging.log4j + log4j-jcl + 2.9.1 + + + org.apache.logging.log4j + log4j-api + 2.9.1 + + + org.apache.logging.log4j + log4j-core + 2.9.1 + + + + + dom4j + dom4j + 1.6.1 + + + + + org.codehaus.groovy + groovy-all + 2.3.2 + + + + + com.alibaba + fastjson + 1.2.39 + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + + + + + + + + + com.sunyard + dproto + 1.0-SNAPSHOT + + + junit + junit + 4.12 + test + + + + + + + + + + + + + + sydapi4j + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + ./public/ + html + html5 + com.sunyard.SydApi:com.sunyard.inf.*:com.sunyard.cert.* + + + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + + + + + + package + + jar-no-fork + + + + + + + org.codehaus.groovy + groovy-eclipse-compiler + 2.9.2-01 + true + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + lib/ + com.xxx.uploadFile + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy + package + + copy-dependencies + + + + ${project.build.directory}/lib + + + + + + + + + maven-assembly-plugin + + + + racal.sunyard.main.Version + + + + jar-with-dependencies + + + + + package + + single + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + src/main/java + + + + + test-compile + test-compile + + test-compile + + + + + 1.6 + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + + compile + compile + + compile + + + + testCompile + test-compile + + testCompile + + + + + 8 + 8 + groovy-eclipse-compiler + true + true + + + + org.codehaus.groovy + groovy-eclipse-compiler + 2.9.2-01 + + + org.codehaus.groovy + groovy-eclipse-batch + 2.4.3-01 + + + + + + + + + src/main/resources + + + + + + + nexus-own + repo-snapshot + ${SnapshotRepository} + + + nexus-own + repo-release + ${ReleaseRepository} + + + + + diff --git a/public.cmd b/public.cmd new file mode 100644 index 0000000..cfb0d92 --- /dev/null +++ b/public.cmd @@ -0,0 +1,7 @@ +:: 自动打包为发布格式 +:: 准备文件夹 +:: rd /s/q ./public +:: md ./public + +:: 获取版本 +node public.script/index.js \ No newline at end of file diff --git a/public.script/color.js b/public.script/color.js new file mode 100644 index 0000000..afe1468 --- /dev/null +++ b/public.script/color.js @@ -0,0 +1,31 @@ + +// console.log('\x1B[36m%s\x1B[0m', info); //cyan +// console.log('\x1B[33m%s\x1b[0m:', path); //yellow +var styles = { + 'bold' : ['\x1B[1m', '\x1B[22m'], + 'italic' : ['\x1B[3m', '\x1B[23m'], + 'underline' : ['\x1B[4m', '\x1B[24m'], + 'inverse' : ['\x1B[7m', '\x1B[27m'], + 'strikethrough' : ['\x1B[9m', '\x1B[29m'], + 'white' : ['\x1B[37m', '\x1B[39m'], + 'grey' : ['\x1B[90m', '\x1B[39m'], + 'black' : ['\x1B[30m', '\x1B[39m'], + 'blue' : ['\x1B[34m', '\x1B[39m'], + 'cyan' : ['\x1B[36m', '\x1B[39m'], + 'green' : ['\x1B[32m', '\x1B[39m'], + 'magenta' : ['\x1B[35m', '\x1B[39m'], + 'red' : ['\x1B[31m', '\x1B[39m'], + 'yellow' : ['\x1B[33m', '\x1B[39m'], + 'whiteBG' : ['\x1B[47m', '\x1B[49m'], + 'greyBG' : ['\x1B[49;5;8m', '\x1B[49m'], + 'blackBG' : ['\x1B[40m', '\x1B[49m'], + 'blueBG' : ['\x1B[44m', '\x1B[49m'], + 'cyanBG' : ['\x1B[46m', '\x1B[49m'], + 'greenBG' : ['\x1B[42m', '\x1B[49m'], + 'magentaBG' : ['\x1B[45m', '\x1B[49m'], + 'redBG' : ['\x1B[41m', '\x1B[49m'], + 'yellowBG' : ['\x1B[43m', '\x1B[49m'] +}; + +module.exports = styles + diff --git a/public.script/index.js b/public.script/index.js new file mode 100644 index 0000000..1258b33 --- /dev/null +++ b/public.script/index.js @@ -0,0 +1,208 @@ +const l = require("./log") +const fs = require('fs'); +const path = require('path'); +const util = require('util'); +const cmd = require('node-cmd'); +const cmdget = util.promisify(cmd.get); + +var version = "" +const project_path = path.join(__dirname, "../") +const out_path = path.join(project_path, "public") + +// 用户文档 +const man = "工银亚洲加密机JAVA接口说明文档V1.00.pdf" + +function prepareDir(){ + + return new Promise(function (cbok, cberr) { + if ( fs.existsSync( out_path ) ){ + l.i("存在旧文件,清空旧文件") + } + + cmdget("rd /s/q .\\public").catch(function (reason) { + + // pass + + }).finally(function () { + + l.i("创建新文件") + fs.mkdirSync( out_path ) + fs.mkdirSync( path.join( out_path, "jar" )) + fs.mkdirSync( path.join( out_path, "jar", "dependences")) + + fs.mkdirSync( path.join( out_path, "doc" )) + fs.mkdirSync( path.join( out_path, "html" )) + //fs.mkdirSync( path.join( out_path, "sample" )) + l.i("目录准备完成") + cbok() + + }) + + }) +} + + +function mvn(){ + l.i("调用 maven 打包,可能需要好几分钟。") + return new Promise(function (cbok, cberr) { + cmdget('mvn package -DskipTests').then(function (value, error) { + + l.d( value ) + if ( value.indexOf("BUILD SUCCESS") < 0 ){ + throw new Error("请检查 maven package 命令") + } + + // 移动文件到发布目录 + fs.renameSync(path.join(project_path, "target", "sydapi4j-jar-with-dependencies.jar") + , path.join(out_path, "jar", "sydapi4j-jar-with-dependencies.jar")) + + + fs.renameSync(path.join(project_path, "target", "sydapi4j.jar") + , path.join(out_path, "jar", "sydapi4j.jar")) + + cbok() + + }) + }) +} + +function doc(){ + return cmdget('mvn javadoc:javadoc').then(function (value, error) { + + l.d( value ) + // if ( value.indexOf("BUILD SUCCESS") < 0 ){ + // throw new Error("请检查 maven doc 命令") + // } + + }).catch(function (reason) { + l.d("忽略文档生成错误") + }) + +} + +function zipjar(){ + return cmdget("7z a .\\public\\sydapi-"+ version +".zip .\\public\\jar\\").then(function (value, error) { + + l.d( value ) + if ( value.indexOf("Everything is Ok") < 0 ){ + throw new Error("请检查 7z 命令") + } + + }) +} + +function zipdoc(){ + return cmdget("7z a .\\public\\sydapi-doc-"+ version +".zip .\\public\\doc\\ .\\public\\html\\ .\\src\\test\\java\\com\\sunyard\\sydapi\\sample .\\release.txt").then(function (value, error) { + + l.d( value ) + if ( value.indexOf("Everything is Ok") < 0 ){ + throw new Error("请检查 7z 命令") + } + + }) +} + + +function dependencies(){ + return cmdget('mvn dependency:copy-dependencies -DoutputDirectory=./public/jar/dependences').then(function (value, error) { + + l.d( value ) + if ( value.indexOf("BUILD SUCCESS") < 0 ){ + throw new Error("请检查 maven dependencies 命令") + } + + }) + +} + +async function main() { + + l.i("项目目录 : " + project_path ) + + cmdget('git status').then(function (value, error) { + + l.d( value ) + + if ( value.indexOf("Command failed") > 0 ){ + throw new Error("请检查 git 命令") + } + + if ( value.indexOf("Changes not staged for commit") > 0){ + throw new Error("项目有文件未保存") + } + + if ( value.indexOf("Changes to be committed") > 0 ){ + throw new Error("项目有文件未提交") + } + + + // 匹配分支,获取前两位版本 + var r = /^On branch dev-(?\S+)$/gm.exec(value) + l.i( r.groups.version ) + version = r.groups.version + + return cmdget('git log -1') + + }).then(function (value) { + + l.d( value ) + var r = /^commit\s(?\S+)$/gm.exec(value) + l.i( r.groups.id ) + + // 缩短 HASH + var short = r.groups.id.substr(0, 6) + version += "." + short + + l.i("目前版本: " + version ) + + return prepareDir() + + }).then(function (value) { + + return mvn() + + }).then(function (value) { + + return dependencies() + + }).then(function (value) { + + var pom = fs.readFileSync("pom.xml", { encoding : "UTF-8" }) + var head = pom.indexOf("") + var tail = pom.indexOf("") + 15 + + var dependencies = pom.substring( head, tail ) + fs.writeFileSync( path.join( out_path, "jar", "dependences.xml") , dependencies ) + + }).then(function (value) { + + fs.copyFileSync( path.join(project_path, "docs", man) , path.join(out_path, "doc", man )) + + }).then(function (value) { + + return doc() + + }).then(function (value) { + + return zipdoc() + + }).then(function (value) { + + return zipjar() + + }).then(function () { + + l.i("打包完成!") + cmdget('start .\\public') + + }).catch(function (reason) { + + l.e( reason ) + + }) +} + +main() + + + diff --git a/public.script/log.js b/public.script/log.js new file mode 100644 index 0000000..22ac094 --- /dev/null +++ b/public.script/log.js @@ -0,0 +1,31 @@ +const style = require("./color") +const info = style.green +const error = style.red +const debug = style.cyan + + +const l = { + + o : console.log, + + i : function ( msg ) { + console.log('%s%s%s', info[0], msg , info[1]); + }, + + d : function ( msg ) { + console.log('%s%s%s', debug[0], msg , debug[1]); + }, + + e : function ( msg ) { + console.log('%s%s%s', error[0], msg , error[1]); + }, +} + +l.show = function () { + + l.i("info") + l.d("debug") + l.e("error") +} + +module.exports = l \ No newline at end of file diff --git a/release.cmd b/release.cmd new file mode 100644 index 0000000..4ab9f3d --- /dev/null +++ b/release.cmd @@ -0,0 +1,3 @@ +7z a ./target/sydapi4j.jar racal.sunyard.main.version +7z a ./target/sydapi4j-sources.jar racal.sunyard.main.version +7z a ./target/sydapi4j-jar-with-dependencies.jar racal.sunyard.main.version \ No newline at end of file diff --git a/release.txt b/release.txt new file mode 100644 index 0000000..d0a8f7c --- /dev/null +++ b/release.txt @@ -0,0 +1,5 @@ +v1.11 版本 +- 修正不规范接口 GenerateRandom 返回值更改为 String 类型。老版本为 bool 类型,仅于活性检测。 + +v1.12 版本 +- 新增编押验押接口/人行定制接口。 \ No newline at end of file diff --git a/src/main/java/com/sunyard/DaToSHCA.java b/src/main/java/com/sunyard/DaToSHCA.java new file mode 100644 index 0000000..d4d7e93 --- /dev/null +++ b/src/main/java/com/sunyard/DaToSHCA.java @@ -0,0 +1,102 @@ +package com.sunyard; + +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +import java.security.Key; + +public class DaToSHCA { + + private SydApi key; + private da_handle daHandle; + public boolean DA_OpenHsmServer(da_handle daHandle, String IP,int Port){ + try { + SydApi key = new SydApi4j().connect(IP,Port,null,10000); + this.key= key; + }catch (SydApiException e){ + e.printStackTrace(); + return false; + } + return true; + } + + public boolean DA_CloseHsmServer (da_handle daHandle){ + int disconnect = key.disconnect(); + if (disconnect == 0){ + return true; + } + return false; + } + + public Key DA_GetSM2PublicKey(da_handle daHandle, int keyNum){ + +// final String s = key.SM2GetPublicKeyC("" + keyNum, 0); + + final String s = key.SM2GetPublicKeyC_QX(keyNum, 0); + + return new Key() { + @Override + public String getAlgorithm() { + return null; + } + + @Override + public String getFormat() { + return null; + } + + @Override + public byte[] getEncoded() { + return Util.hexString2Bytes(s); + } + }; + + } + + public void SM3_Init(da_handle daHandle, byte[] pubKey){ + this.daHandle = daHandle; + RetWrap retWrap = key.SM3Hash(1, "1234567812345678", new byte[0], new byte[0], new byte[0]); + byte[] filterData = (byte[])retWrap.get("filterData"); + daHandle.setFilterData(filterData); + } + + public void SM3_Updata(da_handle daHandle, byte[] InData){ + byte[] filterData = daHandle.getFilterData(); + RetWrap retWrap = key.SM3Hash(2, "",new byte[0], InData, filterData); + filterData = (byte[])retWrap.get("filterData"); + daHandle.setFilterData(filterData); + } + + public byte[] SM3_Final(da_handle daHandle){ + byte[] filterData = daHandle.getFilterData(); + RetWrap retWrap = key.SM3Hash(3, "",new byte[0], new byte[0], filterData); + byte[] hash = (byte[])retWrap.get("hash"); + return hash; + } + + public byte[] DA_SM2Sgin(da_handle daHandle, int keyNum, byte[] InData){ + + byte[] s = key.detachedSign(0,InData,keyNum); + return s; + } + + public boolean DA_SM2Verify(da_handle daHandle, byte[] InData, String SignData, byte[] sm2Pub){ + + return key.detachedVerify(0, InData, SignData.getBytes()); + } + + public static class da_handle{ + public da_handle(){ + super(); + } + private byte[] filterData; + + public void setFilterData(byte[] filterData) { + this.filterData = filterData; + } + + public byte[] getFilterData() { + return filterData; + } + } +} diff --git a/src/main/java/com/sunyard/RetWrap.java b/src/main/java/com/sunyard/RetWrap.java new file mode 100644 index 0000000..17cbb2a --- /dev/null +++ b/src/main/java/com/sunyard/RetWrap.java @@ -0,0 +1,11 @@ +package com.sunyard; + + +import java.util.HashMap; + +/** + * 包装多返回值 + */ +public class RetWrap extends HashMap{ + +} diff --git a/src/main/java/com/sunyard/SydApi.java b/src/main/java/com/sunyard/SydApi.java new file mode 100644 index 0000000..8070a70 --- /dev/null +++ b/src/main/java/com/sunyard/SydApi.java @@ -0,0 +1,87 @@ +package com.sunyard; + + +import com.sunyard.inf.*; +import com.sunyard.inf.customize.SydHAApi; +import com.sunyard.inf.customize.SydQNUCApi; +import com.sunyard.inf.customize.SydSDNXApi; + +import java.io.InputStream; + +/** + * Created by Cheney on 2017/11/11. + * 程序调用接口 + */ +public interface SydApi extends SydRawApi, SydCertApi, SydCryptionApi, SydGenApi, SydSVApi, SydHAApi, SydQNUCApi, SydPledge, SydPINOpt { + + byte ALG_AES = 0x30; + byte ALG_SM4 = 0x31; + int NALG_3DES = 0x00; + int NALG_SM4 = 0x01; + int NALG_AES = 0x02; + + String RET_CIPHER_KEY = "CipherKey"; + String RET_SESSION_KEY = "SessionKey"; + String RET_PUBLIC_KEY = "PublicKey"; + String RET_PRIVATE_KEY = "PrivateKey"; + String RET_KCV = "KCV"; + + + int FOR_SIGN = 0; + int FOR_ENCRYPT = 1; + + int DATA_HASH = 0; + int DATA_ORIGIN = 1; + + + byte KCV_S = 0x53; + + /** + * 建立到指定地址和端口号的加密设备的TCP/IP 连接,返回 TCP/IP 连接句柄。 + * 如果采用短连接,交易结束,要调用 disconnect() 进行释放连接。 + * @param ip 加密设备的 IP 地址。 + * @param port 加密设备的端口号。 + * @param pwd 保留。 + * @param timeout 超时时间。 + * @return 设备操作对象 + */ + SydApi connect(String ip, int port, String pwd, int timeout); + + /** + * 建立到指定地址和端口号的加密设备的TCP/IP 连接,返回 TCP/IP 连接句柄。 + * 如果采用短连接,交易结束,要调用 disconnect() 进行释放连接。 + * @param ip 加密设备的 IP 地址。 + * @param port 加密设备的端口号。 + * @param pwd 保留。 + * @param connectTimeout 链接超时时间。 + * @param readTimeout 通信超时时间 + * @return 设备操作对象 + */ + SydApi connect(String ip, int port, String pwd, int connectTimeout, int readTimeout); + + + + /** + * 断开连接 + * @return 0 表示成功;非 0 表示失败; + */ + int disconnect(); + + + // 方便链接池扩展 + // 单例可以不实现 + void free(); + + // 方便链接池扩展 + // 单例可以不实现 + void error(); + + + /** + * 获取加密机状态 + * @return CPU/MEM/DISK + */ + RetWrap getStatus(); + + byte[] directBytes(byte[] data); +} diff --git a/src/main/java/com/sunyard/SydApiException.java b/src/main/java/com/sunyard/SydApiException.java new file mode 100644 index 0000000..c00c1ba --- /dev/null +++ b/src/main/java/com/sunyard/SydApiException.java @@ -0,0 +1,116 @@ +package com.sunyard; + +import com.sunyard.proto.Util; + +/** + * Created by Cheney on 2017/8/3. + */ +public class SydApiException extends RuntimeException{ + private int retCode; + private String msg; + + public int getRetCode() { + return retCode; + } + + + public void transMsg(){ + switch (this.retCode){ + case -1: + case -2: + case -3: + this.msg = "网络错误"; + break; + case -4: + this.msg = "返回包的序列号有误"; + break; + case -5: + this.msg = "返回包的命令码有误"; + break; + case -6: + this.msg = "输出缓冲区预留太小"; + break; + case -25: + this.msg = "输入的 HASH 值长度应该为 32 个字节"; + break; + case -26: + this.msg = "用户标识超长(应该<=16) "; + break; + case -27: + this.msg = "数据类型不合法 "; + break; + case 33: + this.msg = "检索的数据或密钥不存在"; + break; + case 4: + this.msg = "DER 编码格式错误(公钥) "; + break; + case 21: + this.msg = "输入的数据格式错误 "; + break; + case 19: + this.msg = "数据解密错(C3) "; + break; + case 2: + this.msg = "签名验证错误 "; + break; + + case 32770: + this.msg = "签名验证错误(P7) "; + break; + + case 32773: + this.msg = "证书不可信"; + break; + + case 32884: + this.msg = "证书或签名数据的格式错"; + break; + + case 36868: + this.msg = "DN 所指向的实体不存在"; + break; + + case 40000: + this.msg = "输入的大数据处理异常"; + + default: + this.msg = "未定义的错误"; + } + } + + public SydApiException(int retCode) { + this.retCode = retCode; + transMsg(); + } + + + public SydApiException(String msg, int ret){ + this(ret); + if (null == msg || "".equals(msg)){ + transMsg(); + }else { + this.msg = msg; + } + } + + public static SydApiException fromBin( byte[] b , String msg){ + int code = null != b && b[0] >= 48 && b[0] <= 57 ? Util.a2i( b , 10) : Util.b2i( b ); + return new SydApiException(msg, code); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(SydApiException.class.getName()); + sb.append(" : "); + sb.append("code = "); + sb.append(this.retCode); + sb.append(" ( 0x"); + sb.append(Integer.toHexString(this.retCode)); + sb.append(" ) "); + sb.append(" msg = "); + sb.append(this.msg); + return sb.toString(); + } +} diff --git a/src/main/java/com/sunyard/cert/Cert.java b/src/main/java/com/sunyard/cert/Cert.java new file mode 100644 index 0000000..ae032ac --- /dev/null +++ b/src/main/java/com/sunyard/cert/Cert.java @@ -0,0 +1,26 @@ +package com.sunyard.cert; + +import com.sunyard.proto.Util; + +public class Cert extends CertInfo { + + // 公钥数据 + private byte[] pubKey; + + + public byte[] getPubKey() { + return pubKey; + } + + public void setPubKey(byte[] pubKey) { + this.pubKey = pubKey; + } + + public void setPubKey(byte[] pubKey, int offsize, int len) { + int l = (0xFF & pubKey[offsize]) * 256 + (0xFF & pubKey[offsize + 1]); + + byte[] pk = new byte[ l ]; + System.arraycopy(pubKey, offsize + 2, pk , 0, l); + this.pubKey = Util.hexString2Bytes(new String(pk)); + } +} diff --git a/src/main/java/com/sunyard/cert/CertInfo.java b/src/main/java/com/sunyard/cert/CertInfo.java new file mode 100644 index 0000000..21a3390 --- /dev/null +++ b/src/main/java/com/sunyard/cert/CertInfo.java @@ -0,0 +1,14 @@ +package com.sunyard.cert; + +public class CertInfo extends Info { + + private String cert; + + public String getCert() { + return cert; + } + + public void setCert(String cert) { + this.cert = cert; + } +} diff --git a/src/main/java/com/sunyard/cert/Info.java b/src/main/java/com/sunyard/cert/Info.java new file mode 100644 index 0000000..bef261a --- /dev/null +++ b/src/main/java/com/sunyard/cert/Info.java @@ -0,0 +1,62 @@ +package com.sunyard.cert; + +import com.sunyard.proto.Util; + +/** + * Created by Ztt on 2017/8/3. + */ +abstract public class Info { + // 颁发者 DN + private String issuer; + // 证书序列号 + private String serialNumber; + // 证书主题 + private String subject; + // 证书有效期的起始时间 + private String notBefore; + // 证书有效期的终止时间 + private String notAfter; + + + public String getIssuer() { + return issuer; + } + + public void setIssuer(String issuer) { + this.issuer = issuer; + } + + public String getSerialNumber() { + return serialNumber; + } + + public void setSerialNumber(String serialNumber) { + this.serialNumber = serialNumber; + } + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getNotBefore() { + return notBefore; + } + + public void setNotBefore(String notBefore) { + this.notBefore = notBefore; + } + + public String getNotAfter() { + return notAfter; + } + + public void setNotAfter(String notAfter) { + this.notAfter = notAfter; + } + + +} diff --git a/src/main/java/com/sunyard/cert/X509.java b/src/main/java/com/sunyard/cert/X509.java new file mode 100644 index 0000000..98f908a --- /dev/null +++ b/src/main/java/com/sunyard/cert/X509.java @@ -0,0 +1,8 @@ +package com.sunyard.cert; + +/** + * Created by Ztt on 2017/8/3. + */ +public class X509 extends Cert { + +} diff --git a/src/main/java/com/sunyard/inf/SydCertApi.java b/src/main/java/com/sunyard/inf/SydCertApi.java new file mode 100644 index 0000000..0816dbb --- /dev/null +++ b/src/main/java/com/sunyard/inf/SydCertApi.java @@ -0,0 +1,82 @@ +package com.sunyard.inf; + + +import com.sunyard.cert.X509; + +/** + * 证书操作相关接口 + */ +public interface SydCertApi { + /** + * 通过证书的 DN,获取证书的序号。 + * @param nCertType 输入 证书类型,0x00:签名证书,0x01:加密证书 + * @param certDN 输入。证书 subject 的 DN。 + * @return CertSerial 证书有 SN。 + */ + String getX509SN( + int nCertType, + byte[] certDN + ); + + /** + * 通过证书 获得 DER编码的公钥。 + * @param dnType 证书类型 0:签名证书, 1:加密证书 + * @param dn 传入的证书 + * @return 输出的公钥串,DER 编码,HEX 格式。输出的公钥串,DER 编码,HEX 格式。 + */ + String GetDNPublicKey( + int dnType, + byte[] dn + ); + + /** + * 通过使用者 ID 获得使用者的 SM2 公钥(DER 编码)。 + * @param userId 使用者的 ID,最大长度为 16 位数字,右对齐。 + * @param nKeyTypes 密钥类型,0x00:签名公钥, 0x01:加密公钥。 + * @return 输出的公钥串,DER 编码,HEX 格式。输出的公钥串,DER 编码,HEX 格式。 + */ + String SM2GetPublicKeyC( + String userId, + int nKeyTypes + ); + + String SM2GetPublicKeyC_QX( + int userId, + int nKeyTypes + ); + + + /** + * 输入 X509 格式的证书,获取证书信息。 + * @param pCert base64 编码的证书 + * @return 证书信息类 + */ + X509 GetX509CertInfo( + String pCert + ); + + + /** + * 通过使用者 ID 获取的 X509 证书文件。 + * @param userId 使用者的 ID,最大长度为 16 位数字(要与生成实体的机构号保持一致)。 + * @param nCertType 证书类型,0x00:签名证书, 0x01:加密证书 + * @return base64 编码的证书 + */ + String GetX509CertFileC( + String userId, + int nCertType + ); + + + /** + * 从签名中获取证书 + * @param orgData 待签名的原始数据 + * @param sign 签名数据 + * @return 证书信息(包含公钥字段) + */ + public X509 SYD_Get_X509_CertInfo_HA( + byte[] orgData, + String sign + ); + +} diff --git a/src/main/java/com/sunyard/inf/SydCryptionApi.java b/src/main/java/com/sunyard/inf/SydCryptionApi.java new file mode 100644 index 0000000..c4fcb66 --- /dev/null +++ b/src/main/java/com/sunyard/inf/SydCryptionApi.java @@ -0,0 +1,210 @@ +package com.sunyard.inf; + +/** + * 对称加解密相关接口 + */ + +public interface SydCryptionApi extends SydSYMApi, SydASYMApi, SydHashApi { + +} + + +/** + * Hash 算法接口 + */ +interface SydHashApi { + + /** + * 输入对指定的原始数据和公钥,通过 SM3 算法计算数据的散列值。 + * + * @param publicKey 公钥(可以为空) + * @param data 原始数据 + * @param mac 上一轮 mac 值 + * @return HASH 值,32 个 Bytes. + */ + byte[] SM3Hash(String publicKey, byte[] data, int i, byte[] mac); + + + /** + * 输入对指定的原始数据和公钥,通过 SM3 算法计算数据的散列值。 + * + * @param publicKey 公钥(可以为空) + * @param data 原始数据 + * @return HASH 值,32 个 Bytes. + */ + byte[] SM3Hash(String publicKey, byte[] data); + + + /** + * 输入对指定的原始数据 (无公钥),通过 SM3 算法计算数据的散列值。 + * + * @param data 原始数据 + * @return HASH 值,32 个 Bytes. + */ + byte[] SM3Hash(byte[] data); + + + public byte[] MACCalc(int alg, int keyType, int fullmode, int maclen, String key, byte[] infoData); + + /** + * mac 计算 + * @param alg 0=DES 1=3DES 2=SM4 3=AES 4=IDEA 5=SM1 6=3DES-X9.19 + * @param keyType 0-TAK 1-ZAK + * @param fullMode 0-弱填充 1 强填充 + * @param AK 密钥 + * @param infoData <=1024 + * @param macLen 1=4Byte 2=8Byte 3=16Byte(仅在SM4/AES 下有效) + * @return mac 值 hex 格式 + */ + public String MACCalc(int alg, int keyType, String AK, int fullMode, byte[] infoData, int macLen); + public void MACCheck(int alg, int keyType, String AK, int fullMode, byte[] infoData, String mac); + + public String calcPBOCMAC(int mode, int keyType, String key, byte[] data, int block, byte[] iv); + +} + + +/** + * 非对称加解密接口 + */ +interface SydASYMApi { + /** + * 用指定的 SM2 公钥对指定的密文数据进行加密。 + * + * @param publicKey 公钥钥串,DER 编码,HEX 格式。 + * @param pOrgData 加密的数据。 + * @return 加密的数据 base64 编码。 + */ + String SM2Encrypt( + byte[] publicKey, + byte[] pOrgData + ); + + + /** + * 通过使用者 ID 所对应的私钥对指定的密文数据进行解密。 + * + * @param userId 使用者的 ID,最大长度为 16 位数字,右对齐。 + * @param pEnData 加密的数据,base64 编码。 + * @return 明文数据。 + */ + byte[] SM2DecryptC( + String userId, + String pEnData + ); +} + + +/** + * 对称加解密接口 + */ +interface SydSYMApi { + + public byte[] SYMEnDeData(Boolean isEn, int nAlg, String seesionKey, int roundmod, int fullMode, byte[] pInData, byte[] iv, int block); + + + + /** + * 用输入的会话密钥,对指定报文数据进行加密处理。 + * + * @param nAlg  算法标识.,0x00:3DES,0x01:SM4。 + * @param seesionKey  本地LMK 加密的会话密钥,HEX 格式 + * @param pINdata  要加密的报文明文。必须是 8 或16 的倍数。 + * @return 输出的报文密文, 长度为报文明文 + 16 + */ + byte[] SYMEncryptData(int nAlg, String seesionKey, byte[] pINdata); + byte[] SYMEncryptData(int nAlg, String seesionKey, int fullmode, byte[] pINdata); + + byte[] SYMEncryptData_nofill(int nAlg, String seesionKey, byte[] pInData); + + + /** + * 用输入的会话密钥,对指定报文数据进行解密处理。 + * + * @param nAlg  算法标识.,0x00:3DES,0x01:SM4。 + * @param seesionKey 本地LMK 加密的会话密钥,HEX 格式 + * @param pINdata 要解密的报文密文。长度必须是8 或16 的倍数。 + * @return 输出的报文明文。 + */ + byte[] SYMDecryptData(int nAlg, String seesionKey, byte[] pINdata); + byte[] SYMDecryptData(int nAlg, String seesionKey, int fullmode, byte[] pINdata); + + byte[] SYMDecryptData_nofill(int nAlg, String seesionKey, byte[] pInData); + + boolean SYMDecryptDataWithFile(int nAlg, String seesionKey, String inputPath, String outputPath) throws Exception; + + /** + * 用输入的会话密钥,对指定报文数据进行加密处理。 + * + * @param nAlg  算法标识.,0x00:3DES,0x01:SM4。 + * @param seesionKey  本地LMK 加密的会话密钥,HEX 格式 + * @param pINdata  要加密的报文明文。必须是 8 或16 的倍数。 + * @return 输出的报文密文, 长度为报文明文 + 16 + */ + byte[] SYMEncryptDataCBC(int nAlg, String seesionKey, byte[] pINdata); + public byte[] SYMEncryptDataCBC(int nAlg, String seesionKey, int fullmode, byte[] pInData); + + /** + * 用输入的会话密钥,对指定报文数据进行解密处理。 + * + * @param nAlg  算法标识.,0x00:3DES,0x01:SM4。 + * @param seesionKey 本地LMK 加密的会话密钥,HEX 格式 + * @param pINdata 要解密的报文密文。长度必须是8 或16 的倍数。 + * @return 输出的报文明文。 + */ + byte[] SYMDecryptDataCBC(int nAlg, String seesionKey, byte[] pINdata); + public byte[] SYMDecryptDataCBC(int nAlg, String seesionKey, int fullmode, byte[] pInData); + + /** + * 用输入的会话密钥,对指定报文数据进行解密处理。 + * + * @param srcKey  源秘钥.十六进制字符串。 + * @param desKey  目的秘钥.十六进制字符串。 + * @param sca  源算法SCA.Int类型。 + * @param sPin  源PIN块.十六进制字符串。 + * @param primaryAccount  主账号.十六进制字符串。 + * @return 目的Pin块。 + */ + byte[] transPinFrOneKeyToAno(String srcKey, String desKey, int sca, String sPin, String primaryAccount); + + + /** + * 用一把DEK密钥加密数据, 报文总长度不大于8192 + * + * @param alg 加密算法 + * @param DEK DEK密钥 + * @param infoData 数据 + * @param vector 初始向量数据 可选项,当加密模式为CBC,CFB或OFB时才显示此项 + * @param disperseAlg 分散算法 + * @return 密文数据 + */ + byte[] SYD_Encrypt_Data(int alg, String DEK, byte[] infoData, byte[] vector, int disperseAlg, byte[] factor); + + + /** + * 用DEK密钥解密数据, 报文总长度不大于8192 + * + * @param alg 解密算法 + * @param DEK DEK密钥 + * @param infoData 数据密文 + * @param vector 初始向量数据 可选项,当加密模式为CBC,CFB或OFB时才显示此项 + * @param disperseAlg 分散算法 + * @return 解密后的明文数据 + */ + byte[] SYD_Decrypt_Data(int alg, String DEK, byte[] infoData, byte[] vector, int disperseAlg, byte[] factor); + + + /** + * 对于给定的数据生成一个MAC + * + * @param key LMK对(16-17)下加密的TAK + * @param infoData 生成MAC的数据 + * @param IV + * @param disperseNum 指定对根密钥分散的次数(1-3次) + * @param disperseAlg 分散算法 + * @return 所计算出的MAC + */ + byte[] SYD_MAC_Data(String key, String infoData, byte[] factor, String IV, int disperseNum, int disperseAlg); + + +} diff --git a/src/main/java/com/sunyard/inf/SydGenApi.java b/src/main/java/com/sunyard/inf/SydGenApi.java new file mode 100644 index 0000000..0aaf87a --- /dev/null +++ b/src/main/java/com/sunyard/inf/SydGenApi.java @@ -0,0 +1,144 @@ +package com.sunyard.inf; + +import com.sunyard.RetWrap; + + +/** + * 密钥生成相关接口 + */ +public interface SydGenApi { + /** + * RSA、SM2 非对称密钥产生 + * + * @return RetWrap 包含 privateKey 和 publicKey + * privateKey LMK 加密下的私钥 + * publicKey 公钥的 DER 编码 + */ + RetWrap SM2GenKeyPair(); + + /** + * RSA、SM2 非对称密钥产生 + * @param keyType 算法标识 0:RSA 1:SM2 + * @param index 27位数字,以此索引存储生成的密钥 + * @param length 长度 + * @return RetWrap 包含 privateKey 和 publicKey + * privateKey LMK 加密下的私钥 + * publicKey 公钥的 DER 编码 + * 再之前的接口上添加了索引参数 + */ + RetWrap SM2OrRSAGenKeyPair(int keyType,String index,int length); + + + /** + * 对称密钥产生 + * @param keyType 密钥类型 + * @param solution 密钥方案(LMK) 密钥长度/LMK下加密密钥的方案。 + * @return RetWrap 包含 + * lmkKey LMK LMK加密密钥 + * keyCheck 密钥校验值 + * + */ + RetWrap genSymmetricKey(String keyType,char solution); + RetWrap genAndPrintSplit(String keyType,char solution); + + + public RetWrap outputKey(String keyType, char solution, String zmk, String key); + public RetWrap inputKey(String keyType, char solution, String zmk, String key); + + /** + * 密钥合成 + * @param keyType 密钥类型 + * @param keySolution 密钥方案(LMK) 密钥长度/LMK下加密密钥的方案。 + * @param keyClearPattern 两个明文分量异或合成 + * @return RetWrap 包含 + * lmkKey LMK LMK加密密钥 + * keyCheck 密钥校验值 + * + */ + RetWrap genComposeKey(String keyType,char keySolution,String keyClearPattern); + RetWrap genComposeKey(String[] keys); + /** + * SM2 非对称密钥产生和存储 + * + * @return RetWrap 包含 privateKey 和 publicKey + * privateKey LMK 加密下的私钥 + * publicKey 公钥的 DER 编码 + */ + RetWrap SYD_SM2GenKeyPair(); + + + /** + * 此函数用于会话密钥的产生,用发起端。 + * 加密机产生随机会话密钥,输出两类密文: + * 1、 公钥加密的密文,用于密钥的传递。 + * 2、 本地 LMK 加密,用于本地应用数据的加解密。 + * + * @param publicKey 公钥串,DER 编码,HEX 格式。 + * @return CipherKey 公钥加密的会话密钥,DER 编码,HEX 格式, SessionKey 本地LMK 加密的会话密钥,HEX 格式 , KCV 会话密钥的检验值,HEX 格式,长度为 16H + */ + RetWrap SM2GenSessionKey(String publicKey); + + + /** + * 此函数用于会话密钥的接收,用于接收端。 + * 加密机通过使用者 ID 所对应的私钥解密对方公钥加密的密文,输出本地 LMK 加密的会话密钥,用于本地应用数据的加解密。 + * + * @param userId 使用者的 ID,最大长度为 16 位数字,右对齐。 + * @param cipherKey 公钥加密的会话密钥,DER 编码,HEX 格式 + * @return SessionKey : 本地LMK 加密的会话密钥,HEX 格式 ; KCV 会话密钥的检验值,HEX 格式,长度为 16H。 + */ + RetWrap SM2ConfirmSessionKeyC(String userId, String cipherKey); + /** + * 此函数用于会话密钥的接收,用于接收端。 + * 加密机通过使用者 ID 所对应的私钥解密对方公钥加密的密文,输出本地 LMK 加密的会话密钥,用于本地应用数据的加解密。 + * + * @param sk 私钥 + * @param cipherKey 公钥加密的会话密钥,DER 编码,HEX 格式 + * @return SessionKey : 本地LMK 加密的会话密钥,HEX 格式 ; KCV 会话密钥的检验值,HEX 格式,长度为 16H。 + */ + RetWrap SM2ConfirmSessionKey(String sk, String cipherKey); + + + /** + * 产生对称密钥,通过公钥加密生成网联格式的数字信封。 + + * @param certSerial 对*方 X509 证书的序列号。 + * @param nAlg 算法标识,0:AES,1:SM4 + * @return RetWrap 包含 CipherKey SessionKey KCV + * CipherKey 公钥加密的会话密钥 ,BASE64 编码 + * SessionKey 本地LMK 加密的会话密钥,HEX 格式, 本地 LMK 加密的会话密钥长度,HEX 格式(不包括第 1 个字符),一般为 33 个 Bytes。默认输入值为缓冲区的大小。 + * KCV 会话密钥的检验值,HEX 格式,长度为 32H。 + */ + RetWrap generateDE( + String certSerial, + byte nAlg + ); + + + /** + * 接收用私钥解密数字信封,还原对称密钥。 + * + * @param pCertSerial 输入。 对方 X509 证书的序列号。 + * @param pCipherKey 输入。 公钥加密的会话密钥,BASE64 编码 + * @return RetWrap 包含 SessionKey KCV + * SessionKey 输出。 本地LMK 加密的会话密钥,格式为:密钥类型|密钥密文,比如:02|密钥密文 + * KCV 会话密钥的检验值,HEX 格式,长度为 36H。 + */ + RetWrap decryptDE( + String pCertSerial, + String pCipherKey + ); + + /** + * 产生要求长度的随即数据串,可用于身份认证 + * + * @param nRandomSize 需要输出的随机串的长度 + * @return 未抛出异常表示成功, 返回 HEX 格式的密钥 + * + */ + String GenerateRandom( + int nRandomSize + ); + + +} diff --git a/src/main/java/com/sunyard/inf/SydPINOpt.java b/src/main/java/com/sunyard/inf/SydPINOpt.java new file mode 100644 index 0000000..945db95 --- /dev/null +++ b/src/main/java/com/sunyard/inf/SydPINOpt.java @@ -0,0 +1,65 @@ +package com.sunyard.inf; + + +/** + * 密钥工具类接口 + * 不影响数据库中的密钥 + */ +public interface SydPINOpt { + + + String transPINFromZPKToZPK(String zpk1, String zpk2, int sca, int dca, int spt, int dpt, String pin, String account); + + String transPINFromTPKToZPK(String tpk, String zpk, int sca, int dca, int spt, int dpt, String pin, String account); + +// +// /** +// * 将 PIN 从一个 ZPK 加密转为另一个 ZPK 加密 +// * @param zpk1 源 PIN保护密钥 +// * @param zpk2 目标 PIN保护密钥 +// * @param account1 源账号 +// * @param account2 目标账号 +// * @param pin 源 PIN 密文 +// * @return PIN 密文 +// */ +// String transPinFromZPKToZPK(String zpk1, String zpk2, String account1, String account2, String pin); +// +// +// /** +// * 将 PIN 从一个 ZPK 加密转为另一个 ZPK 加密 +// * @param zpk1 源 PIN保护密钥 +// * @param zpk2 目标 PIN保护密钥 +// * @param account 账号 +// * @param pin 源 PIN 密文 +// * @return PIN 密文 +// */ +// String transPinFromTPKToZPK(String zpk1, String zpk2, String account, String pin); +// +// +// /** +// * +// * ZPK转PVK加密的IBM PIN OFFSET +// * +// * @param zpk 区域 PIN保护密钥 +// * @param pvk 验 PIN 专用密钥 +// * @param account1 源账号 +// * @param account2 目标账号 +// * @param pin ZPK 加密的 PIN 密文 +// * @return IBM PIN OFFSE +// */ +// String calculateIBMPinOffsetFromZPKToPVK(String zpk, String pvk, String account1, String account2, String pin); +// +// +// /** +// * ZPK转PVK加密的IBM PIN OFFSET并校验 +// * +// * @param zpk 区域 PIN保护密钥 +// * @param pvk 验 PIN 专用密钥 +// * @param account1 源账号 +// * @param account2 目标账号 +// * @param pin ZPK 加密的 PIN 密文 +// * @param pinOffset IBM PIN OFFSE +// * @return true 校验通过 / false 校验不通过 +// */ +// Boolean verifyIBMPinOffsetFromZPKToPVK(String zpk, String pvk, String account1, String account2, String pin, String pinOffset); +} diff --git a/src/main/java/com/sunyard/inf/SydPledge.java b/src/main/java/com/sunyard/inf/SydPledge.java new file mode 100644 index 0000000..d6e70ef --- /dev/null +++ b/src/main/java/com/sunyard/inf/SydPledge.java @@ -0,0 +1,26 @@ +package com.sunyard.inf; + +public interface SydPledge { + + /** + * 编押 + * @param AreaCode 地区代码 6 位 + * @param Alg SydApi.NALG_3DES/SydApi.NALG_SM4 + * @param Version 版本号 + * @param Data 原始数据 + * @return MAC 长度为 8 的 HEX字符串 + */ + public String GenerateMIYA(String AreaCode, int Version, int Alg, byte[] Data); + + /** + * + * @param AreaCode 地区代码 6 位 + * @param Alg SydApi.NALG_3DES/SydApi.NALG_SM4 + * @param Version 版本号 + * @param MAC 长度为 8 的 HEX字符串 + * @param Data 原始数据 + * @return true=核押通过 false=核押不通过 + */ + public boolean VerifyMIYA(String AreaCode, int Version, int Alg, String MAC, byte[] Data); + +} diff --git a/src/main/java/com/sunyard/inf/SydRawApi.java b/src/main/java/com/sunyard/inf/SydRawApi.java new file mode 100644 index 0000000..08c0a37 --- /dev/null +++ b/src/main/java/com/sunyard/inf/SydRawApi.java @@ -0,0 +1,21 @@ +package com.sunyard.inf; + +public interface SydRawApi { + + /** + * 加密机直接通信 + * @param pack 组好的 Hex 格式包 + * @return 返回加密机返回 Hex 格式包 + */ + public String send(String pack); + + + /** + * 加密机直接通信 + * @param pack 组好的包 + * @return 返回加密机返回包 + */ + public byte[] send(byte[] pack); + + +} diff --git a/src/main/java/com/sunyard/inf/SydSVApi.java b/src/main/java/com/sunyard/inf/SydSVApi.java new file mode 100644 index 0000000..be36c1e --- /dev/null +++ b/src/main/java/com/sunyard/inf/SydSVApi.java @@ -0,0 +1,261 @@ +package com.sunyard.inf; + + +import com.sunyard.RetWrap; + +/** + * 签名验签相关接口 + */ +public interface SydSVApi extends SydNakedSVApi, SydAttachedSVApi, SydDetachedSVApi{ + +} + +/** + * 不经过 CA 授信 + * 直接使用公私钥对签名验签 + */ +interface SydNakedSVApi { + /** + * 使用指定的证书 DN,从加密设备获取对应的私钥证书,对指定的原始数据编制裸签名(遵循 PKCS#1) + * @param orgData 待签名的原始数据 + * @param sCertDN 签名者证书 DN + * @return 签名数据 + */ + public byte[] SYD_NakedSign( + byte[] orgData, + String sCertDN + ); + + + /** + * 使用指定的证书 DN,对指定的原始数据编制裸验签(遵循PKCS#1) + * @param orgData 待签名的原始数据 + * @param sign 签名数据 + * @param sCertDN 签名者证书 DN + * @return 验签是否通过 + */ + public boolean SYD_NakedVerify( + byte[] orgData, + byte[] sign, + String sCertDN + ); +} + +/** + * 带原文的签名验签 + */ +interface SydAttachedSVApi { + + /** + * SM2 私钥签名 + * @param pUserID 使用者的 ID,最大长度为 16 位数字,右对齐。 + * @param certNo 证书号 + * @param nOrgDataType 原始数据类型 0 : hash 1 : 原数据 + * @param publicKey 公钥的 DER 编码 + * @param orgData 原始数据 + * @return 签名的 base64 编码 + */ + String SM2SignC( + String pUserID, + String certNo, + int nOrgDataType, + byte[] publicKey, + byte[] orgData + ); + + /** + * RSA 私钥签名 + * @param HashMark 哈希标识 指示用于哈希证书数据的哈希算法的标识。0: SHA1 1: SHA256 2: MD5。 + * @param privateKeyTag 私钥标记 指示私钥位置的标记。数字为存储私钥的索引,除了全9表示使用由命令中提供的密钥。 + * 27位的索引号:16位机构号+3位密钥类型+8位密钥索引号 + * @param nOrgDataType 原始数据类型 0 : hash 1 : 原数据 + * @param orgData 原始数据 + * @return 签名的 base64 编码 + */ + byte[] RSASignC( + String privateKeyTag, + int HashMark, + int nOrgDataType, + byte[] orgData); + + + byte[] RSASign( + String privateKey, + int HashMark, + int nOrgDataType, + byte[] orgData); + + /** + * 采用 RSA 算法,用指定的公钥对指定的原始数据进行数字签名验证。 + * @param HashMark 证书号 + * @param nOrgDataType 签名方式 + * @param publicKey 公钥 + * @param orgData 原始数据 + * @param sign base64 格式的签名 + * @return true 验签通过 false 验签失败 + */ + boolean RSAVerify( + int HashMark, + int nOrgDataType, + byte[] publicKey, + byte[] orgData, + byte[] sign); + + + /** + * 采用 SM2 算法,用指定的公钥对指定的原始数据进行数字签名验证。 + * @param certNo 哈希标识 指示用于哈希证书数据的哈希算法的标识。0: SHA1 1: SHA256 2: MD5 + * @param nOrgDataType 签名方式 + * @param publicKey 公钥 + * @param orgData 原始数据 + * @param sign base64 格式的签名 + * @return true 验签通过 false 验签失败 + */ + boolean SM2Verify( + String certNo, + int nOrgDataType, + byte[] publicKey, + byte[] orgData, + String sign + ); + + + /** + * SM2 私钥签名 + * @param certNo 证书号 + * @param orgData 原始数据 + * @return 签名的 base64 编码 + */ + String SM2SignCustomized( + String certNo, + byte[] orgData + ); + + /** + * 采用 SM2 算法,用指定的公钥对指定的原始数据进行数字签名验证。 + * @param certNo 证书号 + * @param orgData 原始数据 + * @param sign base64 格式的签名 + * @return true 验签通过 false 验签失败 + */ + boolean SM2VerifyCustomized( + String certNo, + byte[] orgData, + String sign + ); +} + + +/** + * 不带原文的签名验签 + */ +interface SydDetachedSVApi { + + /** + * 对指定的原始数据核验其带公钥证书签名(PKCS#7) + * @param orgData 待签名的原始数据 + * @param sign 签名数据 + * @return 验签是否通过 + */ + public boolean SYD_DetachedVerify( + byte[] orgData, + String sign); + + + /** + * 通过指定的私钥对指定的原始数据编制带公钥证书的数字签名(遵循PKCS#7) + * @param orgData 待签名的原始数据 + * @param sCertDN 签名者证书 DN + * @return 签名数据 + */ + public String SYD_DetachedSign( + byte[] orgData, + String sCertDN + ); + + + + /** + * 通过指定的私钥对指定的原始数据编制带公钥证书的数字签名(遵循PKCS#7) + * 待签名的原始数据将在接口内部进行 sm3 ,然后做 Detach 签名 + * @param orgData 待签名的原始数据 + * @param publicKey sm3 hash 所用的公钥 + * @param sCertDN 签名者证书 DN + * @return 签名数据 + */ + public String sm3AndDetachedSign( + byte[] orgData, + String publicKey, + String sCertDN + ); + + + + /** + * 对指定的原始数据核验其带公钥证书签名(PKCS#7) + * 原始数据将在接口内部进行 sm3 ,然后做 Detach 验签 + * @param orgData 待签名的原始数据 + * @param publicKey sm3 hash 所用的公钥 + * @param sign 签名数据 + * @return 验签是否通过 + */ + public boolean sm3AndDetachedVerify( + byte[] orgData, + String publicKey, + String sign); + + + + /** + * + * 通过指定的私钥对指定的原始数据编制带公钥证书的数字签名(遵循PKCS#7) + * 数据模式可选 DATA_HASH 或 DATA_ORIGIN + * + * @param dataType 输入的数据为 HASH 后的数据 DATA_HASH = 0 ,输入的数据为原始数据库 DATA_ORIGIN = 1 + * @param orgData 输入的数据 + * @param sCertDN 签名者证书 DN + * @return 签名数据 + */ + public String detachedSign( + int dataType, + byte[] orgData, + String sCertDN + ); + //8024 + public byte[] detachedSign( + int dataType, + byte[] orgData, + int sCertDN + ); + + public String detachedSignbysn( + int dataType, + byte[] orgData, + String certificateNo); + + + /** + * 对指定的原始数据核验其带公钥证书签名(PKCS#7) + * 数据模式可选 DATA_HASH 或 DATA_ORIGIN + * + * @param dataType 输入的数据为 HASH 后的数据 DATA_HASH = 0 ,输入的数据为原始数据库 DATA_ORIGIN = 1 + * @param orgData 待签名的原始数据 + * @param sign 签名数据 + * @return 验签是否通过 + */ + boolean detachedVerify( + int dataType, + byte[] orgData, + String sign); + //8025 + boolean detachedVerify( + int dataType, + byte[] orgData, + byte[] sign); + + RetWrap SM3Hash(int packSn, String userId, byte[] publicKey, byte[] msg, byte[] filterData); + +} + + + diff --git a/src/main/java/com/sunyard/inf/customize/SydHAApi.java b/src/main/java/com/sunyard/inf/customize/SydHAApi.java new file mode 100644 index 0000000..41a2785 --- /dev/null +++ b/src/main/java/com/sunyard/inf/customize/SydHAApi.java @@ -0,0 +1,117 @@ +package com.sunyard.inf.customize; + +import com.sunyard.cert.X509; + +public interface SydHAApi { + + /** + * 通过机构实体ID获得使用者的SM2公钥(DER编码) + * @param pUserID 本机构实体ID,最大长度为16位数字,即设备安装生成实体时的实体机构输入栏的内容 + * @param nKeyType 密钥类型,0:签名公钥,1:加密公钥,如无加解密业务,传入0即可 + * @return 输出的公钥串,DER编码,HEX格式,此公钥是机构自己公钥证书的公钥 + */ + public String SYD_SM2_Get_Id_PublicKey_HA ( + String pUserID, + int nKeyType + ); + + + /** + * 通过证书DN获得机构的公钥(DER编码),联调前需要导入公钥证书 + * @param Dn 证书的DN,每个证书有唯一的DN + * @param nKeyType 密钥类型,0:签名公钥,1:加密公钥,如无加解密业务,传入0即可 + * @return 输出的公钥串,DER编码,HEX格式,此公钥为他方机构的公钥 + */ + public String SYD_SM2_Get_Dn_PublicKey_HA ( + byte[] Dn, + int nKeyType + ); + + + /** + * 通过本机构实体ID所对应的私钥对指定的原始数据进行数字签名(PKCS#1) + * @param pUserID 本机构实体ID,最大长度为16位数字,即设备安装生成实体时的实体机构输入栏的内容 + * @param nOrgDataType 输入的数据类型,0:HASH值,1:原始数据,原始数据由加密设备内部完成HASH并签名 + * @param publicKey 公钥串,DER编码,HEX格式。仅 OrgDataType=1有效, 2.1章节接口,输出公钥原串传入 + * @param orgData 待签名的原始数据 + * @return 签名数据( DER 编码 + Base64 编码) + */ + public String SYD_SM2_Sign_HA( + String pUserID, + int nOrgDataType, + byte[] publicKey, + byte[] orgData + ); + + /** + * 通过本机构实体ID所对应的私钥对指定的原始数据进行数字签名(PKCS#1) + * @param nOrgDataType 输入的数据类型,0:HASH值,1:原始数据,原始数据由加密设备内部完成HASH并签名 + * @param privateKey 私钥串,LMK34-35 下加密的私钥 + * @param publicKey 公钥串,DER编码,HEX格式。仅 OrgDataType=1有效, 2.1章节接口,输出公钥原串传入 + * @param orgData 待签名的原始数据 + * @return 签名数据( DER 编码 + Base64 编码) + */ + public String SYD_SM2_Sign_HA( + int nOrgDataType, + byte[] privateKey, + byte[] publicKey, + byte[] orgData + ); + + + + /** + * 用指定的公钥对指定的原始数据进行数字签名验证(PKCS#1) + * @param nOrgDataType 数据类型,SydApi.DATA_ORIGIN 原始数据 SydApi.DATA_HASH : hash 后的类型 + * @param publicKey 公钥串,DER编码,HEX格式,2.1章节接口,输出公钥原串传入 + * @param orgData 待签名的原始数据 + * @param sign 签名数据 (DER 编码 + Base64 编码) + * @return 验签是否通过 + */ + public boolean SYD_SM2_Verify_HA( + int nOrgDataType, + byte[] publicKey, + byte[] orgData, + String sign + ); + + + /** + * 对指定的原始数据核验其带公钥证书签名(PKCS#7) + * @param orgData 待签名的原始数据 + * @param sign 签名数据 + * @return 验签是否通过 + */ + public boolean SYD_SM2_DetachedVerify_HA( + byte[] orgData, + String sign ); + + + /** + * 通过指定的私钥对指定的原始数据编制带公钥证书的数字签名(遵循PKCS#7) + * @param orgData 待签名的原始数据 + * @param sCertDN 签名者证书 DN + * @return 签名数据 + */ + public String SYD_SM2_DetachedSign_HA( + byte[] orgData, + String sCertDN + ); + + + + // 外部私钥 + public String SM2Sign( + int nOrgDataType, + byte[] privateKey, + byte[] orgData + ); + + // SYD_SM2_Verify_HA + public boolean SM2Verify( + int nOrgDataType, + byte[] publicKey, + byte[] orgData, + String base64Sign + ); +} diff --git a/src/main/java/com/sunyard/inf/customize/SydQNUCApi.java b/src/main/java/com/sunyard/inf/customize/SydQNUCApi.java new file mode 100644 index 0000000..c73b266 --- /dev/null +++ b/src/main/java/com/sunyard/inf/customize/SydQNUCApi.java @@ -0,0 +1,33 @@ +package com.sunyard.inf.customize; + + +/** + * 网联全称 "网联清算有限公司"(China Nets Union Clearing Corporation) + * 是一个线上支付统一清算平台(unified clearing platform for online payment),在央行指导下,由中国支付清算协会(Payment & Clearing Association of China)组织支付机构成立,用以处理由非银行支付机构发起的、与银行交互的支付业务。 + */ +public interface SydQNUCApi { + + + /** + * 用指定的证书私钥对指定的数据进行数字签名。 + * @param pCertSerial 输入。签名 X509 证书的序列号。 + * @param pOrgData 输入。 待签名的原始数据。 + * @return 签名数据(BASE64 编码)。 + */ + public String netSign(String pCertSerial, byte[] pOrgData); + + + /** + * 用指定证书对指定的原始数据进行数字签名验证。 + * @param pCertSerial 输入。 签名 X509 证书的序列号。 + * @param pOrgData 输入。 待签名的原始数据。 + * @param pSignData 输入。 签名数据(BASE64 编码)。 + * @return true 表示验证正确;false 表示失败; + */ + boolean netVerify( + String pCertSerial, + byte[] pOrgData, + String pSignData + ); + +} diff --git a/src/main/java/com/sunyard/inf/customize/SydSDNXApi.java b/src/main/java/com/sunyard/inf/customize/SydSDNXApi.java new file mode 100644 index 0000000..f17dc54 --- /dev/null +++ b/src/main/java/com/sunyard/inf/customize/SydSDNXApi.java @@ -0,0 +1,62 @@ +package com.sunyard.inf.customize; + +import com.sunyard.cert.X509; + +/** + * 山东农信定制开发接口 + */ +public interface SydSDNXApi { + + /** + * 使用指定的证书 DN,从加密设备获取对应的私钥证书,对指定的原始数据编制裸签名(遵循 PKCS#1) + * @param orgData 待签名的原始数据 + * @param sCertDN 签名者证书 DN + * @return 签名数据 + */ + public String nakedSign( + byte[] orgData, + String sCertDN + ); + + + /** + * 使用指定的证书机构号,对指定的原始数据编制裸验签(遵循PKCS#1) + * @param orgData 待签名的原始数据 + * @param sign 签名数据 + * @param organizationNum 机构号 + * @return 验签结果,true:表示验证正确;验签不通过返回错误码和错误信息 + */ + public boolean SYD_NakedVerify( + byte[] orgData, + String sign, + String organizationNum + ); + + + + /** + * 验签,通过传入行号字符串,获取证书去验签 + * @param bNumber 行号,通过行号获取证书 + * @param orgData 带签名的原始数据 + * @param signData 签名数据( BASE64 编码) + * @return 验签结果,true:表示验证正确;验签不通过返回错误码和错误信息 + */ + /* boolean netVerify( + String bNumber, + byte[] orgData, + String signData + ); +*/ + /** + *验签 ,上传并返回证书内容,并更新机构号 + * @param bNumber 行号,通过行号获取证书 + * @param orgData 待签名的原始数据 + * @param sign 签名数据( BASE64 编码) + * @return 证书信息(包含公钥字段) + */ + public X509 SYD_Get_X509_CertInfo_HA( + String bNumber, + byte[] orgData, + String sign + ); +} diff --git a/src/main/java/com/sunyard/inf/customize/SydSDNXApiImpl.java b/src/main/java/com/sunyard/inf/customize/SydSDNXApiImpl.java new file mode 100644 index 0000000..9959469 --- /dev/null +++ b/src/main/java/com/sunyard/inf/customize/SydSDNXApiImpl.java @@ -0,0 +1,185 @@ +package com.sunyard.inf.customize; + +import com.sunyard.SydApiException; +import com.sunyard.cert.X509; +import com.sunyard.proto.Packet; +import com.sunyard.proto.PacketSection; +import com.sunyard.proto.Util; +import com.sunyard.trans.PacketSN; +import racal.sunyard.main.SydApi4j; +import racal.sunyard.main.proto.Proto8003; +import racal.sunyard.main.proto.Proto8004; +import racal.sunyard.main.proto.Proto8012; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class SydSDNXApiImpl extends SydApi4j implements SydSDNXApi { + + + public String nakedSign(byte[] orgData, String sCertDN) { + Proto8003 proto = new Proto8003(); //pset.getProtocolReqRender("75"); + byte[] dn = new byte[256]; + byte[] s = null; + try { + s = sCertDN.getBytes("GBK"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + System.arraycopy(s, 0, dn, 0, s.length); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("signatureDataType$option", 1); + data.put("DN", dn); + data.put("data", orgData); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + + + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + + throw new SydApiException(error.getInfo(), error.autoInt()); + + } + + return Util.encodeBase64(((PacketSection) ret.get("signature")).getBytes()); + //return ((PacketSection) ret.get("signature")).getBytes(); + } + + @Override + public boolean SYD_NakedVerify(byte[] orgData, String sign, String organizationNum) { + Proto8004 proto = new Proto8004(); //pset.getProtocolReqRender("75"); + + byte[] dn = new byte[256]; + byte[] s = null; + + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("signatureDataType$option", 2); + data.put("organizationNum", organizationNum); + data.put("data", orgData); + data.put("signature", Util.decodeBase64(sign)); + data.put("returnSign$option", 0); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + + + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ((0 != (be[0] ^ be[1]))) { + + throw new SydApiException(error.getInfo(), error.autoInt()); + } + return true; + } + + @Override + public X509 SYD_Get_X509_CertInfo_HA(String bNumber, byte[] orgData, String sign) { + + Proto8012 proto = new Proto8012(); //pset.getProtocolReqRender("75"); + + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("originData", orgData); + data.put("signData", sign.getBytes()); + data.put("flag$option", 2); + data.put("organizationNum", bNumber); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + + + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ((0 != (be[0] ^ be[1]))) { + + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + PacketSection info = (PacketSection) ret.get("info"); + + byte[] pCertInfo = info.getBytes(); +// X509 cinfo = new X509(); +// cinfo.setIssuer(Util.toCleanString(pCertInfo, 0, 257)); +// cinfo.setSerialNumber(Util.toCleanString(pCertInfo, 257, 65)); +// cinfo.setSubject(Util.toCleanString(pCertInfo, 257 + 65, 257)); +// cinfo.setNotBefore(Util.toCleanString(pCertInfo, 257 + 65 + 257, 15)); +// cinfo.setNotAfter(Util.toCleanString(pCertInfo, 257 + 65 + 257 + 15, 15)); +// byte[] blen = new byte[]{pCertInfo[257 + 65 + 257 + 15 + 15], pCertInfo[257 + 65 + 257 + 15 + 16]}; +// int len = Util.b2i(blen); +// byte[] pem = new byte[len]; +// System.arraycopy(pCertInfo, 257 + 65 + 257 + 15 + 17, pem, 0, len); +// String pp = new String(pem); + // 解析证书 + return GetX509CertInfo(new String(pCertInfo)); + } + + +} diff --git a/src/main/java/com/sunyard/trans/AlgorithmType.java b/src/main/java/com/sunyard/trans/AlgorithmType.java new file mode 100644 index 0000000..1600d0c --- /dev/null +++ b/src/main/java/com/sunyard/trans/AlgorithmType.java @@ -0,0 +1,34 @@ +package com.sunyard.trans; + +public enum AlgorithmType { + + // DES 加密 + ENCRYPT_DES, + // DES 解密 + DECRYPT_DES, + // AES 加密 + ENCRYPT_AES, + // AES 解密 + DECRYPT_AES, + // SSF33 加密 + ENCRYPT_SSF33, + // SSF33 解密 + DECRYPT_SSF33, + // SM1 加密 + ENCRYPT_SM1, + // SM1 解密 + DECRYPT_SM1, + // SM4 加密 + ENCRYPT_SM4, + // SM4 解密 + DECRYPT_SM4, + // IDEA 加密 + ENCRYPT_IDEA, + // IDEA 解密 + DECRYPT_IDEA, + // AES256 加密 + ENCRYPT_AES256, + // AES256 解密 + DECRYPT_AES256, + +} diff --git a/src/main/java/com/sunyard/trans/CMD.java b/src/main/java/com/sunyard/trans/CMD.java new file mode 100644 index 0000000..6d5ff19 --- /dev/null +++ b/src/main/java/com/sunyard/trans/CMD.java @@ -0,0 +1,19 @@ +package com.sunyard.trans; + +import java.nio.ByteBuffer; + +public enum CMD { + + // 加解密 + ENCRYPTION_DECRYPTION("E0"); + + private String value; + + public ByteBuffer getValue() { + return ByteBuffer.wrap(value.getBytes()); + } + + CMD(String value) { + this.value = value; + } +} diff --git a/src/main/java/com/sunyard/trans/DataType.java b/src/main/java/com/sunyard/trans/DataType.java new file mode 100644 index 0000000..aca775f --- /dev/null +++ b/src/main/java/com/sunyard/trans/DataType.java @@ -0,0 +1,11 @@ +package com.sunyard.trans; + +public enum DataType { + + // 二进制 + BIN, + // 十六进制编码的二进制 + HEX, + // 文本格式 + TXT +} diff --git a/src/main/java/com/sunyard/trans/FullEndType.java b/src/main/java/com/sunyard/trans/FullEndType.java new file mode 100644 index 0000000..c82c05b --- /dev/null +++ b/src/main/java/com/sunyard/trans/FullEndType.java @@ -0,0 +1,22 @@ +package com.sunyard.trans; + +public enum FullEndType { + + /** + * 填充数据的最后一个字节不填充计数位。解 + 密后的数据包含填充数据,由应用摘取实际数据。 + */ + WITH_END, + /** + * 填充数据的最后一个字节填充计数位。计数 + 位取值在 0x01 to 0x08/ 0x10 之间。解密后 + 的数据由加密机根据 Pad count flag 值在内部自 + 动去掉填充数据 + */ + AUTO_END, + + /** + * pkcs5和 pkcs7 填充 + */ + PKCS5_PKCS7 +} diff --git a/src/main/java/com/sunyard/trans/FullMode.java b/src/main/java/com/sunyard/trans/FullMode.java new file mode 100644 index 0000000..15f2760 --- /dev/null +++ b/src/main/java/com/sunyard/trans/FullMode.java @@ -0,0 +1,23 @@ +package com.sunyard.trans; + +/** + */ +public enum FullMode { + + /** + * 如果数据块长度为 8/16 的整数倍,不需要填 + 充;如果长度不为 8/16 的整数倍,填充至长度满 + 8/16 的整数倍(填充方式按 Pad character 域中 + 描述的规则进行,由加密机内部自动完成) + */ + FULL_8_16, + /** + * 如果数据块长度为 8/16 的整数倍,填充一个 + 整 8/16 字节的数据(填充方式按 Pad character + 域中描述的规则进行,由加密机内部自动完成); + 如果长度不为8/16的整数倍,填充至长度满8/16 + 的整数倍(填充方式按 Pad character 域中描述 + 的规则进行,由加密机内部自动完成) + */ + FULL_MORE_8_16 +} diff --git a/src/main/java/com/sunyard/trans/KeyType.java b/src/main/java/com/sunyard/trans/KeyType.java new file mode 100644 index 0000000..9b8d0d8 --- /dev/null +++ b/src/main/java/com/sunyard/trans/KeyType.java @@ -0,0 +1,10 @@ +package com.sunyard.trans; + +public enum KeyType { + + // LMK 加密的 ZEK (区域加密密钥) + ZEK, + // LMK 加密的 TEK () + TEK, + +} diff --git a/src/main/java/com/sunyard/trans/PackType.java b/src/main/java/com/sunyard/trans/PackType.java new file mode 100644 index 0000000..368501c --- /dev/null +++ b/src/main/java/com/sunyard/trans/PackType.java @@ -0,0 +1,13 @@ +package com.sunyard.trans; + +public enum PackType { + + // 唯一块 + ONLY, + // 起始块 + HEAD, + // 中间块 + MIDDLE, + // 结束块 + TAIL +} diff --git a/src/main/java/com/sunyard/trans/PacketSN.java b/src/main/java/com/sunyard/trans/PacketSN.java new file mode 100644 index 0000000..88bf323 --- /dev/null +++ b/src/main/java/com/sunyard/trans/PacketSN.java @@ -0,0 +1,80 @@ +package com.sunyard.trans; + +import com.sunyard.proto.Util; + +import java.nio.ByteBuffer; +import java.util.HashMap; + + +/** + * 生成包序号,不负责销毁。 + * 相同设备 sn 轮转 + * 不同设备 sn 无关 + */ +public class PacketSN { + + private static HashMap keeper = new HashMap(); + + private ByteBuffer sn; + private String devid; + + public static PacketSN gen(String devid){ + + // 申请小锁 + SN sn = keeper.get(devid); + if ( null == sn){ + // 申请全局锁 + synchronized (PacketSN.class){ + SN snCheck = keeper.get(devid); + if( null == snCheck){ + keeper.put(devid, new SN()); + sn = keeper.get(devid); + }else{ + sn = snCheck; + } + } + } + + return new PacketSN(sn.next(), devid); + } + + public static PacketSN gen(){ + return gen("default"); + } + + public PacketSN(ByteBuffer sn, String devid) { + this.sn = sn; + this.devid = devid; + } + + public ByteBuffer getSn() { + return sn; + } + + public String getDevid() { + return devid; + } + + public String getGlobalId(){ + return devid + "-" + Util.bytes2HexString(sn.array()); + } + +} + +class SN { + private long sn = 0; + + synchronized ByteBuffer next(){ + ByteBuffer bb = ByteBuffer.allocate(8); + bb.put((byte) ((sn >>> 56) & 0xFF)); + bb.put((byte) ((sn >>> 48) & 0xFF)); + bb.put((byte) ((sn >>> 40) & 0xFF)); + bb.put((byte) ((sn >>> 32) & 0xFF)); + bb.put((byte) ((sn >>> 24) & 0xFF)); + bb.put((byte) ((sn >>> 16) & 0xFF)); + bb.put((byte) ((sn >>> 8) & 0xFF)); + bb.put((byte) (sn & 0xFF)); + sn += 1; + return bb; + } +} diff --git a/src/main/java/com/sunyard/trans/RoundType.java b/src/main/java/com/sunyard/trans/RoundType.java new file mode 100644 index 0000000..2c13044 --- /dev/null +++ b/src/main/java/com/sunyard/trans/RoundType.java @@ -0,0 +1,16 @@ +package com.sunyard.trans; + + +public enum RoundType { + + // 占位 + DO_NOT_USE, + // 电子密码本 + ECB, + // 密码块连接 + CBC, + // 分组长度密码反馈 + CFB, + // 分组长度输出反馈 + OFB +} diff --git a/src/main/java/com/sunyard/trans/pkg/DataEncryptDecryptPacket.java b/src/main/java/com/sunyard/trans/pkg/DataEncryptDecryptPacket.java new file mode 100644 index 0000000..29a130f --- /dev/null +++ b/src/main/java/com/sunyard/trans/pkg/DataEncryptDecryptPacket.java @@ -0,0 +1,267 @@ +package com.sunyard.trans.pkg; + +import com.sunyard.trans.FullMode; +import com.sunyard.SydApiException; +import com.sunyard.proto.Util; +import com.sunyard.trans.*; + +import java.nio.ByteBuffer; + +public class DataEncryptDecryptPacket extends Packet { + + // 包类型 + private int packType; + // 算法标记 + private int alg; + // 轮类型 + private int round; + // 密钥类型 + private int keyType; + // 密钥 + private byte[] key; + // 输入数据类型 + private int inDataType; + // 输出数据类型 + private int outDataType; + // 填充模式 + private int fullMode; + // 填充字符 + private String fullCharacter; + // 填充类型 + private int fullEndType; + /** + * 消息类型影响消息长度(若消息类型为二进制,则为 + * 随后域长度;若消息类型为扩展十六进制,则为随后 + * 域长度的一半)。默认是 BIN + */ + private int messageType; + + // 消息数据 + private byte[] message; + + + public DataEncryptDecryptPacket() { + this.setCommand(CMD.ENCRYPTION_DECRYPTION); + } + + @Override + protected DataEncryptDecryptPacket clone(){ + DataEncryptDecryptPacket subPack = new DataEncryptDecryptPacket(); + subPack.setCommand(getCommand()); + subPack.setHeader(getHeader()); + subPack.setPackType(packType); + subPack.setAlg(alg); + subPack.setRound(round); + subPack.setKeyType(keyType); + subPack.setKey(key); + subPack.setInDataType(inDataType); + subPack.setOutDataType(outDataType); + subPack.setFullMode(fullMode); + subPack.setFullCharacter(fullCharacter); + subPack.setFullEndType(fullEndType); + return subPack; + } + + /** + * 初始向量 + * 仅当密钥加密轮函数类型为 CBC ,CFB ,OFB 时有此域。 + * 当密钥模式为 DES加解密 该域为 16H + * 当密钥模式为 AES SSF33 SM1 加解密时,该域为 32H + */ + private byte[] iv = new byte[0]; + + + public void setKeyType(KeyType keyType) { + this.keyType = keyType.ordinal(); + } + + + public void setRoundType(RoundType roundType) { + this.round = roundType.ordinal(); + } + + public void setPackType(PackType type) { + this.packType = type.ordinal(); + } + + public void setAlgType(AlgorithmType type){ + this.alg = type.ordinal(); + } + + public void setKey(byte[] key){ + this.key = key; + } + + + public void setIv(byte[] iv) { + if ( RoundType.CBC.ordinal() == round + || RoundType.CFB.ordinal() == round + || RoundType.OFB.ordinal() == round + ){ + if( AlgorithmType.ENCRYPT_DES.ordinal() == keyType + || AlgorithmType.DECRYPT_DES.ordinal() == keyType + ){ + if( 16 != iv.length ){ + throw new SydApiException(65535); + } + }else{ + if( 32 != iv.length ){ + throw new SydApiException(65535); + } + } + this.iv = iv; + } + throw new SydApiException(65535); + + } + + public void setInDataType(DataType dataType) { + this.inDataType = dataType.ordinal(); + } + + public void setOutDataType(DataType dataType) { + this.outDataType = dataType.ordinal(); + } + + public void setFullMode(FullMode mode,FullEndType endType, String firstChar, String otherChar){ + this.fullMode = mode.ordinal(); + this.fullCharacter = firstChar + otherChar; + this.fullEndType = endType.ordinal(); + } + + public void setMessage(DataType type , byte[] message) { + this.message = message; + this.messageType = type.ordinal(); + } + + public void setMessage(byte[] message) { + setMessage(DataType.BIN, message); + } + + private ByteBuffer toSubPack(){ + ByteBuffer bb = ByteBuffer.allocate(MAX_PACKAGE_DATA_LEN); + bb.put( Util.int2charbyte16(packType) ); + bb.put( Util.int2charbyte16(alg) ); + bb.put( Util.int2charbyte16(round) ); + bb.put( Util.int2charbyte16(keyType)); + bb.put( key ); + bb.put( Util.int2charbyte16(inDataType) ); + bb.put( Util.int2charbyte16(outDataType) ); + if ( 0 == packType || 3 == packType ){ + bb.put( Util.int2charbyte16(fullMode) ); + bb.put( fullCharacter.getBytes() ); + bb.put( Util.int2charbyte16(fullEndType)); + } + bb.put(iv); + int msgLen = message.length; + if ( DataType.HEX.ordinal() == messageType ){ + msgLen = msgLen/2; + } + bb.put(String.format("%03X", msgLen).getBytes()); + bb.put(message); + + this.setData(bb); + + return this.pack(); + } + + @Override + public ByteBuffer toSendPack(PacketSN sn) { + + setHeader(sn.getSn()); + + // 依据数据长度的不同可能需要分包 + int packLen = 2048; + int inDataLen = this.message.length; + // 拆包数量 + int loop = inDataLen / packLen; + if ( 0 != inDataLen % packLen ){ + loop += 1; + } + + ByteBuffer bb = ByteBuffer.allocate( packLen * loop ); + + int i = 0; + while ( i < loop){ + + DataEncryptDecryptPacket subPack = this.clone(); + if ( 0 == i){ + if ( 1 == loop){ + subPack.setPackType(PackType.ONLY); + }else{ + subPack.setPackType(PackType.HEAD); + } + }else{ + if ( (loop - 1) == i){ + subPack.setPackType(PackType.TAIL); + }else{ + subPack.setPackType(PackType.MIDDLE); + } + } + + // 唯一包 + if ( 1 == loop){ + subPack.setMessage(this.message); + }else{ + byte[] tMsg = new byte[packLen]; + // 最后一个包 + if ( (loop - 1) == i){ + System.arraycopy(this.message, i * packLen , tMsg, 0, this.message.length % packLen); + }else{ // 其他包 + System.arraycopy(this.message, i * packLen , tMsg, 0, packLen); + } + subPack.setMessage(tMsg); + } + + bb.put( subPack.toSubPack() ); + i++; + } + + + return bb; + } + + + + // POJO set + + public void setPackType(int packType) { + this.packType = packType; + } + + public void setAlg(int alg) { + this.alg = alg; + } + + public void setRound(int round) { + this.round = round; + } + + public void setKeyType(int keyType) { + this.keyType = keyType; + } + + public void setInDataType(int inDataType) { + this.inDataType = inDataType; + } + + public void setOutDataType(int outDataType) { + this.outDataType = outDataType; + } + + public void setFullMode(int fullMode) { + this.fullMode = fullMode; + } + + public void setFullCharacter(String fullCharacter) { + this.fullCharacter = fullCharacter; + } + + public void setFullEndType(int fullEndType) { + this.fullEndType = fullEndType; + } + + public void setMessageType(int messageType) { + this.messageType = messageType; + } +} diff --git a/src/main/java/com/sunyard/trans/pkg/Packet.java b/src/main/java/com/sunyard/trans/pkg/Packet.java new file mode 100644 index 0000000..6ebca3f --- /dev/null +++ b/src/main/java/com/sunyard/trans/pkg/Packet.java @@ -0,0 +1,70 @@ +package com.sunyard.trans.pkg; + + +import com.sunyard.trans.CMD; +import com.sunyard.trans.PacketSN; + +import java.nio.ByteBuffer; + +/** + * SJJ1316 加密机通用格式 + */ +public abstract class Packet { + + public static final int MAX_PACKAGE_DATA_LEN = 8192; + public static final int MAX_PACKAGE_LEN = MAX_PACKAGE_DATA_LEN + 10; + + + private ByteBuffer header; + private ByteBuffer command; + private ByteBuffer data; + private ByteBuffer length; + + + + public abstract ByteBuffer toSendPack(PacketSN sn); + + + public ByteBuffer getHeader() { + return header; + } + + public ByteBuffer getCommand() { + return command; + } + + public void setCommand(CMD cmd) { + this.command = cmd.getValue(); + } + + public void setCommand(ByteBuffer command) { + this.command = command; + } + + public void setHeader(ByteBuffer header){ + this.header = header; + } + + public void setData(ByteBuffer data){ + this.data = data; + int len = data.array().length + 8 + 2; + header.put(0, (byte) (len / 256)); + header.put(1, (byte) (len % 256)); + } + + + public ByteBuffer pack(){ + ByteBuffer bb = ByteBuffer.allocate(MAX_PACKAGE_LEN); + // 长度占位 + bb.put(length); + // head 占位 + bb.put(header); + // command 占位 + bb.put(command); + // data + bb.put(data); + + return bb; + } + +} diff --git a/src/main/java/com/sunyard/util/CoderUtil.java b/src/main/java/com/sunyard/util/CoderUtil.java new file mode 100644 index 0000000..99f21d8 --- /dev/null +++ b/src/main/java/com/sunyard/util/CoderUtil.java @@ -0,0 +1,174 @@ +package com.sunyard.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; + +public class CoderUtil { + + public static byte[] EToA = hexToBytes(getEDBToAsc()); + public static byte[] AToE = hexToBytes(getAscToEDB()); + + public static String getAscToEDB() { + StringBuffer sb = new StringBuffer(); + sb.append("00010203372D2E2F1605250B0C0D0E0F"); + sb.append("101112133C3D322618193F271C1D1E1F"); + sb.append("405A7F7B5B6C507D4D5D5C4E6B604B61"); + sb.append("F0F1F2F3F4F5F6F7F8F97A5E4C7E6E6F"); + sb.append("7CC1C2C3C4C5C6C7C8C9D1D2D3D4D5D6"); + sb.append("D7D8D9E2E3E4E5E6E7E8E9ADE0BD5F6D"); + sb.append("79818283848586878889919293949596"); + sb.append("979899A2A3A4A5A6A7A8A9C04FD0A107"); + sb.append("202122232415061728292A2B2C090A1B"); + sb.append("30311A333435360838393A3B04143EE1"); + sb.append("41424344454647484951525354555657"); + sb.append("58596263646566676869707172737475"); + sb.append("767778808A8B8C8D8E8F909A9B9C9D9E"); + sb.append("9FA0AAABAC4AAEAFB0B1B2B3B4B5B6B7"); + sb.append("B8B9BABBBC6ABEBFCACBCCCDCECFDAdB"); + sb.append("DCDDDEDFEAEBECEDEEEFFAFBFCFDFEFF"); + return sb.toString(); } + + public static String getEDBToAsc() { + StringBuffer sb = new StringBuffer(); + sb.append("000102039C09867F978D8E0B0C0D0E0F"); + sb.append("101112139D8508871819928F1C1D1E1F"); + sb.append("80818283840A171B88898A8B8C050607"); + sb.append("909116939495960498999A9B14159E1A"); + sb.append("20A0A1A2A3A4A5A6A7A8D52E3C282B7C"); + sb.append("26A9AAABACADAEAFB0B121242A293B5E"); + sb.append("2D2FB2B3B4B5B6B7B8B9E52C255F3E3F"); + sb.append("BABBBCBDBEBFC0C1C2603A2340273D22"); + sb.append("C3616263646566676869C4C5C6C7C8C9"); + sb.append("CA6A6B6C6D6E6F707172CBCCCDCECFD0"); + sb.append("D17E737475767778797AD2D3D45BD6D7"); + sb.append("D8D9DADBDCDDDEDFE0E1E2E3E45DE6E7"); + sb.append("7B414243444546474849E8E9EAEBECED"); + sb.append("7D4A4B4C4D4E4F505152EEEFF0F1F2F3"); + sb.append("5C9F535455565758595AF4F5F6F7F8F9"); + sb.append("30313233343536373839FAFBFCFDFEFF"); + return sb.toString(); } + + public static byte[] hexToBytes(char[] hex) { + int length = hex.length / 2; + byte[] raw = new byte[length]; + for (int i = 0; i < length; i++) { + int high = Character.digit(hex[i * 2], 16); + int low = Character.digit(hex[i * 2 + 1], 16); + int value = (high << 4) | low; + if (value > 127) value -= 256; raw[i] = (byte) value; } + return raw; } + + public static byte[] hexToBytes(String hex) { return hexToBytes(hex.toCharArray()); } + + /** + * byte :: ASCII->EBCDIC + */ + public static int ASCIIToEBCDIC(int ascii) { + return AToE[ascii & 0xff] & 0xff; + } + + /** + * byte :: EBCDIC->ASCII + */ + public static int EBCDICToASCII(int ebcdic) { + return EToA[ebcdic & 0xff] & 0xff; + } + + /** + * byte[] :: ASCII->EBCDIC + */ + public static byte[] ASCIIToEBCDIC(byte[] ascii) { + byte[] tobytes = new byte[ascii.length]; + for (int i = 0; i < ascii.length; i++) + tobytes[i] = (byte) ASCIIToEBCDIC(ascii[i]); + return tobytes; + } + + /** + * 直接在原数据上修改 + * byte[] :: ASCII->EBCDIC + */ + public static byte[] ASCIIToEBCDICFIX(byte[] ascii, int from) { + for (int i = from; i < ascii.length; i++) + ascii[i] = (byte) ASCIIToEBCDIC(ascii[i]); + return ascii; + } + + /** + * byte[] :: EBCDIC->ASCII + */ + public static byte[] EBCDICToASCII(byte[] ebcdic) { + byte[] tobytes = new byte[ebcdic.length]; + for (int i = 0; i < ebcdic.length; i++) + tobytes[i] = (byte) EBCDICToASCII(ebcdic[i]); + return tobytes; + } + + /** + * byte[] :: EBCDIC->ASCII + * 直接修改原数据 + */ + public static byte[] EBCDICToASCIIFIX(byte[] ebcdic, int from) { + for (int i = from; i < ebcdic.length; i++) + ebcdic[i] = (byte) EBCDICToASCII(ebcdic[i]); + return ebcdic; + } + + /** + * String :: ASCII->EBCDIC + */ + public static String ASCIIToEBCDIC(String ascii) + throws Exception + { + return new String(ASCIIToEBCDIC(ascii.getBytes("iso-8859-1")), "iso-8859-1"); + } + + /** + * String :: EBCDIC->ASCII + */ + public static String EBCDICToASCII(String ebcdic) + throws Exception + { + return new String(EBCDICToASCII(ebcdic.getBytes("iso-8859-1")),"iso-8859-1"); + } + + /** + * File :: ASCII->EBCDIC + */ + public static void ASCIIToEBCDIC(String fromfile, String tofile) { + try { + FileInputStream in = new FileInputStream(new File(fromfile)); + FileOutputStream out = new FileOutputStream(new File(tofile)); + int tempint, i = 0; + byte[] tempbytes = new byte[in.available()]; + while ((tempint = in.read()) != -1) + tempbytes[i++] = (byte) tempint; + out.write(ASCIIToEBCDIC(tempbytes)); + in.close(); + out.close(); + } catch (Exception e) { + System.out.println(e); + } + } + + /** + * File :: EBCDIC->ASCII + */ + public static void EBCDICToASCII(String fromfile, String tofile) { + try { + FileInputStream in = new FileInputStream(new File(fromfile)); + FileOutputStream out = new FileOutputStream(new File(tofile)); + int tempint, i = 0; + byte[] tempbytes = new byte[in.available()]; + while ((tempint = in.read()) != -1) + tempbytes[i++] = (byte) tempint; + out.write(EBCDICToASCII(tempbytes)); + in.close(); + out.close(); + } catch (Exception e) { + System.out.println(e); + } + } + +} diff --git a/src/main/java/racal/sunyard/main/.gitignore b/src/main/java/racal/sunyard/main/.gitignore new file mode 100644 index 0000000..f51faad --- /dev/null +++ b/src/main/java/racal/sunyard/main/.gitignore @@ -0,0 +1,2 @@ +/proto/ +/script/ diff --git a/src/main/java/racal/sunyard/main/SydApi4j.java b/src/main/java/racal/sunyard/main/SydApi4j.java new file mode 100644 index 0000000..7f1ecb0 --- /dev/null +++ b/src/main/java/racal/sunyard/main/SydApi4j.java @@ -0,0 +1,7188 @@ +package racal.sunyard.main; + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.SydApiException; +import com.sunyard.cert.X509; +import com.sunyard.proto.Packet; +import com.sunyard.proto.PacketSection; +import com.sunyard.proto.Util; +import com.sunyard.proto.section.SectionValue; +import com.sunyard.proto.value.Str; +import com.sunyard.trans.PacketSN; +import com.sunyard.util.CoderUtil; +import com.sunyard.util.SYMUtil; +import racal.sunyard.main.dto.*; +import racal.sunyard.main.proto.*; + +import java.io.*; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketAddress; +import java.net.SocketTimeoutException; +import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.text.SimpleDateFormat; +import java.util.*; + +public class SydApi4j implements SydApi { + + private static boolean debug = false; + + private static long sTime = System.currentTimeMillis(); + + private static String ip1; + private static String ip2; + private static int port; + private static int timeout; + + //初始化变量 + static { + + String d = System.getProperty("com.sunyard.sydapi4j.debug"); + if ("true".equals(d)) { + debug = true; + } + } + + private static void delta() { + long m = System.currentTimeMillis(); + System.out.print("delta \t"); + System.out.println(m - sTime); + sTime = m; + } + + + /** + * 简单双机热备模式 + * + * @param ip1 + * @param ip2 + * @param port + * @param timeout + * @return + */ + public static int SYD_Set_Parameter_HA( + String ip1, + String ip2, + int port, + int timeout + ) { + + SydApi4j.ip1 = ip1; + SydApi4j.ip2 = ip2; + SydApi4j.port = port; + SydApi4j.timeout = timeout; + + return 0; + } + + + public RetWrap SYD_SM2GenKeyPair() { + ProtoQN proto = new ProtoQN(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("sk", "999999999999999999999999999"); + data.put("startTime", "00000000"); + data.put("endTime", "00000000"); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + String pk = ((PacketSection) ret.get("pk")).getString(); + String sk = ((PacketSection) ret.get("sk")).getString(); + + RetWrap r = new RetWrap(); + r.put("publicKey", pk); + r.put("privateKey", sk); + return r; + } + + @Override + public String SYD_SM2_Get_Id_PublicKey_HA( + String pUserID, + int nKeyType + ) { + return SM2GetPublicKeyC(pUserID, nKeyType); + } + + + @Override + public String SYD_SM2_Get_Dn_PublicKey_HA( + byte[] Dn, + int nKeyType + ) { + return GetDNPublicKey(nKeyType, Dn); + } + + + @Override + public String SYD_SM2_Sign_HA( + int nOrgDataType, + byte[] privateKey, + byte[] publicKey, + byte[] orgData) { + + Proto74 proto = new Proto74(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("signatureDataType$option", nOrgDataType); + data.put("userId", "1234567812345678".getBytes()); + + data.put("privateKey", privateKey); + data.put("publicKey", publicKey); + data.put("infoData", orgData); + data.put("privateKeyTag", "999999999999999999999999999"); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + + SectionValue sv = new SectionValue(); + sv.setValue(new byte[]{bb.get(12), bb.get(13)}); + PacketSection error = new PacketSection(sv); + if (0 != error.autoInt()) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + bb.position(14); + byte[] v = new byte[4]; + bb.get(v, 0, v.length); + int a = Util.a2i(v, 10); + byte[] s = new byte[a]; + bb.get(s, 0, a); + + return Util.encodeBase64(s); + } + + + @Override + public String SYD_SM2_Sign_HA( + String pUserID, + int nOrgDataType, + byte[] publicKey, + byte[] orgData + ) { + + if (SydApi.DATA_HASH == nOrgDataType) { + orgData = SM3Hash(Util.bytes2HexString(publicKey), orgData); + } + + //return SM2SignC(pUserID, "1234567812345678", nOrgDataType, publicKey, orgData); + Proto74 proto = new Proto74(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("signatureDataType$option", nOrgDataType); + data.put("userId", "1234567812345678".getBytes()); + data.put("publicKey", publicKey); + data.put("infoData", orgData); + data.put("hashData", orgData); + data.put("privateKeyTag", SYMUtil.genPrivateKeyMark(pUserID, SYMUtil.KT_SIGN, "00000001")); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + //System.out.println(Util.bytes2HexString(Util.toArray(bb))); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + + SectionValue sv = new SectionValue(); + sv.setValue(new byte[]{bb.get(12), bb.get(13)}); + PacketSection error = new PacketSection(sv); + if (0 != error.autoInt()) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + bb.position(14); + byte[] v = new byte[4]; + bb.get(v, 0, v.length); + int a = Util.a2i(v, 10); + byte[] s = new byte[a]; + bb.get(s, 0, a); + + return Util.encodeBase64(s); + } + + @Override + public byte[] transPinFrOneKeyToAno(String srcKey, String desKey, int sca, String sPin, String primaryAccount) { + ProtoCB proto = new ProtoCB(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("srcKeyType", "00A"); + data.put("desKeyType", "00A"); + //srcKey = "XK" + srcKey; + data.put("srcKey", srcKey); + data.put("desKey", desKey); + data.put("algorithmKey", 'P'); + // 协议 1 2 对应 0 1 + data.put("dca$option", 1); + data.put("sca$option", sca - 1); + data.put("sPin", sPin); + data.put("sPinType$option", 0); + data.put("dPinType$option", 0); + data.put("primaryAccount", primaryAccount); + data.put("businessKey", 'N'); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + + byte[] pinBlock = ((PacketSection) ret.get("dPin")).getBytes(); + return pinBlock; + } + } + } + + /** + * 工银定制版本 + */ + private SydApiBuilder builder; + + protected void keepBuilder(SydApiBuilder builder) { + this.builder = builder; + } + + @Override + public boolean SYD_SM2_Verify_HA( + int nOrgDataType, + byte[] publicKey, + byte[] orgData, + String base64Sign + ) { + //return SM2Verify( "1234567812345678", nOrgDataType, publicKey, orgData, base64Sign); +// if (certNo.length() > 32) { +// certNo = certNo.substring(0, 32); +// } + if (SydApi.DATA_HASH == nOrgDataType) { + orgData = SM3Hash(Util.bytes2HexString(publicKey), orgData); + } + + String certNo = "1234567812345678"; + //ProtocolRender render = pset.getProtocolReqRender("75"); + Proto75 proto = new Proto75(); + + byte[] sign = Util.decodeBase64(base64Sign); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("signatureDataType$option", nOrgDataType); + data.put("signature", sign); + data.put("userId", certNo.getBytes()); + data.put("infoData", orgData); + data.put("hashData", orgData); + data.put("publicKey", publicKey); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + //System.out.println(Util.bytes2HexString(Util.toArray(bb))); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + bb.position(12); + byte[] v = new byte[2]; + bb.get(v, 0, v.length); + String a = Util.bytes2HexString(v); + if ("3030".equals(a)) { + return true; + } else { + return false; + } + } + + + @Override + public byte[] SYD_NakedSign(byte[] orgData, String sCertDN) { + Proto8003 proto = new Proto8003(); //pset.getProtocolReqRender("75"); + byte[] dn = new byte[256]; + byte[] s = null; + try { + s = sCertDN.getBytes("GBK"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + System.arraycopy(s, 0, dn, 0, s.length); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("signatureDataType$option", 1); + data.put("DN", dn); + data.put("data", orgData); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + + throw new SydApiException(error.getInfo(), error.autoInt()); + } + return ((PacketSection) ret.get("signature")).getBytes(); + } + + + @Override + public boolean SYD_NakedVerify(byte[] orgData, byte[] sign, String sCertDN) { + Proto8004 proto = new Proto8004(); //pset.getProtocolReqRender("75"); + + byte[] dn = new byte[256]; + byte[] s = null; + + try { + s = sCertDN.getBytes("GBK"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + System.arraycopy(s, 0, dn, 0, s.length); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("signatureDataType$option", 1); + data.put("DN", dn); + data.put("data", orgData); + data.put("signature", sign); + data.put("returnSign$option", 0); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + byte[] b = syncSend(bb); + + // 响应解析 + bb = syncRead(b); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ((0 != (be[0] ^ be[1]))) { + + return false; + } + return true; + } + + + @Override + public String sm3AndDetachedSign(byte[] orgData, String publicKey, String sCertDN) { + + byte[] hash = SM3Hash(publicKey, orgData); + return detachedSign(DATA_HASH, hash, sCertDN); + + } + + @Override + public RetWrap genComposeKey(String[] keys) { + + ProtoGY proto = new ProtoGY(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + int len = 0; + for (String key : keys) { + len += key.length(); + } + len = len / 2; + + byte[] ks = new byte[len]; + len = 0; + for (String key : keys) { + byte[] bs = Util.hexString2Bytes(key); + System.arraycopy(bs, 0, ks, len, bs.length); + len += bs.length; + } + + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("num", keys.length); + data.put("keys", ks); + data.put("flag", 'N'); + + data.put("split", ";"); + data.put("zmk", "Z"); + data.put("lmk", "Z"); + data.put("kcvType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + byte[] lmks = ((PacketSection) ret.get("key")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("keyHead")).getBytes(); + byte[] bs = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs, lmkHeads.length, lmks.length); + retWrap.put("lmkKey", bs); + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + + } + + + public RetWrap genComposeKey(String keyType, char keySolution, String keyClearPattern) { + + ProtoAA proto = new ProtoAA(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("businessKey", 'N'); + data.put("keySolution", keySolution); + data.put("keyClearPattern", keyClearPattern); + data.put("keyType", keyType); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap rw = new RetWrap(); + byte[] lmks = ((PacketSection) ret.get("lmk")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("lmkHead")).getBytes(); + byte[] bs = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs, lmkHeads.length, lmks.length); + rw.put("lmkKey", bs); + rw.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return rw; + } + } + + } + + @Override + public boolean sm3AndDetachedVerify(byte[] orgData, String publicKey, String sign) { + byte[] hash = SM3Hash(publicKey, orgData); + return detachedVerify(DATA_HASH, hash, sign); + } + + @Override + public String detachedSign(int dataType, byte[] orgData, String sCertDN) { + Proto8005 proto = new Proto8005(); //pset.getProtocolReqRender("75"); + byte[] dn = new byte[256]; + byte[] s = null; + try { + s = sCertDN.getBytes("GBK"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + System.arraycopy(s, 0, dn, 0, s.length); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("DN", dn); + if (dataType == DATA_HASH) { + data.put("hashFlag", 'P'); + data.put("hash", orgData); + } else { + data.put("infoData", orgData); + } + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("signature")).getString(); + + } + + @Override + public boolean detachedVerify(int dataType, byte[] orgData, String sign) { + Proto8006 proto = new Proto8006(); //pset.getProtocolReqRender("75"); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + if (dataType == DATA_HASH) { + data.put("hashFlag", 'P'); + data.put("hash", orgData); + } else { + data.put("originData", orgData); + } + + + data.put("signData", sign.getBytes()); + data.put("flag$option", 0); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ((0 != (be[0] ^ be[1]))) { + + return false; + } + return true; + } + + + @Override + public boolean detachedVerify(int dataType, byte[] orgData, byte[] sign) { + Proto8025 proto = new Proto8025(); //pset.getProtocolReqRender("75"); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + if (dataType == DATA_HASH) { + data.put("hashFlag", 'P'); + data.put("hash", orgData); + } else { + data.put("originData", orgData); + } + + data.put("signData", sign); + data.put("flag$option", 0); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ((0 != (be[0] ^ be[1]))) { + + return false; + } + return true; + } + + @Override + public String SYD_SM2_DetachedSign_HA( + byte[] orgData, + String sCertDN + ) { + return detachedSign(DATA_ORIGIN, orgData, sCertDN); + } + + + @Override + public boolean SYD_SM2_DetachedVerify_HA( + byte[] orgData, + String sign) { + + return detachedVerify(DATA_ORIGIN, orgData, sign); + } + + + @Override + public boolean SYD_DetachedVerify(byte[] orgData, String sign) { + return SYD_SM2_DetachedVerify_HA(orgData, sign); + } + + @Override + public String SYD_DetachedSign(byte[] orgData, String sCertDN) { + return SYD_SM2_DetachedSign_HA(orgData, sCertDN); + } + + @Override + public X509 SYD_Get_X509_CertInfo_HA( + byte[] orgData, + String sign + ) { + + Proto8012 proto = new Proto8012(); //pset.getProtocolReqRender("75"); + + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("originData", orgData); + data.put("signData", sign.getBytes()); + data.put("flag$option", 1); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ((0 != (be[0] ^ be[1]))) { + + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + PacketSection info = (PacketSection) ret.get("info"); + + byte[] pCertInfo = info.getBytes(); +// X509 cinfo = new X509(); +// cinfo.setIssuer(Util.toCleanString(pCertInfo, 0, 257)); +// cinfo.setSerialNumber(Util.toCleanString(pCertInfo, 257, 65)); +// cinfo.setSubject(Util.toCleanString(pCertInfo, 257 + 65, 257)); +// cinfo.setNotBefore(Util.toCleanString(pCertInfo, 257 + 65 + 257, 15)); +// cinfo.setNotAfter(Util.toCleanString(pCertInfo, 257 + 65 + 257 + 15, 15)); +// byte[] blen = new byte[]{pCertInfo[257 + 65 + 257 + 15 + 15], pCertInfo[257 + 65 + 257 + 15 + 16]}; +// int len = Util.b2i(blen); +// byte[] pem = new byte[len]; +// System.arraycopy(pCertInfo, 257 + 65 + 257 + 15 + 17, pem, 0, len); +// String pp = new String(pem); + // 解析证书 + return GetX509CertInfo(new String(pCertInfo)); + } + + + public SydApi4j() { +// if (null == pset) { +// synchronized (SydApi4j.class) { +// if (null == pset) { +// loader = new ResourceLoader("^packet.racal.sunyard.*"); +// pset = new ProtocolSet(loader); +// } +// } +// } + } + + private Socket socket; + + +// /** +// * 不同的模式返回不同的 socket +// */ +// private Socket getSocket() { +// if ( null != pool ){ +// +// return pool.get().getOrigin().socket; +// +// }else { +// // 普通模式和全局热备模式 +// return socket; +// } +// } + + + private static void println(Object i) { + if (debug) { + System.out.println(i); + } + + } + + private static void print(Object i) { + if (debug) { + System.out.print(i); + } + + } + + /** + * 确认链接可用 + * 确认读缓存为空 + */ + private void testSocket() { + + // 就是简单对象模式,链接长短完全由用户自己控制 + if (null == socket) { + + // 全局热备模式(old shool) + if (null != ip2) { + + Socket s1 = new Socket(); + SocketAddress address = new InetSocketAddress(ip1, port); + + try { + s1.connect(address, timeout); + socket = s1; + socket.setSoTimeout(timeout); + } catch (Exception e) { + Socket s2 = new Socket(); + SocketAddress add2 = new InetSocketAddress(ip2, port); + try { + s2.connect(add2, timeout); + socket = s2; + socket.setSoTimeout(timeout); + } catch (Exception e2) { + throw new SydApiException(-2); + } + } + + } + } + + clear(); + + } + + protected byte[] syncSend(ByteBuffer bb) { + + + byte[] buff; + if (bb.position() == bb.limit()) { + buff = bb.array(); + } else { + buff = new byte[bb.position()]; + System.arraycopy(bb.array(), 0, buff, 0, buff.length); + } + + + println("\n\n发送数据"); +// print("原始数据: \t"); +// println(Arrays.toString(buff)); + print("HEX数据: \t"); + println(Util.bytes2HexString(buff)); + + if (null != builder && builder.isUseEBCDMode()) { + // 对十个字节之后的进行 EBCD 转码 + buff = CoderUtil.ASCIIToEBCDICFIX(buff, 10); + print("EBCD 数据: \t"); + println(Util.bytes2HexString(buff)); + } + + testSocket(); + + try { + socket.getOutputStream().write(buff); + } catch (IOException e) { + e.printStackTrace(); + } + + return buff; + } + + /** + * 开放此接口 + * + * @param buff + */ + public void syncSend(byte[] buff) { + + println("\n\n (补发) 发送数据"); + print("原始数据: \t"); + println(Arrays.toString(buff)); + print("HEX数据: \t"); + println(Util.bytes2HexString(buff)); + + testSocket(); + + try { + socket.getOutputStream().write(buff); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + private void clear() { + try { + InputStream is = socket.getInputStream(); + while (is.available() > 0) { + is.read(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private boolean hasData() { + try { + return socket.getInputStream().available() > 0; + } catch (IOException e) { + e.printStackTrace(); + } + return false; + } + + private ByteBuffer read(Socket socket) throws IOException { + InputStream is = socket.getInputStream(); + int d; + int high = is.read(); + int low = is.read(); + int len = (high << 8) + low; + + len += 2; + + print("H\t"); + println(Integer.toHexString(high)); + print("L\t"); + println(Integer.toHexString(low)); + print("Len\t"); + println(len); + + + ByteBuffer bb = ByteBuffer.allocate(len); + bb.put((byte) (high & 0xFF)); + //println(String.format("%d %d %s",len, bb.position() -1, Util.bytes2HexString(new byte[]{(byte) (high & 0xFF)}))); + + bb.put((byte) (low & 0xFF)); + //println(String.format("%d %d %s",len, bb.position() -1, Util.bytes2HexString(new byte[]{(byte) (low & 0xFF)}))); + + + while (true) { + d = is.read(); + if (-1 == d) { + break; + } + + bb.put((byte) (d & 0xFF)); + + //println(String.format("%d %d %s",len, bb.position() -1, Util.bytes2HexString(new byte[]{(byte) (d & 0xFF)}))); + + if (bb.position() == len) { + break; + } + } + + + if (null != builder && builder.isUseEBCDMode()) { + print("EBCD 数据: \t"); + println(Util.bytes2HexString(bb.array())); + + byte[] b = bb.array(); + CoderUtil.EBCDICToASCIIFIX(b, 10); + } + + print("HEX数据: \t"); + println(Util.bytes2HexString(bb.array())); + return bb; + } + + /** + * 阻塞读取 + * 前两个字节是长度 + * + * @return + * @buffer 如果出错,需要补发的数据。 + */ + protected ByteBuffer syncRead(byte[] buffer) { + println("\n\n接收数据"); + try { + // 正常接收 + ByteBuffer bb = read(socket); + return bb; + + } catch (SocketTimeoutException e) { + throw new SydApiException("接收数据超时", -2); + } catch (Exception e) { + e.printStackTrace(); + } + + throw new SydApiException("通信数据错误", -3); + } + + @Override + synchronized public SydApi connect(String ip, int port, String pwd, int timeout) { + + if (null != ip2) { + throw new SydApiException("双机热备模式不用调用此方法", -1); + } + Socket socket = new Socket(); + SocketAddress address = new InetSocketAddress(ip, port); + + try { + if (timeout > 0) { + socket.connect(address, timeout); + } else { + socket.connect(address); + } + socket.setSoTimeout(timeout); + } catch (Exception e) { + throw new SydApiException(-2); + } + + + this.socket = socket; + return this; + } + + @Override + synchronized public SydApi connect(String ip, int port, String pwd, int connectTimeout, int readTimeout) { + + if (null != ip2) { + throw new SydApiException("双机热备模式不用调用此方法", -1); + } + Socket socket = new Socket(); + SocketAddress address = new InetSocketAddress(ip, port); + + try { + socket.connect(address, connectTimeout); + socket.setSoTimeout(readTimeout); + } catch (Exception e) { + throw new SydApiException(-2); + } + + + this.socket = socket; + return this; + } + + @Override + synchronized public int disconnect() { + + if (null != socket) { + try { + socket.getInputStream().close(); + } catch (Exception e1) { + } + + + try { + socket.getOutputStream().close(); + } catch (Exception e2) { + } + + + try { + socket.close(); + } catch (Exception e) { + } + + } + + return 0; + } + + @Override + public void free() { + throw new RuntimeException("不要在非集群下调用此接口"); + } + + @Override + public void error() { + throw new RuntimeException("不要在非集群下调用此接口"); + } + + + private byte[] repackEncrypt(HashMap packet) { + + HashMap data = (HashMap) packet.get("data"); + int v = ((byte[]) data.get("msg")).length; + final ByteBuffer bbs = ByteBuffer.allocate(v + 1024); + + repack("E0", 2048, packet, new PackCallBack() { + + @Override + public void circle(int packSn, HashMap packet, Map ret) { + bbs.put(((PacketSection) ret.get("msg")).getBytes()); + } + }); + + return Util.toArray(bbs); + } + + private byte[] repackHash(HashMap packet) { + + HashMap data = (HashMap) packet.get("data"); + int v = ((byte[]) data.get("msg")).length; + final ByteBuffer bbs = ByteBuffer.allocate(v + 1024); + final byte[][] hash = new byte[1][0]; + + + repack("76", 2048, packet, new PackCallBack() { + + @Override + public void circle(int packNo, HashMap packet, Map ret) { + if (0 == packNo || 3 == packNo) { + hash[0] = ((PacketSection) ret.get("hash")).getBytes(); + } else { + byte[] filterData = ((PacketSection) ret.get("filterData")).getBytes(); + HashMap data = (HashMap) packet.get("data"); + data.put("filterData", filterData); + } + } + }); + + return hash[0]; + } + + /** + * 分包发送接收 + * + * @param packSize + */ + private void repack(String cmd, int packSize, HashMap packet, PackCallBack cb) { + HashMap data = (HashMap) packet.get("data"); + int v = ((byte[]) data.get("msg")).length; + int loop = v / packSize; + int tailLen = v % packSize; + if (tailLen > 0) { + loop++; + } else { + tailLen = packSize; + } + byte[] msgAll = (byte[]) (data.get("msg")); + + + + // 大包分包 + int block = 0; + if ( data.containsKey("block") ){ + block = (Integer) data.get("block"); + } + + // 什么情况下不传 iv ? + // ecb 模式的 唯一包/首包 不传 iv + // 其他模式 所有包都传 iv + // 全都传了,也没问题,没有就传全零 + // 这个值暂时不用 + int roundModel = (Integer) data.get("roundModel$option"); + boolean hasIV = true; + if ( 0 == roundModel && (block == 0 || block == 1) ){ + hasIV = false; + } + + + /** + * 初始值,仅当密钥加密模式为2,3,4时有此域。 + * 当密钥模式为 0,1时,该域为16H + * 当密钥模式为 2,3,4,5,6,7时,该域为32H + */ + int alg = (Integer) data.get("alg$option"); + int ivlen = (0 == alg || 1 == alg) ? 16 : 32; + byte[] iv = (byte[]) data.get("iv"); + if( null == iv ){ + iv = new byte[ivlen]; + Arrays.fill(iv, (byte) 0x30); + } + data.put("iv", iv); + + // 获取协议 + synchronized (this) { + int packNo = 0; + for (int i = 0; i < loop; i++) { + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + // 如果大包是唯一包 0 , 逻辑不变 + // 如果大包是首包 1,则尾包不是尾包 + // 如果大包是中间包 2,则全部是中间包 + // 如果大包是尾包 3,则没有首包。 + if (0 == i) { + if (1 == loop) { + // 唯一包 + // [如果大包是中间包 2,则全部是中间包] + packNo = 0; + if( 2 == block){ + packNo = 2; + } + + data.put("packSn$option", packNo); + data.put("msg", msgAll); + println("\n\t唯一包"); + } else { + // 首包 + packNo = 1; + // [如果大包是尾包 3,则没有首包] + if ( 3 == block ){ + packNo = 3; + } + + // [如果大包是中间包 2,则全部是中间包] + if( 2 == block){ + packNo = 2; + } + data.put("packSn$option", packNo); + byte[] msg = new byte[packSize]; + System.arraycopy(msgAll, 0, msg, 0, packSize); + println("\n\t首包"); + data.put("msg", msg); + } + } else { + + if ( null != iv ) { + data.put("iv", iv); + iv = null; + } + + if (i == (loop - 1)) { + // 尾包 + packNo = 3; + // [如果大包是首包 1,则尾包不是尾包] + if ( 1 == block ){ + packNo = 2; + } + // [如果大包是中间包 2,则全部是中间包] + if( 2 == block){ + packNo = 2; + } + data.put("packSn$option", packNo); + byte[] msg = new byte[tailLen]; + System.arraycopy(msgAll, i * packSize, msg, 0, tailLen); + println("\n\t尾包"); + data.put("msg", msg); + } else { + // 中间包 + packNo = 2; + data.put("packSn$option", 2); + byte[] msg = new byte[packSize]; + System.arraycopy(msgAll, i * packSize, msg, 0, packSize); + println("\n\t中间包"); + data.put("msg", msg); + } + } + + // 渲染发送 + + ProtoE0 proto = new ProtoE0(); + + ByteBuffer bb = proto.rend(packet); + + if (null != builder && builder.isUseETEncrypt()) { + bb.put(11, (byte) 'T'); + } + + + bb = syncRead(syncSend(bb)); + + + Packet p = proto.parse(bb, packet); + + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + + + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + // 对 iv 进行处理 + //if (hasIV) { + // 只处理首包和中间包 + if (1 == packNo || 2 == packNo) { + byte[] niv = ((PacketSection) ret.get("iv")).getBytes(); + println("\n\t IV=" + Util.bytes2HexString(niv)); + iv = niv; + } + //} + + cb.circle(packNo, packet, ret); + } + } + } + + + @Override + public boolean SYMDecryptDataWithFile(int nAlg, String seesionKey, String inputPath, String outputPath) { + + if (2 == nAlg && 'L' != seesionKey.charAt(0)) { + throw new SydApiException(-27); + } + + int packSize = 8000; + int readSize = 8000; + + // 获取文件长度 + int lenIndata = 0; + File file = new File(inputPath); + if (file.exists() && file.isFile()) { + lenIndata = (int) file.length(); + } else { + return false; + } + +// try { +// lenIndata = getInDataLen(inputPath); +// } catch (Exception e) +// { +// System.out.println("[ERROR]: " + e.getMessage()); +// e.printStackTrace(); +// } + + int loop = lenIndata / packSize; + int tailLen = lenIndata % packSize; + if (tailLen > 0) { + loop++; + } else { + tailLen = packSize; + } + + FileInputStream fileInputStream = null; + FileOutputStream fileOutputStream = null; + try { + + fileInputStream = new FileInputStream(inputPath); + File outFile = new File(outputPath); + //清空文件 + try { + if (!outFile.exists()) { + outFile.createNewFile(); + } + FileWriter fileWriter = new FileWriter(outFile); + fileWriter.write(""); + fileWriter.flush(); + fileWriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + fileOutputStream = new FileOutputStream(outputPath, true); + + for (int i = 0; i < loop; i++) { + + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + switch (nAlg) { + case 0: + data.put("alg$option", 0x1); + break; + case 2: + data.put("alg$option", 0xD); + break; + default: + data.put("alg$option", 0x9); + } + + + if (0 == i) { + if (1 == loop) { + // 唯一包 + data.put("packSn$option", 0); + readSize = lenIndata; + byte[] msg = new byte[readSize]; + fileInputStream.read(msg); + data.put("msg", msg); + println("\n\t唯一包"); + } else { + // 首包 + data.put("packSn$option", 1); + readSize = packSize; + byte[] msg = new byte[readSize]; + fileInputStream.read(msg); + println("\n\t首包"); + data.put("msg", msg); + } + } else { + if (i == (loop - 1)) { + // 尾包 + data.put("packSn$option", 3); + readSize = tailLen; + byte[] msg = new byte[readSize]; + fileInputStream.read(msg); + println("\n\t尾包"); + data.put("msg", msg); + } else { + // 中间包 + data.put("packSn$option", 2); + readSize = packSize; + byte[] msg = new byte[readSize]; + fileInputStream.read(msg); + println("\n\t中间包"); + data.put("msg", msg); + } + } + data.put("roundModel$option", 0); + data.put("keyType$option", 0); + data.put("key", seesionKey.getBytes()); + data.put("inType$option", 0); + data.put("outType$option", 0); + data.put("fullMode$option", 1); + data.put("fullChar$option", 0); + data.put("fullType$option", 2); +// data.put("msg", pInData); + packet.put("data", data); + + // 渲染发送 + ProtoE1 proto = new ProtoE1(); + ByteBuffer bb = proto.rend(packet); + bb = syncRead(syncSend(bb)); + Packet p = proto.parse(bb); + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + byte[] encryptPacket = ((PacketSection) ret.get("msg")).getBytes(); + fileOutputStream.write(encryptPacket); + } + + } + + } catch (SydApiException e1) { + throw e1; + } catch (Exception e) { + println("[ERROR]: " + e.getMessage()); + e.printStackTrace(); + throw new SydApiException(e.getMessage(), 65535); + } finally { + if (null != fileInputStream) { + try { + fileInputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + if (null != fileOutputStream) { + try { + fileOutputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + return true; + } + + @Override + public byte[] SYMEncryptData(int nAlg, String seesionKey, byte[] pInData) { + return SYMEncryptData(nAlg, seesionKey, 1, pInData); + } + + + /** + * E0 指令复合接口 + * @param isEn + * @param nAlg + * @param seesionKey + * @param roundmod + * @param fullMode + * @param pInData + * @param iv + * @return + */ + public byte[] SYMEnDeData(Boolean isEn, int nAlg, String seesionKey, int roundmod, int fullMode, byte[] pInData, byte[] iv, int block) { + + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + // 确认算法 + if ( isEn ){ + switch (nAlg) { + case 0: + data.put("alg$option", 0x0); + break; + case 2: + data.put("alg$option", 0xC); + break; + default: + data.put("alg$option", 0x8); + } + } else { + switch (nAlg) { + case 0: + data.put("alg$option", 0x1); + break; + case 2: + data.put("alg$option", 0xD); + break; + default: + data.put("alg$option", 0x9); + } + } + + // 确认 roundmod + data.put("roundModel$option", roundmod); + + // 确认 iv + data.put("iv", iv); + data.put("block", block); + + + data.put("keyType$option", 0); + data.put("key", seesionKey.getBytes()); + data.put("inType$option", 0); + data.put("outType$option", 0); + data.put("fullMode$option", fullMode); + data.put("fullChar$option", 0); + data.put("fullType$option", 0 == fullMode ? 0 : 2); + data.put("msg", pInData); + packet.put("data", data); + + return repackEncrypt(packet); + } + + + @Override + public byte[] SYMEncryptData(int nAlg, String seesionKey, int fullMode, byte[] pInData) { + + if (2 == nAlg && 'L' != seesionKey.charAt(0)) { + throw new SydApiException(-27); + } + + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + switch (nAlg) { + case 0: + data.put("alg$option", 0x0); + break; + case 2: + data.put("alg$option", 0xC); + break; + default: + data.put("alg$option", 0x8); + } + + + data.put("roundModel$option", 0); + data.put("keyType$option", 0); + data.put("key", seesionKey.getBytes()); + data.put("inType$option", 0); + data.put("outType$option", 0); + data.put("fullMode$option", fullMode); + data.put("fullChar$option", 0); + data.put("fullType$option", 0 == fullMode ? 0 : 2); + data.put("msg", pInData); + packet.put("data", data); + + return repackEncrypt(packet); + } + + + public byte[] SYMEncryptData_nofill(int nAlg, String seesionKey, byte[] pInData) { + + if (2 == nAlg && 'L' != seesionKey.charAt(0)) { + throw new SydApiException(-27); + } + + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + switch (nAlg) { + case 0: + data.put("alg$option", 0x0); + break; + case 2: + data.put("alg$option", 0xC); + break; + default: + data.put("alg$option", 0x8); + } + + + data.put("roundModel$option", 0); + data.put("keyType$option", 0); + data.put("key", seesionKey.getBytes()); + data.put("inType$option", 0); + data.put("outType$option", 0); + data.put("fullMode$option", 0); + data.put("fullChar$option", 0); + data.put("fullType$option", 0); + data.put("msg", pInData); + packet.put("data", data); + + return repackEncrypt(packet); + } + + @Override + public byte[] SYMDecryptData_nofill(int nAlg, String seesionKey, byte[] pInData) { + + if (2 == nAlg && 'L' != seesionKey.charAt(0)) { + throw new SydApiException(-27); + } + + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + switch (nAlg) { + case 0: + data.put("alg$option", 0x1); + break; + case 2: + data.put("alg$option", 0xD); + break; + default: + data.put("alg$option", 0x9); + } + + + data.put("roundModel$option", 0); + data.put("keyType$option", 0); + data.put("key", seesionKey.getBytes()); + data.put("inType$option", 0); + data.put("outType$option", 0); + data.put("fullMode$option", 0); + data.put("fullChar$option", 0); + data.put("fullType$option", 0); + data.put("msg", pInData); + packet.put("data", data); + + return repackEncrypt(packet); + } + + + @Override + public byte[] SYMDecryptData(int nAlg, String seesionKey, byte[] pInData) { + return SYMDecryptData(nAlg, seesionKey, 1, pInData); + } + + @Override + public byte[] SYMDecryptData(int nAlg, String seesionKey, int fullmode, byte[] pInData) { + if (2 == nAlg && 'L' != seesionKey.charAt(0)) { + throw new SydApiException(-27); + } + + + // 获取协议 + //ProtocolRender render = pset.getProtocolReqRender("E0"); + + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + switch (nAlg) { + case 0: + data.put("alg$option", 0x1); + break; + case 2: + data.put("alg$option", 0xD); + break; + default: + data.put("alg$option", 0x9); + } + + + data.put("roundModel$option", 0); + data.put("keyType$option", 0); + data.put("key", seesionKey.getBytes()); + data.put("inType$option", 0); + data.put("outType$option", 0); + data.put("fullMode$option", fullmode); + data.put("fullChar$option", 0); + data.put("fullType$option", 0 == fullmode ? 0 : 2); + data.put("msg", pInData); + packet.put("data", data); + + + return repackEncrypt(packet); + } + + + @Override + public RetWrap generateDE(String certSerial, byte nAlg) { + // 获取协议 + //ProtocolRender render = pset.getProtocolReqRender("6A"); + Proto6A proto = new Proto6A(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + data.put("alg$option", nAlg - 0x30); + data.put("certificateModel$option", 0); + data.put("certificateSn", certSerial); + data.put("keyType", "X"); + packet.put("data", data); + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + rw.put(SydApi.RET_CIPHER_KEY, ((PacketSection) ret.get("key")).getString()); + rw.put(SydApi.RET_SESSION_KEY, ((PacketSection) ret.get("lmkHead")).getString() + + ((PacketSection) ret.get("lmk")).getString() + ); + + rw.put(SydApi.RET_KCV, ((PacketSection) ret.get("keyCheck")).getString()); + + return rw; + } + + @Override + public RetWrap decryptDE(String certSerial, String pCipherKey) { + // 获取协议 + //ProtocolRender render = pset.getProtocolReqRender("6B"); + Proto6B proto = new Proto6B(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + data.put("certificateModel$option", 0); + data.put("certificateSn", certSerial); + data.put("key", pCipherKey); + data.put("keyType", "X"); + packet.put("data", data); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + + rw.put(SydApi.RET_SESSION_KEY, ((PacketSection) ret.get("lmkHead")).getString() + + ((PacketSection) ret.get("lmk")).getString() + ); + + rw.put(SydApi.RET_KCV, ((PacketSection) ret.get("keyCheck")).getString()); + + return rw; + } + + @Override + public String GenerateRandom(int nRandomSize) { + //获取协议 + ProtoY8 proto = new ProtoY8(); + + //填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + data.put("nRandomSize", nRandomSize); + packet.put("data", data); + + //渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + //解析响应 + bb = syncRead(syncSend(bb)); + } + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + return ((PacketSection) ret.get("random")).getString(); + } + + @Override + public String netSign(String pCertSerial, byte[] pOrgData) { + + + // 获取协议 + //ProtocolRender render = pset.getProtocolReqRender("6C"); + Proto6C proto = new Proto6C(); + + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + data.put("certificateModel$option", 0); + data.put("certificateSn", pCertSerial); + data.put("inData", pOrgData); + packet.put("data", data); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("sign")).getString(); + } + + @Override + public boolean netVerify(String pCertSerial, byte[] pOrgData, String pSignData) { + // 获取协议 + //ProtocolRender render = pset.getProtocolReqRender("6D"); + Proto6D proto = new Proto6D(); + + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + data.put("certificateModel$option", 0); + data.put("certificateSn", pCertSerial); + data.put("inData", pOrgData); + data.put("sign", pSignData); + packet.put("data", data); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return true; + } + + + @Override + public String getX509SN(int nCertType, byte[] certDN) { + // 获取协议 + //ProtocolRender render = pset.getProtocolReqRender("6E"); + Proto6E proto = new Proto6E(); + + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + data.put("certificateModel$option", nCertType >= 0x30 ? nCertType - 0x30 : nCertType); + data.put("certificateDn", certDN); + packet.put("data", data); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("sn")).getString(); + } + + @Override + public RetWrap SM2GenKeyPair() { + //ProtocolRender render = pset.getProtocolReqRender("E2"); + ProtoE2 proto = new ProtoE2(); + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("algorithmId$option", 0x1); + data.put("keyLength", 256); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + + //ProtocolParser parser = pset.getProtocolResParse(); + + Map ret = null; + Packet p = proto.parse(bb); + ret = p.toMap(); + + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + + rw.put(SydApi.RET_PUBLIC_KEY, ((PacketSection) ret.get("publicKey")).getBytes()); + + rw.put(SydApi.RET_PRIVATE_KEY, ((PacketSection) ret.get("privateKey")).getBytes()); + + return rw; + + + } + + @Override + public RetWrap SM3Hash(int packSn, String userId, byte[] publicKey, byte[] msg, byte[] filterData) { + Proto76 proto = new Proto76(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("packSn$option", packSn); + data.put("msg", msg); + data.put("userId", userId.getBytes()); + data.put("publicKey", publicKey); + data.put("filterData", filterData); + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap rw = new RetWrap(); + if (packSn == 1 || packSn == 2) { + rw.put("filterData", ((PacketSection) ret.get("filterData")).getBytes()); + } else { + rw.put("hash", ((PacketSection) ret.get("hash")).getBytes()); + } + return rw; + } + } + } + + @Override + public RetWrap SM2OrRSAGenKeyPair(int keyType, String index, int length) { + + System.out.println( getClass().getClassLoader().hashCode() ); + + ProtoE2 proto = new ProtoE2(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + int keyLength = -1; + if (keyType == 0) { + keyLength = length; + } else if (keyType == 1) { + keyLength = 256; + } + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + String date = sdf.format(new Date()); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("algorithmId$option", keyType); + data.put("keyLength", keyLength); + //data.put("flag", "P"); + data.put("index", SYMUtil.genPrivateKeyMark(index, "000", "00000001")); + data.put("startTime", date); + data.put("endTime", date); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap rw = new RetWrap(); + rw.put("PublicKey", ((PacketSection) ret.get("publicKey")).getBytes()); + rw.put("PrivateKey", ((PacketSection) ret.get("privateKey")).getBytes()); + return rw; + } + } + } + + + public boolean RSAVerify(int HashMark, int nOrgDataType, byte[] publickey, byte[] orgData, byte[] base64Sign) { + + Proto7C proto = new Proto7C(); + byte[] sign = base64Sign; + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("signatureDataType$option", nOrgDataType); + data.put("hashMark$option", HashMark); + data.put("signature", sign); + data.put("hashData", orgData); + data.put("publicKey", publickey); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if ("02".equals(error.getString())) { + return false; + } else if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + return true; + } + } + } + + public byte[] RSASignC(String privateKeyIndex, int HashMark, int nOrgDataType, byte[] orgData) { + Proto7B proto = new Proto7B(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("signatureDataType$option", nOrgDataType); + data.put("hashMark$option", HashMark); + data.put("infoData", orgData); + data.put("hashData", orgData); + data.put("privateKeyTag", SYMUtil.genPrivateKeyMark(privateKeyIndex, "000", "00000001")); + + + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + SectionValue sv = new SectionValue(); + sv.setValue(new byte[]{bb.get(12), bb.get(13)}); + PacketSection error = new PacketSection(sv); + if (0 != error.autoInt()) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + bb.position(14); + byte[] v = new byte[4]; + bb.get(v, 0, v.length); + int a = Util.a2i(v, 10); + byte[] s = new byte[a]; + bb.get(s, 0, a); + + return s; + } + } + + @Override + public byte[] RSASign(String privateKey, int HashMark, int nOrgDataType, byte[] orgData) { + return new byte[0]; + } + + @Override + public RetWrap genSymmetricKey(String keyType, char solution) { + ProtoA0 proto = new ProtoA0(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("mode$option", 0); + data.put("keyType", keyType); + data.put("solution", solution); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap rw = new RetWrap(); + byte[] lmks = ((PacketSection) ret.get("lmk")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("lmkHead")).getBytes(); + byte[] bs= new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs, lmkHeads.length, lmks.length); + rw.put("lmkKey", bs); + rw.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return rw; + } + } + } + + + @Override + public String SM2GetPublicKeyC(String userId, int nKeyType) { + + //ProtocolRender render = pset.getProtocolReqRender("QQ"); + ProtoQQ proto = new ProtoQQ(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("privateKeyTag", SYMUtil.genPrivateKeyMark(userId, 0 == nKeyType ? "000" : "001", "00000001")); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + //System.out.println(Util.bytes2HexString(Util.toArray(bb))); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + int len = Integer.parseInt(((PacketSection) ret.get("publicLen")).getString()); + if (len == 128) { + return "03420004" + ((PacketSection) ret.get("publicKey")).getString(); + } + + return ((PacketSection) ret.get("publicKey")).getString(); + } + + public String SM2GetPublicKeyC_QX(int userId, int nKeyType) { + + //ProtocolRender render = pset.getProtocolReqRender("QQ"); + ProtoQX proto = new ProtoQX(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + byte[] privateKeyTag = {(new Integer(userId / 256 / 256 / 256)).byteValue(), + (new Integer(userId / 256 / 256)).byteValue(), + (new Integer(userId / 256)).byteValue(), + (new Integer(userId)).byteValue()}; + + data.put("privateKeyTag", privateKeyTag); +// data.put("privateKeyTag", SYMUtil.genPrivateKeyMark(userId, 0 == nKeyType ? "000" : "001", "00000001")); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + //System.out.println(Util.bytes2HexString(Util.toArray(bb))); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + int len = Integer.parseInt(((PacketSection) ret.get("publicLen")).getString()); + if (len == 128) { + return "03420004" + ((PacketSection) ret.get("publicKey")).getString(); + } + + return ((PacketSection) ret.get("publicKey")).getString(); + } + + @Override + public X509 GetX509CertInfo(String pCert) { + + //ProtocolRender render = pset.getProtocolReqRender(new byte[]{(byte) 0x80, 0x16}); + Proto8016 proto = new Proto8016(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("cert", Util.getSafeBytes(pCert)); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + SectionValue sv = new SectionValue(); + sv.setValue(new byte[]{bb.get(12), bb.get(13)}); + PacketSection error = new PacketSection(sv); + if (0 != error.autoInt()) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + + bb.position(14); + byte[] v = new byte[2]; + bb.get(v, 0, v.length); + int a = Integer.valueOf(Util.bytes2HexString(v), 16); + byte[] s = new byte[a]; + bb.get(s, 0, a); + + /*ProtocolParser parser = pset.getProtocolResParse(); + Packet p = parser.parse(bb, "Res8016"); + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + System.out.println(error.autoInt()); + if (0 != error.autoInt()) { + throw new SydApiException(error.getInfo(), error.autoInt()); + }*/ + + byte[] pCertInfo = s; + //byte[] pCertInfo = ((PacketSection) ret.get("certInfo")).getBytes(); + //Util.bytes2HexString(pCertInfo); + + X509 cinfo = new X509(); + cinfo.setIssuer(Util.toCleanString(pCertInfo, 0, 257)); + cinfo.setSerialNumber(Util.toCleanString(pCertInfo, 257, 65)); + cinfo.setSubject(Util.toCleanString(pCertInfo, 257 + 65, 257)); + cinfo.setNotBefore(Util.toCleanString(pCertInfo, 257 + 65 + 257, 15)); + cinfo.setNotAfter(Util.toCleanString(pCertInfo, 257 + 65 + 257 + 15, 15)); + cinfo.setPubKey(pCertInfo, 257 + 65 + 257 + 15 + 15, pCertInfo.length - (257 + 65 + 257 + 15 + 15)); + + return cinfo; + } + + @Override + public String GetX509CertFileC(String userId, int nCertType) { + + //ProtocolRender render = pset.getProtocolReqRender(new byte[]{(byte) 0x80, 0x17}); + Proto8017 proto = new Proto8017(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + + if (userId.length() > 16) { + throw new SydApiException(-26); + } + byte[] u = new byte[16]; + System.arraycopy(userId.getBytes(), 0, u, 0, userId.length()); + byte type = 0 == nCertType ? (byte) 0 : (byte) 1; + + data.put("userId", u); + data.put("type", type); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + + + if (0 != error.autoInt()) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return new String(((PacketSection) ret.get("cert")).getBytes(), Charset.forName("gbk")); + + } + + @Override + public String SM2SignC(String pUserID, String certNo, int nOrgDataType, byte[] publicKey, byte[] orgData) { + + + if (certNo.length() > 32) { + certNo = certNo.substring(0, 32); + } + + + //ProtocolRender render = pset.getProtocolReqRender("74"); + Proto74 proto = new Proto74(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("signatureDataType$option", nOrgDataType); + data.put("userId", certNo.getBytes()); + data.put("publicKey", publicKey); + data.put("infoData", orgData); + data.put("hashData", orgData); + data.put("privateKeyTag", SYMUtil.genPrivateKeyMark(pUserID, SYMUtil.KT_SIGN, "00000001")); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + //System.out.println(Util.bytes2HexString(Util.toArray(bb))); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + + SectionValue sv = new SectionValue(); + sv.setValue(new byte[]{bb.get(12), bb.get(13)}); + PacketSection error = new PacketSection(sv); + if (0 != error.autoInt()) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + bb.position(14); + byte[] v = new byte[4]; + bb.get(v, 0, v.length); + int a = Util.a2i(v, 10); + byte[] s = new byte[a]; + bb.get(s, 0, a); +// ProtocolParser parser = pset.getProtocolResParse(); +// delta(); +// Packet p = parser.parse(bb, "Res74"); +// delta(); +// Map ret = p.toMap(); +// if ( +// !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) +// ) { +// throw new SydApiException("包序号不匹配", -4); +// } +// ret = (Map) ret.get("data"); +// PacketSection error = (PacketSection) ret.get("error"); +// if (!"00".equals(error.getString())) { +// throw new SydApiException(error.getInfo(), error.autoInt()); +// } + + //return SYMUtil.derSign2Base64Sign(((PacketSection) ret.get("signature")).getBytes()); + return SYMUtil.derSign2Base64Sign(s); + + } + + @Override + public String SM2SignCustomized(String certNo, byte[] orgData) { + + if (certNo.length() > 32) { + certNo = certNo.substring(0, 32); + } + Proto80 proto = new Proto80(); //pset.getProtocolReqRender("75"); + + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("certificateNo", certNo.getBytes()); + data.put("infoData", orgData); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + + throw new SydApiException(error.getInfo(), error.autoInt()); + } + return ((PacketSection) ret.get("signature")).getString(); + } + + + + public boolean SM2Verify( + int nOrgDataType, + byte[] publicKey, + byte[] orgData, + String base64Sign + ){ + String certNo = "1234567812345678"; + //ProtocolRender render = pset.getProtocolReqRender("75"); + Proto75 proto = new Proto75(); + + byte[] sign = Util.decodeBase64(base64Sign); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("signatureDataType$option", nOrgDataType); + data.put("signature", sign); + data.put("userId", certNo.getBytes()); + data.put("infoData", orgData); + data.put("hashData", orgData); + data.put("publicKey", publicKey); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + //System.out.println(Util.bytes2HexString(Util.toArray(bb))); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + bb.position(12); + byte[] v = new byte[2]; + bb.get(v, 0, v.length); + String a = Util.bytes2HexString(v); + if ("3030".equals(a)) { + return true; + } else { + return false; + } + } + + + + @Override + public String SM2Sign( + int nOrgDataType, + byte[] privateKey, + byte[] orgData) { + + Proto74 proto = new Proto74(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("signatureDataType$option", nOrgDataType); + data.put("userId", "1234567812345678".getBytes()); + + data.put("privateKey", privateKey); + data.put("hashData", orgData); + data.put("infoData", orgData); + data.put("privateKeyTag", "999999999999999999999999999"); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + + SectionValue sv = new SectionValue(); + sv.setValue(new byte[]{bb.get(12), bb.get(13)}); + PacketSection error = new PacketSection(sv); + if (0 != error.autoInt()) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + bb.position(14); + byte[] v = new byte[4]; + bb.get(v, 0, v.length); + int a = Util.a2i(v, 10); + byte[] s = new byte[a]; + bb.get(s, 0, a); + + return Util.encodeBase64(s); + } + + + + + @Override + public boolean SM2VerifyCustomized(String certNo, byte[] orgData, String base64Sign) { + + if (certNo.length() > 32) { + certNo = certNo.substring(0, 32); + } + + Proto81 proto = new Proto81(); //pset.getProtocolReqRender("75"); + + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("certificateNo", certNo.getBytes()); + data.put("signature", base64Sign.getBytes()); + data.put("infoData", orgData); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + + return false; + } + return true; + + } + + + @Override + public boolean SM2Verify(String certNo, int nOrgDataType, byte[] publicKey, byte[] orgData, String base64Sign) { + + if (certNo.length() > 32) { + certNo = certNo.substring(0, 32); + } + + Proto75 proto = new Proto75(); //pset.getProtocolReqRender("75"); + + byte[] sign = SYMUtil.base64Sign2DerSign(base64Sign); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("signatureDataType$option", nOrgDataType); + data.put("signature", sign); + data.put("userId", certNo.getBytes()); + data.put("infoData", orgData); + data.put("publicKey", publicKey); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + long b = System.currentTimeMillis(); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + + throw new SydApiException(error.getInfo(), error.autoInt()); + } + return true; + } + + + public byte[] encryptBySk(int alg, String sk, byte[] data) { + + byte[] algBin = 0 == alg ? DTO79.Req.Data.AlgorithmKeyOptions.OPVRSA.getBin() : DTO79.Req.Data.AlgorithmKeyOptions.OPVSM2.getBin(); + + Proto79 proto = new Proto79(); + DTO79.Req req = new DTO79.Req() + .setHeader(PacketSN.gen().getSn().array()) + .buildData() + .setAlgorithmKey(algBin) + .setFillKey(DTO79.Req.Data.FillKeyOptions.OPVPKCS1v15填充方式.getBin()) + .setPrivateKeyTag("999999999999999999999999999".getBytes()) + .setPrivateKey(Util.hexString2Bytes(sk)) + .setInfoData(data) + .closeBuilding(); + + + ByteBuffer bb = proto.rend(req.toSoup()); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + DTO79.Res res = new DTO79.Res(); + res = res.fullFromSoup(proto.parse(bb).resSoup()); + + if ("3030".equals(res.getData().getErrorAsHex())) { + return res.getData().getCipherDataAsBin(); + } else { + throw SydApiException.fromBin(res.getData().getErrorAsBin(), res.getData().getErrorCn()); + } + } + + + public byte[] decryptByPk(int alg, String pk, byte[] data) { + + byte[] algBin = 0 == alg ? DTO7A.Req.Data.AlgorithmKeyOptions.OPVRSA.getBin() : DTO7A.Req.Data.AlgorithmKeyOptions.OPVSM2.getBin(); + + Proto7A proto = new Proto7A(); + DTO7A.Req req = new DTO7A.Req() + .setHeader(PacketSN.gen().getSn().array()) + .buildData() + .setAlgorithmKey(algBin) + .setFillKey(DTO78.Req.Data.FillKeyOptions.OPVPKCS1v15填充方式.getBin()) + .setPublicKey(Util.hexString2Bytes(pk)) + .setInfoData(data) + .closeBuilding(); + + + ByteBuffer bb = proto.rend(req.toSoup()); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + DTO7A.Res res = new DTO7A.Res(); + res = res.fullFromSoup(proto.parse(bb).resSoup()); + + if ("3030".equals(res.getData().getErrorAsHex())) { + return res.getData().getCipherDataAsBin(); + } else { + throw SydApiException.fromBin(res.getData().getErrorAsBin(), res.getData().getErrorCn()); + } + } + + /** + * @param alg 0 = RSA 1 = SM2 + * @param pk HEX 格式的公钥 + * @return + */ + public byte[] encryptByPk(int alg, String pk, byte[] data) { + + byte[] algBin = 0 == alg ? DTO77.Req.Data.AlgorithmKeyOptions.OPVRSA.getBin() : DTO77.Req.Data.AlgorithmKeyOptions.OPVSM2.getBin(); + + Proto77 proto = new Proto77(); + DTO77.Req req = new DTO77.Req() + .setHeader(PacketSN.gen().getSn().array()) + .buildData() + .setAlgorithmKey(algBin) + .setFillKey(DTO77.Req.Data.FillKeyOptions.OPVPKCS1v15填充方式.getBin()) + .setPublicKey(Util.hexString2Bytes(pk)) + .setInfoData(data) + .closeBuilding(); + + + ByteBuffer bb = proto.rend(req.toSoup()); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + DTO77.Res res = new DTO77.Res(); + res = res.fullFromSoup(proto.parse(bb).resSoup()); + + if ("3030".equals(res.getData().getErrorAsHex())) { + return res.getData().getCipherDataAsBin(); + } else { + throw SydApiException.fromBin(res.getData().getErrorAsBin(), res.getData().getErrorCn()); + } + } + + public String encryptBase64ByPk(int alg, String pk, byte[] data) { + return SYMUtil.derEnData2Base64EnData(encryptByPk(alg, pk, data)); + } + + public byte[] decryptBase64BySk(int alg, String sk, String data) { + return decryptBySk(alg, sk, SYMUtil.base64EnData2DerEnData(data)); + } + + public byte[] decryptBySk(int alg, String sk, byte[] data) { + + byte[] algBin = 0 == alg ? DTO78.Req.Data.AlgorithmKeyOptions.OPVRSA.getBin() : DTO78.Req.Data.AlgorithmKeyOptions.OPVSM2.getBin(); + + Proto78 proto = new Proto78(); + DTO78.Req req = new DTO78.Req() + .setHeader(PacketSN.gen().getSn().array()) + .buildData() + .setAlgorithmKey(algBin) + .setFillKey(DTO78.Req.Data.FillKeyOptions.OPVPKCS1v15填充方式.getBin()) + .setPrivateKeyTag("999999999999999999999999999".getBytes()) + .setPrivateKey(Util.hexString2Bytes(sk)) + .setInfoData(data) + .closeBuilding(); + + + ByteBuffer bb = proto.rend(req.toSoup()); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + DTO78.Res res = new DTO78.Res(); + res = res.fullFromSoup(proto.parse(bb).resSoup()); + + if ("3030".equals(res.getData().getErrorAsHex())) { + return res.getData().getDataAsBin(); + } else { + throw SydApiException.fromBin(res.getData().getErrorAsBin(), res.getData().getErrorCn()); + } + } + + @Override + public String SM2Encrypt(byte[] publicKey, byte[] pOrgData) { + Proto77 proto = new Proto77(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("AlgorithmKey$option", 1); + data.put("publicKey", publicKey); + data.put("infoData", pOrgData); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return SYMUtil.derEnData2Base64EnData(((PacketSection) ret.get("cipherData")).getBytes()); + } + + @Override + public byte[] SM2DecryptC(String userId, String enData) { + //ProtocolRender render = pset.getProtocolReqRender("78"); + Proto78 proto = new Proto78(); + + byte[] pOrgData = SYMUtil.base64EnData2DerEnData(enData); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("AlgorithmKey$option", 1); + data.put("infoData", pOrgData); + data.put("privateKeyTag", SYMUtil.genPrivateKeyMark(userId, SYMUtil.KT_ENCRYPT, "00000001")); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("data")).getBytes(); + } + + @Override + public byte[] SM3Hash(byte[] msg) { + return SM3Hash(null, msg); + } + + + @Override + public byte[] SM3Hash(String publicKey, byte[] msg) { + return SM3Hash(publicKey, msg, 0, null); + } + + + /** + * @param publicKey + * @param msg + * @param mac 当 mac 不是 null,长度不为 0,则直接从第二包开始。 + * @return + */ + @Override + public byte[] SM3Hash(String publicKey, byte[] msg, int block, byte[] mac) { + + + // 填充数据 + PacketSN sn = PacketSN.gen(); + final int packLen = 2048; + int loop = msg.length / packLen; + if (msg.length % packLen > 0) { + loop++; + } + + + byte[] ctx = new byte[0]; + if (2 == block || 3 == block) { + ctx = mac; + } + + + // 最后一块正好为空的情况 + boolean hard = false; + if (msg.length == 0 || 3 == block) { + hard = true; + } + + byte packtype; + int i = 0; + while (i < loop || hard) { + + if (hard) { + packtype = '3'; + } else { + if (0 == i) { + if (1 == loop) { + packtype = '0'; + } else { + packtype = '1'; + } + } else { + if (i == (loop - 1)) { + packtype = '3'; + } else { + packtype = '2'; + } + } + + // 如果大包是唯一包 0 , 逻辑不变 + // 如果大包是首包 1,则尾包不是尾包 + // 如果大包是中间包 2,则全部是中间包 + // 如果大包是尾包 3,则没有首包。 + + + if (1 == block && packtype == '3') { + packtype = '2'; + } else if (2 == block) { + packtype = '2'; + } else if (3 == block && packtype == '1') { + packtype = '2'; + } + } + + + ByteBuffer bb = ByteBuffer.allocate(3000); + + byte[] ret = new byte[2]; + bb.put(ret); + bb.put(sn.getSn().array()); + bb.put("76".getBytes()); + bb.put(packtype); + + + int tmplen = (i < (loop - 1) || !(msg.length % packLen > 0)) ? packLen : (msg.length % packLen); + + if (hard) { + tmplen = 0; + } + hard = false; + + // 填充长度 + bb.put(String.format("%04d", tmplen).getBytes()); + + // 填充数据 + bb.put(msg, i * packLen, tmplen); + + + if ('0' == packtype || '1' == packtype) { + + + if (null == publicKey) { + bb.put(String.format("%02d", 0).getBytes()); + bb.put("".getBytes()); + bb.put(String.format("%04d", 0).getBytes()); + bb.put("".getBytes()); + } else { + bb.put(String.format("%02d", 16).getBytes()); + bb.put("1234567812345678".getBytes()); + bb.put(String.format("%04d", publicKey.length() / 2).getBytes()); + bb.put(Util.hexString2Bytes(publicKey)); + } + + + } else if ('2' == packtype || '3' == packtype) { + + bb.put(String.format("%04d", ctx.length).getBytes()); + bb.put(ctx); + + } + + + int len = bb.position() - 2; + + bb.put(0, (byte) (0xFF & (len / 256))); + bb.put(1, (byte) (0xFF & (len % 256))); + + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + + bb.flip(); + + // 忽略头部 + bb.get(new byte[12], 0, 12); + + + // 检测错误 + byte[] error = new byte[2]; + + bb.get(error, 0, 2); + + int e = Util.a2i(error, 16); + + if (0 != e) { + throw new SydApiException(0x80 == e ? "数据长度错" : "输入长度错", e); + } + + + if ('0' == packtype || '3' == packtype) { + byte[] hash = new byte[32]; + bb.get(hash, 0, 32); + return hash; + } else if ('1' == packtype || '2' == packtype) { + + byte[] hashLen = new byte[4]; + + bb.get(hashLen, 0, 4); + + + byte[] hash = new byte[Util.a2i(hashLen, 10)]; + + bb.get(hash, 0, hash.length); + + ctx = hash; + + + } + + i++; + } + + return ctx; + } + + @Override + public RetWrap SM2GenSessionKey(String publicKey) { + // 获取协议 + //ProtocolRender render = pset.getProtocolReqRender("72"); + Proto72 proto = new Proto72(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + data.put("publicKey", Util.hexString2Bytes(publicKey)); + data.put("lmk", "X"); + packet.put("data", data); + + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + rw.put(SydApi.RET_CIPHER_KEY, Util.bytes2HexString( + ((PacketSection) ret.get("key")).getBytes() + )); + rw.put(SydApi.RET_SESSION_KEY, ((PacketSection) ret.get("lmkHead")).getString() + + ((PacketSection) ret.get("lmk")).getString() + ); + + rw.put(SydApi.RET_KCV, ((PacketSection) ret.get("keyCheck")).getString()); + + return rw; + } + + @Override + public RetWrap SM2ConfirmSessionKeyC(String userId, String cipherKey) { + + if (userId.length() > 16) { + throw new SydApiException(-26); + } + + + // 获取协议 + //ProtocolRender render = pset.getProtocolReqRender("73"); + Proto73 proto = new Proto73(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + //传全9的情况,私钥需要自己传 + //data.put("privateKeyTag", "999999999999999999999999999"); + //String sk = "00010000C530EFBC1971D6526BDAB640370EE9197BFB0D78F88417C1ED49981FFEF226980000000000000000000000000000000000000000000000000000000000000000"; + //data.put("privateKey", Util.hexString2Bytes(sk)); + + data.put("privateKeyTag", SYMUtil.genPrivateKeyMark(userId, "001", "00000001")); + data.put("privateKey", new byte[0]); + data.put("cipherKey", Util.hexString2Bytes(cipherKey)); + data.put("lmk", "X"); + + packet.put("data", data); + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + + System.out.println("lmkHead" + ((PacketSection) ret.get("lmkHead")).getString() + + "\nlmk" + ((PacketSection) ret.get("lmk")).getString()); + + + rw.put(SydApi.RET_SESSION_KEY, ((PacketSection) ret.get("lmkHead")).getString() + + ((PacketSection) ret.get("lmk")).getString() + ); + + rw.put(SydApi.RET_KCV, ((PacketSection) ret.get("keyCheck")).getString()); + + return rw; + } + + @Override + public byte[] SYMEncryptDataCBC(int nAlg, String seesionKey, byte[] pInData) { + return SYMEncryptDataCBC(nAlg, seesionKey, 1, pInData); + } + + + @Override + public byte[] SYMEncryptDataCBC(int nAlg, String seesionKey, int fullmode, byte[] pInData) { + if (2 == nAlg && 'L' != seesionKey.charAt(0)) { + throw new SydApiException(-27); + } + + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + byte[] iv = new byte[0 == nAlg ? 16 : 32]; + Arrays.fill(iv, (byte) 0x30); + + switch (nAlg) { + case 0: + data.put("alg$option", 0x0); + break; + case 2: + data.put("alg$option", 0xC); + break; + default: + data.put("alg$option", 0x8); + } + + + data.put("roundModel$option", 1); + data.put("iv", iv); + data.put("keyType$option", 0); + data.put("key", seesionKey.getBytes()); + data.put("inType$option", 0); + data.put("outType$option", 0); + data.put("fullMode$option", fullmode); + data.put("fullChar$option", 0); + data.put("fullType$option", 0 == fullmode ? 0 : 2); + data.put("msg", pInData); + packet.put("data", data); + + return repackEncrypt(packet); + } + + + @Override + public byte[] SYMDecryptDataCBC(int nAlg, String seesionKey, byte[] pInData) { + return SYMDecryptDataCBC(nAlg, seesionKey, 1, pInData); + } + + @Override + public byte[] SYMDecryptDataCBC(int nAlg, String seesionKey, int fullmode, byte[] pInData) { + if (2 == nAlg && 'L' != seesionKey.charAt(0)) { + throw new SydApiException(-27); + } + byte[] iv = new byte[0 == nAlg ? 16 : 32]; + Arrays.fill(iv, (byte) 0x30); + + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + switch (nAlg) { + case 0: + data.put("alg$option", 0x1); + break; + case 2: + data.put("alg$option", 0xD); + break; + default: + data.put("alg$option", 0x9); + } + + + data.put("roundModel$option", 1); + data.put("iv", iv); + data.put("keyType$option", 0); + data.put("key", seesionKey.getBytes()); + data.put("inType$option", 0); + data.put("outType$option", 0); + data.put("fullMode$option", fullmode); + data.put("fullChar$option", 0); + data.put("fullType$option", 0 == fullmode ? 0 : 2); + data.put("msg", pInData); + packet.put("data", data); + + return repackEncrypt(packet); + } + + @Override + public String GetDNPublicKey(int dnType, byte[] dn) { + + //ProtocolRender render = pset.getProtocolReqRender("7E"); + Proto7E proto = new Proto7E(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("userCertificateType$option", dnType); + data.put("DN", dn); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + //System.out.println(Util.bytes2HexString(Util.toArray(bb))); + synchronized (this) { + + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return Util.bytes2HexString(((PacketSection) ret.get("publicKey")).getBytes()); + } + + + @Override + public byte[] send(byte[] pack) { + + ByteBuffer bb = ByteBuffer.wrap(pack); + synchronized (this) { + + // 响应解析 + bb = syncRead(syncSend(bb)); + } + return bb.array(); + } + + @Override + public String send(String pack) { + + return Util.bytes2HexString( + send(Util.hexString2Bytes(pack)) + ); + + } + + + static interface PackCallBack { + void circle(int packSn, HashMap packet, Map ret); + } + + + @Override + public byte[] detachedSign(int dataType, byte[] orgData, int keyTag) { + Proto8024 proto = new Proto8024(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + byte[] byteKeyNum = {(new Integer(keyTag / 256 / 256 / 256)).byteValue(), + (new Integer(keyTag / 256 / 256)).byteValue(), (new Integer(keyTag / 256)).byteValue(), + (new Integer(keyTag)).byteValue()}; + + data.put("keyTag", byteKeyNum); + +// data.put("keyTag", keyTag); + if (dataType == DATA_HASH) { + data.put("hashFlag", 'P'); + data.put("hash", orgData); + } else { + data.put("infoData", orgData); + } + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("signature")).getBytes(); + } + + + // 读取文件长度 + public int getInDataLen(String filePath) throws Exception { + FileInputStream tmpInput = new FileInputStream(filePath); + int lenInData = tmpInput.available(); + tmpInput.close(); + return lenInData; + } + + // 读取文件内容 + public byte[] getInData(String filePath) throws Exception { + FileInputStream tmpInput = new FileInputStream(filePath); + int lenInData = tmpInput.available(); + + byte[] InData = new byte[lenInData]; + + tmpInput.read(InData); + tmpInput.close(); + + return InData; + } + + // 写入文件内容 + public static void outToFile(byte[] outData, String filePath) throws Exception { + FileOutputStream tmpOutput = new FileOutputStream(filePath, true); + tmpOutput.write(outData); + tmpOutput.close(); + } + + @Override + public String detachedSignbysn(int dataType, byte[] orgData, String certificateNo) { + Proto8026 proto = new Proto8026(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("certificateNo", certificateNo); + +// data.put("keyTag", keyTag); + if (dataType == DATA_HASH) { + data.put("dataSign", "P"); + data.put("hash", orgData); + } else { + data.put("infoData", orgData); + } + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("signature")).getString(); + } + + public byte[] Encrypt_Data(int alg, int roundModel, int fullMode, String DEK, byte[] infoData, byte[] vector) { + ProtoQ1 proto = new ProtoQ1(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("alg$option", alg - 1); + data.put("roundModel$option", roundModel - 1); + data.put("fullMode$option", fullMode); + data.put("DEK", DEK); + /* int length = DEK.length(); + if (length == 16){ + data.put("DEK", DEK); + }else if (length == 32 ){ + data.put("DEK", "X"+DEK); + }else if (length == 48){ + data.put("DEK", "Y"+DEK); + }else if (length == 27){ + data.put("DEK", "XK"+DEK); + }else { + System.out.println("索引长度错误"); + return null; + }*/ + data.put("infoData", infoData); + + if (roundModel == 2 || roundModel == 3 || roundModel == 4) { + data.put("vector", vector); + } + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("infoData")).getBytes(); + } + + public byte[] Decrypt_Data(int alg, int roundModel, int fullMode, String DEK, byte[] infoData, byte[] vector) { + ProtoQ2 proto = new ProtoQ2(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("alg$option", alg - 1); + data.put("roundModel$option", roundModel - 1); + data.put("fullMode$option", fullMode); + data.put("DEK", DEK); + /*int length = DEK.length(); + if (length == 16){ + data.put("DEK", DEK); + }else if (length == 32 ){ + data.put("DEK", "X"+DEK); + }else if (length == 48){ + data.put("DEK", "Y"+DEK); + }else if (length == 27){ + data.put("DEK", "XK"+DEK); + }else { + System.out.println("索引长度错误"); + return null; + }*/ + + data.put("infoData", infoData); + + if (roundModel == 2 || roundModel == 3 || roundModel == 4) { + data.put("vector", vector); + } + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("infoData")).getBytes(); + } + + + public byte[] MAC_Data(String TAK, String infoData, String IV) { + ProtoMA proto = new ProtoMA(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + if (IV != null && !IV.equals("")) { + data.put("IVKey", "P"); + data.put("IV", IV); + } + + + data.put("TAK", TAK); + + + infoData += "80"; + while (infoData.length() % 16 != 0) { + infoData += "00"; + } + data.put("MACData", infoData); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("MAC")).getBytes(); + } + + + public byte[] _calcPBOCMAC(int mode, int keyType, String key, byte[] odata, int block, byte[] iv) { + ProtoMU proto = new ProtoMU(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("block", block); + data.put("keyType$option", keyType); + data.put("mode$option", mode); + data.put("dataType$option", 0); + data.put("key", key); + if (null != iv) { + data.put("iv", iv); + } + + data.put("MACData", odata); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("MAC")).getBytes(); + } + + public String calcPBOCMAC(int mode, int keyType, String key, byte[] data, int block, byte[] iv) { + + int packSize = 2048; + // 进行分包 + // 满包数 + int loop = data.length / packSize; + int tailLen = data.length % packSize; + if (tailLen > 0) { + loop++; + } else { + tailLen = packSize; + } + + + // 获取协议 + synchronized (this) { + int packNo = 0; + for (int i = 0; i < loop; i++) { + + if (0 == i) { + if (1 == loop) { + // 数据量很小 + // 大包可能是唯一包/尾包,不可能是首包/中间包。 + // + if (0 == block) { + // 唯一包 + // 大包是唯一包 + // 小包也是唯一包 + // 即小数据量,一包结束。 + byte[] r = _calcPBOCMAC(mode, keyType, key, data, 0, null); + println("\n\t唯一包"); + return new String(r); + } else if (3 == block) { + // 尾包 + byte[] r = _calcPBOCMAC(mode, keyType, key, data, 3, iv); + println("\n\t尾包"); + return new String(r); + + } else { + assert false : "大包可能是唯一包/尾包,不可能是首包/中间包。"; + } + + } else { + + // 大包可能是首包唯一包/首包/中间包/尾包。 + if (0 == block || 1 == block) { + // 大包是唯一包/首包 + // 小包是首包 + byte[] msg = new byte[packSize]; + System.arraycopy(data, 0, msg, 0, packSize); + println("\n\t首包"); + iv = _calcPBOCMAC(mode, keyType, key, msg, 1, null); + + } else if (2 == block || 3 == block) { + // 大包是中间包/尾包 + // 小包是中间包 + byte[] msg = new byte[packSize]; + System.arraycopy(data, 0, msg, 0, packSize); + println("\n\t中间包"); + iv = _calcPBOCMAC(mode, keyType, key, msg, 2, iv); + } + } + } else { + + if (i == (loop - 1)) { + // 小包准备收尾 + // 大包可能是所有类型 + // 需要对大包的首保/中间包的收尾做特殊处理,不算收尾, 算中间包 + if (1 == block || 2 == block) { + byte[] msg = new byte[tailLen]; + System.arraycopy(data, i * packSize, msg, 0, tailLen); + println("\n\t中间包"); + iv = _calcPBOCMAC(mode, keyType, key, msg, 2, iv); + } else { + // 尾包 + byte[] msg = new byte[tailLen]; + System.arraycopy(data, i * packSize, msg, 0, tailLen); + byte[] r = _calcPBOCMAC(mode, keyType, key, msg, 3, iv); + println("\n\t尾包"); + return new String(r); + } + + } else { + // 中间包 + packNo = 2; + byte[] msg = new byte[packSize]; + System.arraycopy(data, i * packSize, msg, 0, packSize); + println("\n\t中间包"); + iv = _calcPBOCMAC(mode, keyType, key, msg, 2, iv); + } + } + } + } + throw new SydApiException(40000); + } + + + /** + * mac 计算 + * + * @param alg 0=DES 1=3DES 2=SM4 3=AES 4=IDEA 5=SM1 6=3DES-X9.19 + * @param keyType 0-TAK 1-ZAK + * @param fullMode 0-弱填充 1 强填充 + * @param AK 密钥 + * @param infoData <=1024 + * @param macLen 1=4Byte 2=8Byte 3=16Byte(仅在SM4/AES 下有效) + * @return mac 值 hex 格式 + */ + @Override + public String MACCalc(int alg, int keyType, String AK, int fullMode, byte[] infoData, int macLen) { + ProtoMA proto = new ProtoMA(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("businessKey", 'P'); + data.put("alg$option", alg); + data.put("keyType$option", keyType); + data.put("fullMode$option", fullMode); + data.put("MACLen$option", macLen - 1); + data.put("key", AK.getBytes()); + data.put("MACData", Util.bytes2HexString(infoData)); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("MAC")).getString(); + } + + + /** + * mac 计算 + * + * @param alg 0=DES 1=3DES 2=SM4 3=AES 4=IDEA 5=SM1 6=3DES-X9.19 + * @param keyType 0-TAK 1-ZAK + * @param fullMode 0-弱填充 1 强填充 + * @param AK 密钥 + * @param infoData <=1024 + * @param mac 值 hex 格式 + * @return + */ + public void MACCheck(int alg, int keyType, String AK, int fullMode, byte[] infoData, String mac) { + ProtoMC proto = new ProtoMC(); + int macLen = mac.length(); + if (macLen == 32) { + macLen = 3; + } else if (macLen == 16) { + macLen = 2; + } else if (macLen == 8) { + macLen = 1; + } else { + throw new SydApiException("MAC 输入错误", 21); + } + + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("businessKey", 'P'); + data.put("alg$option", alg); + data.put("keyType$option", keyType); + data.put("fullMode$option", fullMode); + data.put("MACLen$option", macLen - 1); + data.put("key", AK); + data.put("MAC", mac.getBytes()); + data.put("MACData", Util.bytes2HexString(infoData)); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return; + } + + public String SYD_Disperse(String mainKey, int keyType, int disperseNum, byte[] dt, int disperseAlg, int keyCheckType) { + ProtoYA proto = new ProtoYA(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + int length = mainKey.length(); + if (length == 16) { + data.put("mainKey", mainKey); + } else if (length == 32) { + data.put("mainKey", "X" + mainKey); + } else if (length == 48) { + data.put("mainKey", "Y" + mainKey); + } else if (length == 27) { + data.put("mainKey", "XK" + mainKey); + } else { + System.out.println("索引长度错误"); + return null; + } + data.put("keyType$option", keyType); + data.put("disperseNum", disperseNum); + data.put("data", dt); + +// if(disperseNum == 2){ +// data.put("data2", data1); +// }else if (disperseNum == 3){ +// data.put("data2", data1); +// data.put("data3", data1); +// } + + + data.put("disperseAlg$option", disperseAlg - 1); + data.put("keyCheckType$option", keyCheckType); + + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("lmk")).getString(); + } + + public byte[] SYD_Encrypt_Data(int alg, String DEK, byte[] infoData, byte[] vector, int disperseAlg, byte[] factor) { + String ss = SYD_Disperse(DEK, 0, 1, factor, disperseAlg, 0); + byte[] bytes = Encrypt_Data(alg, 1, 2, ss, infoData, vector); + return bytes; + + } + + public byte[] SYD_Decrypt_Data(int alg, String DEK, byte[] infoData, byte[] vector, int disperseAlg, byte[] factor) { + String ss = SYD_Disperse(DEK, 0, 1, factor, disperseAlg, 0); + byte[] bytes = Decrypt_Data(alg, 1, 2, ss, infoData, vector); + return bytes; + } + + + /** + * 先锋定制特例 + * + * @param DEK + * @param infoData 生成MAC的数据 + * @param factor + * @param IV + * @param disperseNum 指定对根密钥分散的次数(1-3次) + * @param disperseAlg 分散算法 + * @return + */ + public byte[] SYD_MAC_Data(String DEK, String infoData, byte[] factor, String IV, int disperseNum, int disperseAlg) { + String ss = SYD_Disperse(DEK, 1, disperseNum, factor, disperseAlg, 0); + + if (2 == disperseNum) { + ss = ss.substring(1, 17); + } + + byte[] bytes = MAC_Data(ss, infoData, IV); + return bytes; + } + + + public static String getVersion() { + + try { + InputStream is = SydApi.class.getClassLoader().getResourceAsStream("racal.sunyard.main.version"); + + byte[] buff = new byte[is.available()]; + is.read(buff); + return new String(buff).trim(); + + } catch (Exception e) { + return "Non-release"; + } + } + + @Override + public String GenerateMIYA(String AreaCode, int Version, int Alg, byte[] Data) { + if (Version < 0 || Version > 999) { + throw new SydApiException("Version 范围不对", 21); + } + + Proto4D41 proto = new Proto4D41(); + + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + + String keyTpye = ""; + + if (0 == Alg) { + data.put("alg$option", 0); + data.put("type$option", 0); + keyTpye = "003"; + } else { + data.put("alg$option", 1); + data.put("type$option", 1); + keyTpye = "008"; + } + + String key = "XK"; + + // 机构号扩展到 16 位 + // 前补 0 + String gid = "0000000000000000" + AreaCode; + gid = gid.substring(gid.length() - 16); + + String kid = "00000"; + String v = String.format("%03d", Version); + key += gid + keyTpye + kid + v; + + data.put("MACData", Util.bytes2HexString(Data).getBytes()); + data.put("key", key); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("MAC")).getString(); + } + + @Override + public boolean VerifyMIYA(String AreaCode, int Version, int Alg, String mac, byte[] Data) { + + if (Version < 0 || Version > 999) { + throw new SydApiException("Version 范围不对", 21); + } + + Proto4D43 proto = new Proto4D43(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + + String keyTpye = ""; + + if (0 == Alg) { + data.put("alg$option", 0); + data.put("type$option", 0); + keyTpye = "003"; + } else { + data.put("alg$option", 1); + data.put("type$option", 1); + keyTpye = "008"; + } + + String key = "XK"; + + // 机构号扩展到 16 位 + // 前补 0 + String gid = "0000000000000000" + AreaCode; + gid = gid.substring(gid.length() - 16); + + String kid = "00000"; + String v = String.format("%03d", Version); + key += gid + keyTpye + kid + v; + + + data.put("MAC", mac); + data.put("MACData", Util.bytes2HexString(Data).getBytes()); + data.put("key", key); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + + if (1 == error.autoInt()) { + return false; + } + + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return true; + } + + + @Override + public RetWrap getStatus() { + ProtoHI proto = new ProtoHI(); + + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection cpu = (PacketSection) ret.get("cpu"); + PacketSection mem = (PacketSection) ret.get("mem"); + PacketSection disk = (PacketSection) ret.get("disk"); + + + RetWrap retWrap = new RetWrap(); + retWrap.put("CPU", cpu.getString()); + retWrap.put("MEM", mem.getString()); + retWrap.put("DISK", disk.getString()); + + return retWrap; + } + + + public RetWrap genAndPrint(String keyType, String solution) { + ProtoA2 proto = new ProtoA2(); + + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("keyType", keyType); + data.put("solution", solution); + data.put("flag", "N"); + data.put("print", "Cheney;China"); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1])) + + ) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + RetWrap retWrap = new RetWrap(); + byte[] lmks = ((PacketSection) ret.get("key")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("keyHead")).getBytes(); + byte[] bs = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs, lmkHeads.length, lmks.length); + retWrap.put("lmkKey", bs); + + return retWrap; + } + + public void setPrintFormat(String format) { + ProtoPA proto = new ProtoPA(); + + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("format", format); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1])) + + ) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return; + } + + @Override + public RetWrap genAndPrintSplit(String keyType, char solution) { + + ProtoNE proto = new ProtoNE(); + + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + + data.put("keyType", keyType); + data.put("solution", solution); + data.put("flag", "N"); + data.put("print", ""); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + ByteBuffer b2 = syncRead(null); + System.out.println("r " + Util.bytes2HexString(b2.array())); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1])) + + ) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + +// PacketSection keyHead = (PacketSection) ret.get("keyHead"); +// PacketSection key = (PacketSection) ret.get("key"); +// PacketSection kcv = (PacketSection) ret.get("keyCheck"); +// +// System.out.println( keyHead.getString() ); +// System.out.println( key.getString() ); +// System.out.println( Util.bytes2HexString( kcv.getBytes() ) ); + + RetWrap retWrap = new RetWrap(); + byte[] lmks = ((PacketSection) ret.get("key")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("keyHead")).getBytes(); + byte[] bs = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs, lmkHeads.length, lmks.length); + retWrap.put("lmkKey", bs); + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + + return retWrap; + } + + + @Override + public RetWrap outputKey(String keyType, char solution, String zmk, String key) { + + ProtoA8 proto = new ProtoA8(); + + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + + data.put("keyType", keyType); + data.put("keySolution", solution); + data.put("zmk", zmk); + data.put("key", key); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1])) + + ) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + + RetWrap retWrap = new RetWrap(); + byte[] lmks = ((PacketSection) ret.get("zmk")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("zmkHead")).getBytes(); + byte[] bs = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs, lmkHeads.length, lmks.length); + retWrap.put("key", bs); + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + + return retWrap; + } + + @Override + public RetWrap inputKey(String keyType, char solution, String zmk, String key) { + + ProtoA6 proto = new ProtoA6(); + + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + + data.put("keyType", keyType); + data.put("keySolution", solution); + data.put("zmk", zmk); + data.put("key", key); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1])) + + ) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + + RetWrap retWrap = new RetWrap(); + byte[] lmks = ((PacketSection) ret.get("lmk")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("lmkHead")).getBytes(); + byte[] bs = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs, lmkHeads.length, lmks.length); + retWrap.put("key", bs); + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + + return retWrap; + } + + + public byte[] MACCalc(int alg, int keyType, int fullmode, int maclen, String key, byte[] infoData) { + ProtoMA proto = new ProtoMA(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("businessKey", 'P'); + data.put("alg$option", alg); + data.put("keyType$option", keyType); + data.put("fullMode$option", fullmode); + data.put("MACLen$option", maclen); + data.put("key", key); + data.put("MACData", infoData); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb,packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("MAC")).getBytes(); + } + + +// +// +// String genIBMPINOffset(){ +// +// } +// +// void checkIBMPINOffset(){ +// +// } + + /** + * @Description 转换秘钥方案 -> pass + * @Param [keyType秘钥类型, key秘钥, solution秘钥方案] + * @Return com.sunyard.RetWrap + * @Author wp + * @Date 2020/9/29 12:36 + **/ + public RetWrap conversionKey(String keyType, String key, char solution) { + + ProtoB0 proto = new ProtoB0(); + + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("keyType", keyType); + data.put("keySolution", solution); + data.put("key", key); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1])) + + ) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + RetWrap retWrap = new RetWrap(); + byte[] lmks = ((PacketSection) ret.get("lmk")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("lmkHead")).getBytes(); + byte[] bs = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs, lmkHeads.length, lmks.length); + retWrap.put("lmkkey", bs); + + return retWrap; + } + + /** + * @Description 将ZMK由ZMK转为LMK加密(+) -> pass + * @Param [zmki, zmk] + * @Return com.sunyard.RetWrap + * @Author wp + * @Date 2020/9/29 18:16 + **/ + public RetWrap changZMK2LMK(String zmki, String zmk) { + + ProtoBY proto = new ProtoBY(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("zmki", zmki); + data.put("zmk", zmk); + data.put("separator", ";"); + data.put("zmkSolution", "X"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + byte[] zmks = ((PacketSection) ret.get("zmk")).getBytes(); + byte[] zmkHeads = ((PacketSection) ret.get("zmkHead")).getBytes(); + byte[] bs = new byte[zmks.length + zmkHeads.length]; + System.arraycopy(zmkHeads, 0, bs, 0, zmkHeads.length); + System.arraycopy(zmks, 0, bs, zmkHeads.length, zmks.length); + retWrap.put("zmkKey", bs); + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + + } + + /** + * @Description 加密机版本号 -> pass + * @Param [num] + * @Return com.sunyard.RetWrap + * @Author wp + * @Date 2020/9/30 16:42 + **/ + public RetWrap getVersion(String num) { + ProtoHV proto = new ProtoHV(); + + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("num", num); + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection name = (PacketSection) ret.get("name"); + PacketSection model = (PacketSection) ret.get("model"); + PacketSection equipNo = (PacketSection) ret.get("equipNo"); + PacketSection softVersion = (PacketSection) ret.get("softVersion"); + + + RetWrap retWrap = new RetWrap(); + retWrap.put("NAME", name.getString()); + retWrap.put("MODEL", model.getString()); + retWrap.put("EQUIPNO", equipNo.getString()); + retWrap.put("SOFTVERSION", softVersion.getString()); + + return retWrap; + } + + //22.1计算HASH散列值(HMAC-MD5\SHA1\SHA256)(+) ->高性能支持 ,test暂未通过 + public RetWrap calcHash(String key, int hashType, String contextInfo, byte[] infoData) { + Proto82 proto = new Proto82(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("key", key); + data.put("hashType$option", hashType); + data.put("contextInfo", contextInfo); + data.put("infoData", infoData); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap rw = new RetWrap(); + + rw.put("contextInfo_Length", ((PacketSection) ret.get("contextInfo_Length")).getBytes()); + rw.put("contextInfo", ((PacketSection) ret.get("contextInfo")).getBytes()); + rw.put("HMAC_LEN", ((PacketSection) ret.get("HMAC_LEN")).getBytes()); + rw.put("HAMC", ((PacketSection) ret.get("HAMC")).getBytes()); + + return rw; + } + } + } + + //19.1解密数据并由公钥加密输出 ->: code = 19 ( 0x13 ) msg = 数据解密错(C3) (服务器代码问题) + public RetWrap decryptAndEncryptByP(String DEK, byte[] infoData, int alg, byte[] publicKey) { + // 获取协议 + Proto68 proto = new Proto68(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + + data.put("DEK", DEK.getBytes()); + data.put("infoData", infoData); + data.put("alg$option", alg); + data.put("fillKey$option", 1); + data.put("publicKey", publicKey); + /* data.put("AlgorithmKey1", "P"); + data.put("EncryAlgorithm1$option", 1); + data.put("AlgorithmKey2", "Q"); + data.put("EncryAlgorithm2$option", 0);*/ + + packet.put("data", data); + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + rw.put("keyLen", ((PacketSection) ret.get("keyLen")).getString()); + rw.put("key", ((PacketSection) ret.get("key")).getString()); + return rw; + } + + //19.2由私钥解密密文数据并经过DEK加密后输出 ->code = 21 ( 0x15 ) msg = 输入的数据格式错误,等待19.1解决 + public RetWrap decryptAndEncryptByS(String DEK, byte[] infoData, String privatekey) { + // 获取协议 + Proto69 proto = new Proto69(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + data.put("alg$option", 1); + data.put("fillKey$option", 0); + data.put("privateKeyTag", "999999999999999999999999999".getBytes()); + data.put("privateKey", privatekey.getBytes()); + data.put("infoData", infoData); + data.put("DEK", DEK.getBytes()); + data.put("AlgorithmKey1", "P"); + data.put("EncryAlgorithm1$option", 1); + data.put("AlgorithmKey2", "Q"); + data.put("EncryAlgorithm2$option", 0); + + packet.put("data", data); + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + rw.put("keyLen", ((PacketSection) ret.get("keyLen")).getString()); + rw.put("key", ((PacketSection) ret.get("key")).getString()); + return rw; + } + + //18.1加押指令(+) -> pass + public RetWrap impose(String keyType, String key, byte[] infoData) { + // 获取协议 + Proto62 proto = new Proto62(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + data.put("keyType", keyType); + data.put("key", key); + data.put("AlgorithmKey", "P"); + data.put("alg$option", 0); + data.put("outputFormat$option", 0); + data.put("infoData", infoData); + + packet.put("data", data); + + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + rw.put("MAC", ((PacketSection) ret.get("MAC")).getString()); + return rw; + } + + //18.2核押指令(+) -> pass + public Boolean verifyImpose(String keyType, String key, byte[] secret, byte[] infoData) { + // 获取协议 + Proto63 proto = new Proto63(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + data.put("keyType", keyType); + data.put("key", key); + data.put("AlgorithmKey", "P"); + data.put("alg$option", 0); + data.put("outputFormat$option", 0); + data.put("secret", secret); + data.put("infoData", infoData); + + packet.put("data", data); + + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + return false; + } + return true; + } + + //18.3加解密指令(+) -> pass + public RetWrap encryAndDecry(String keyType, String key, byte[] infoData) { + // 获取协议 + Proto64 proto = new Proto64(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + data.put("keyType", keyType); + data.put("key", key); + data.put("log$option", 1); + data.put("AlgorithmKey", "P"); + data.put("alg$option", 0); + data.put("infoData", infoData); + + + packet.put("data", data); + + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + rw.put("infoLen", ((PacketSection) ret.get("infoLen")).getString()); + rw.put("info", ((PacketSection) ret.get("info")).getString()); + return rw; + } + + //18.4转加密指令(+) -> pass + public RetWrap switchEncry(String keyType, String srcKey, String aimKey, byte[] infoData) { + // 获取协议 + Proto65 proto = new Proto65(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + data.put("keyType", keyType); + data.put("srcKey", srcKey); + data.put("aimKey", aimKey); + data.put("AlgorithmKey", "P"); + data.put("alg$option", 0); + data.put("infoData", infoData); + + packet.put("data", data); + + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + rw.put("infoLen", ((PacketSection) ret.get("infoLen")).getString()); + rw.put("info", ((PacketSection) ret.get("info")).getBytes()); + return rw; + } + + //18.5 PIN加解密指令(+) -> pass + public byte[] encryAndDecry4PIN(String key, byte[] pin) { + // 获取协议 + Proto66 proto = new Proto66(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + data.put("key", key); + data.put("AlgorithmKey", "P"); + data.put("log$option", 0); + data.put("alg$option", 0); + data.put("pin", pin); + + packet.put("data", data); + + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb, packet); + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("info")).getBytes(); + } + + //18.6 PIN转加密指令(+) -> pass + public byte[] switchEncry4PIN(String srcKey, String aimKey, byte[] infoData) { + // 获取协议 + Proto67 proto = new Proto67(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + data.put("srcKey", srcKey); + data.put("aimKey", aimKey); + data.put("AlgorithmKey", "P"); + data.put("alg$option", 0); + data.put("pin", infoData); + + packet.put("data", data); + + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb, packet); + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + return ((PacketSection) ret.get("info")).getBytes(); + } + + //17.8 获取传输保护密钥(+) -> code = 18 ( 0x12 ) msg = 未定义的错误 + public RetWrap getTransmissionKey() { + // 获取协议 + Proto60 proto = new Proto60(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + packet.put("data", data); + + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + rw.put("DK", ((PacketSection) ret.get("DK")).getString()); + rw.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getString()); + return rw; + } + + //16.7 LMK加密密钥转公钥加密输出 ->pass + public RetWrap LMK2SM2(byte[] pk, String key) { + // 获取协议 + Proto71 proto = new Proto71(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + data.put("publicKey", pk); + data.put("key", key); + + packet.put("data", data); + + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + rw.put("keyLength", ((PacketSection) ret.get("keyLength")).getString()); + rw.put("key", ((PacketSection) ret.get("key")).getString()); + return rw; + } + + //16.8 ECC密钥生成 -> code = 129 ( 0x81 ) msg = 未定义的错误 (服务器代码问题) + public RetWrap genKeyPair(int nid, int index) { + //ProtocolRender render = pset.getProtocolReqRender("E2"); + ProtoE4 proto = new ProtoE4(); + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("nid", nid); + data.put("flg", 'P'); + data.put("index", index); + data.put("startTime", 20201019); + data.put("endTime", 20201020); + + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + //ProtocolParser parser = pset.getProtocolResParse(); + + Map ret = null; + Packet p = proto.parse(bb); + ret = p.toMap(); + + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + + rw.put(SydApi.RET_PUBLIC_KEY, ((PacketSection) ret.get("publicKey")).getBytes()); + rw.put(SydApi.RET_PRIVATE_KEY, ((PacketSection) ret.get("privateKey")).getBytes()); + + return rw; + } + + //15.7计算HASH散列值(MD5\SHA1\SHA256)(+) -> pass + public RetWrap conutHash(int hashType, int packSn, byte[] msg, byte[] filterData) { + Proto7D proto = new Proto7D(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("hashType$option", hashType); + data.put("packSn$option", packSn); + data.put("msg", msg); + data.put("filterData", filterData); + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap rw = new RetWrap(); + if (packSn == 1 || packSn == 2) { + rw.put("filterData", ((PacketSection) ret.get("filterData")).getBytes()); + } else { + rw.put("hash", ((PacketSection) ret.get("hash")).getBytes()); + } + return rw; + } + } + } + + //10.1装载对称密钥至用户存储区(=) -> pass + public Boolean loadKey(String index, String key, String checkValue) { + ProtoLB proto = new ProtoLB(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("indexFlag", "K"); + data.put("index", index); + data.put("key", key); + data.put("checkFlag", "P"); + data.put("checkValue", checkValue); + + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + Date dt = new Date(); + String startTime = sdf.format(dt); + data.put("startTime", startTime); + + Calendar c = Calendar.getInstance(); + c.setTime(dt); + c.add(Calendar.DATE, 1); + dt = c.getTime(); + String endTime = sdf.format(dt); + data.put("endTime", endTime); + data.put("businessKey", "N"); + + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + } + return true; + } + + //10.2从用户存储区读取对称密钥(=) -> pass(秘钥校验值暂时无法获取) + public RetWrap readKey(String index) { + ProtoLF proto = new ProtoLF(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("indexFlag", "K"); + data.put("index", index); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap rw = new RetWrap(); + byte[] keys = ((PacketSection) ret.get("key")).getBytes(); + byte[] keyHeads = ((PacketSection) ret.get("keyHead")).getBytes(); + byte[] bs= new byte[keys.length + keyHeads.length]; + System.arraycopy(keyHeads, 0, bs, 0, keyHeads.length); + System.arraycopy(keys, 0, bs, keyHeads.length, keys.length); + rw.put("key", bs); + //rw.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return rw; + } + } + } + + //10.3更新对称密钥至用户存储区(=) -> pass + public Boolean updateKey(String index, String key, String checkValue) { + ProtoLB proto = new ProtoLB(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("indexFlag", "K"); + data.put("index", index); + data.put("key", key); + data.put("checkFlag", "P"); + data.put("checkValue", checkValue); + + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + Date dt = new Date(); + String startTime = sdf.format(dt); + data.put("startTime", startTime); + + Calendar c = Calendar.getInstance(); + c.setTime(dt); + c.add(Calendar.DATE, 1); + dt = c.getTime(); + String oldEndTime = sdf.format(dt); + data.put("oldEndTime", oldEndTime); + + c.setTime(new Date()); + c.add(Calendar.DATE, 2); + dt = c.getTime(); + String endTime = sdf.format(dt); + data.put("endTime", endTime); + + data.put("businessKey", "N"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + } + return true; + } + + //9.2 数据转加密指令(Y0)(=) -> pass (注:密文数据那项不一定需要传加密出来的数据) + public byte[] switchEncryY(String srcType, int sca, String desKeyType, int dca, int roundModel, String sDEK, String dDEK, byte[] infoData, String vector) { + ProtoY0 proto = new ProtoY0(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("srcKeyType", srcType); + data.put("sca$option", sca); + data.put("desKeyType", desKeyType); + data.put("dca$option", dca); + data.put("roundModel$option", roundModel); + data.put("sDEK", sDEK); + data.put("dDEK", dDEK); + data.put("infoData", infoData); + data.put("vector", vector.getBytes()); + data.put("businessKey", "N"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + return ((PacketSection) ret.get("cipherData")).getBytes(); + } + } + } + + //8.3用对大消息生成MAC(MAB)(*) -> pass + public RetWrap genMAB(int packSn, int keyType, int mode, String key, byte[] iv, byte[] msg) { + ProtoMS proto = new ProtoMS(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("block$option", packSn); + data.put("keyType$option", keyType); + data.put("mode$option", mode); + data.put("dataType$option", 0); + data.put("key", key); + if (null != iv) { + data.put("iv", iv); + } + data.put("msg", msg); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap rw = new RetWrap(); + rw.put("MAB", ((PacketSection) ret.get("MAB")).getBytes()); + return rw; + } + } + } + + //7.1生成一个随机的PIN(=) -> pass 不能传算法标识和加密算法这两项,否则报错 + public String genPIN(String account) { + ProtoJA proto = new ProtoJA(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("account", account); + data.put("pinLen", 10); //pinLen是必传项 + /* data.put("algorithmKey", "P"); + data.put("encryptionAlg$option", 0);*/ + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + return ((PacketSection) ret.get("pinBlock")).getString(); + } + } + } + + //7.2解密PINBLOCK, 并打印PIN 明文(=) -> : code = -2 ( 0xfffffffe ) msg = 接收数据超时 + public Boolean decryPINBAndPrint(char fileType, String account, int encryptionAlg, String pinBlock) { + + ProtoPE proto = new ProtoPE(); + + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("fileType", fileType); + data.put("account", account); + data.put("algorithmKey", "P"); + data.put("encryptionAlg$option", encryptionAlg); + data.put("pinBlock", pinBlock); + data.put("pinLen", 10); + data.put("print", ""); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + ByteBuffer b2 = syncRead(null); + System.out.println("r " + Util.bytes2HexString(b2.array())); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1])) + ) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + return true; + } + + //7.3将PINBLOCK从一个ZPK翻译到另一个ZPK(*) -> ->pass + @Override + public String transPINFromZPKToZPK(String zpk1, String zpk2, int sca, int dca, int spt, int dpt, String pin, String account) { + + ProtoCC proto = new ProtoCC(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("sourceZpk", zpk1); + data.put("purposeZpk", zpk2); + data.put("algorithmKey", 'P'); + data.put("sca$option", sca); + data.put("dca$option", dca); + data.put("businessKey", 'N'); + data.put("sourcePinBlock", pin); + data.put("sourcePinBlockFormat", 06); + data.put("purposePinBlockFormat", 06); + data.put("account", account); + data.put("maxLength", 12); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("purposePinBlock")).getString(); + + } + + //7.4将PINBLOCK从ZPK翻译到LMK(*) ->pass ( + public String transPINFromZPKToLMK(String zpk, int sca, int dca, int pt, String pin, String account) { + + ProtoJE proto = new ProtoJE(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("zpk", zpk); + data.put("algorithmKey", 'P'); + data.put("sca$option", sca); + data.put("dca$option", dca); + data.put("businessKey", 'N'); + data.put("PinBlock", pin); + data.put("pinBlockFormat", pt); + data.put("account", account); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("pinBlock")).getString(); + } + + //7.5将PINBLOCK从LMK翻译到ZPK(*) ->pass + public String transPINFromLMKToZPK(String zpk, int sca, int dca, int pt, String pin, String account) { + + ProtoJG proto = new ProtoJG(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("zpk", zpk); + data.put("algorithmKey", 'P'); + data.put("sca$option", sca); + data.put("dca$option", dca); + data.put("businessKey", 'N'); + data.put("PinBlock", pin); + data.put("pinBlockFormat", pt); + data.put("account", account); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("pinBlock")).getString(); + } + + //7.6将PINBLOCK从TPK翻译到ZPK(=) -> pass + public String transPINFromTPKToZPK(String tpk, String zpk, int sca, int dca, int spt, int dpt, String pin, String account) { + ProtoCA proto = new ProtoCA(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("sourceZpk", tpk); + data.put("purposeZpk", zpk); + data.put("algorithmKey", 'P'); + data.put("sca$option", sca); + data.put("dca$option", dca); + data.put("businessKey", 'N'); + data.put("sourcePinBlock", pin); + data.put("sourcePinBlockFormat", spt); + data.put("purposePinBlockFormat", dpt); + data.put("account", account); + data.put("maxLength", 12); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("purposePinBlock")).getString(); + } + + //7.7将PINBLOCK从TPK翻译到LMK(=) -> pass + public String transPINFromTPKToLMK(String zpk, int sca, int dca, int pt, String pin, String account) { + + ProtoJC proto = new ProtoJC(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("zpk", zpk); + data.put("algorithmKey", 'P'); + data.put("sca$option", sca); + data.put("dca$option", dca); + data.put("businessKey", 'N'); + data.put("PinBlock", pin); + data.put("pinBlockFormat", pt); + data.put("account", account); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("pinBlock")).getString(); + } + + //7.8加密一个明文的PIN(*) -> pass + public String encryPIN(int alg, String pin, String account) { + + ProtoBA proto = new ProtoBA(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("alg$option", alg); + data.put("pin", pin); + data.put("account", account); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + return ((PacketSection) ret.get("pinBlock")).getString(); + } + + //7.9解密一个已加密的PIN(*) -> 只解出原PIn,缺少参考数这一项 + public String decryPIN(int alg, String PINBLOCK, String account) { + + ProtoNG proto = new ProtoNG(); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("alg$option", alg); + data.put("PINBLOCK", PINBLOCK); + data.put("account", account); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb, packet); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1]))) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + return ((PacketSection) ret.get("PIN")).getString(); + } + } + + //7.10将PINBLOCK从一个密钥翻译到另一个密钥 -> pass + public String transPinFrOneKeyToAno(String srcKeyType, String desKeyType, String srcKey, String desKey, int sca, int dca, String sPin, String primaryAccount) { + ProtoCB proto = new ProtoCB(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("srcKeyType", srcKeyType); + data.put("desKeyType", desKeyType); + //srcKey = "XK" + srcKey; + data.put("srcKey", srcKey); + data.put("desKey", desKey); + data.put("algorithmKey", 'P'); + data.put("dca$option", dca); + data.put("sca$option", sca); + data.put("sPin", sPin); + data.put("sPinType$option", 0); + data.put("dPinType$option", 0); + data.put("primaryAccount", primaryAccount); + data.put("businessKey", 'N'); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + return ((PacketSection) ret.get("dPin")).getString(); + } + } + } + + //6.1生成一个TAK(=) -> pass + public RetWrap genTAK(String tmk) { + ProtoHA proto = new ProtoHA(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("tmk", tmk); + data.put("businessKey", 'N'); + data.put("separator", ";"); + data.put("tmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + byte[] lmks = ((PacketSection) ret.get("takLmk")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("takLmkHead")).getBytes(); + byte[] bs1 = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs1, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs1, lmkHeads.length, lmks.length); + retWrap.put("lmkKey", bs1); + + byte[] tmks = ((PacketSection) ret.get("takTmk")).getBytes(); + byte[] tmkHeads = ((PacketSection) ret.get("takTmkHead")).getBytes(); + byte[] bs2 = new byte[tmks.length + tmkHeads.length]; + System.arraycopy(tmkHeads, 0, bs2, 0, tmkHeads.length); + System.arraycopy(tmks, 0, bs2, tmkHeads.length, tmks.length); + retWrap.put("tmkKey", bs2); + + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + } + + //6.2将TAK从ZMK转为LMK加密(=) -> PASS + public RetWrap transTAKFromZMKToLMK(String zmk, String tak) { + ProtoMF proto = new ProtoMF(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("zmk", zmk); + data.put("tak", tak); + data.put("businessKey", 'N'); + data.put("separator", ";"); + data.put("zmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + byte[] lmks = ((PacketSection) ret.get("takLmk")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("takLmkHead")).getBytes(); + byte[] bs = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs, lmkHeads.length, lmks.length); + retWrap.put("lmkKey", bs); + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + } + + //6.3将TAK从LMK转为ZMK加密(=) -> PASS + public RetWrap transTAKFromLMKToZMK(String zmk, String tak) { + ProtoMG proto = new ProtoMG(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("zmk", zmk); + data.put("tak", tak); + data.put("businessKey", 'N'); + data.put("separator", ";"); + data.put("zmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + byte[] zmks = ((PacketSection) ret.get("takZmk")).getBytes(); + byte[] zmkHeads = ((PacketSection) ret.get("takZmkHead")).getBytes(); + byte[] bs = new byte[zmks.length + zmkHeads.length]; + System.arraycopy(zmkHeads, 0, bs, 0, zmkHeads.length); + System.arraycopy(zmks, 0, bs, zmkHeads.length, zmks.length); + retWrap.put("zmkKey", bs); + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + } + + //6.4将TAK从LMK转为TMK加密(=) -> PASS + public RetWrap transTAKFromLMKToTMK(String tmk, String tak) { + ProtoAG proto = new ProtoAG(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("tmk", tmk); + data.put("tak", tak); + data.put("businessKey", 'N'); + data.put("separator", ";"); + data.put("tmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + byte[] tmks = ((PacketSection) ret.get("tmkTak")).getBytes(); + byte[] tmkHeads = ((PacketSection) ret.get("tmkTakHead")).getBytes(); + byte[] bs = new byte[tmks.length + tmkHeads.length]; + System.arraycopy(tmkHeads, 0, bs, 0, tmkHeads.length); + System.arraycopy(tmks, 0, bs, tmkHeads.length, tmks.length); + retWrap.put("tmkKey", bs); + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + } + + //5.1生成一个TMK、TPK或PVK加密下的新密钥(=) -> PASS + public RetWrap genKeyByTMKOrTPKOrPVK(String tmk) { + ProtoHC proto = new ProtoHC(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("tmk", tmk); + data.put("businessKey", 'N'); + data.put("separator", ";"); + data.put("tmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + byte[] lmks = ((PacketSection) ret.get("lmkKey")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("lmkHead")).getBytes(); + byte[] bs1 = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs1, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs1, lmkHeads.length, lmks.length); + retWrap.put("lmkKey", bs1); + + byte[] tmks = ((PacketSection) ret.get("tmkKey")).getBytes(); + byte[] tmkHeads = ((PacketSection) ret.get("tmkHead")).getBytes(); + byte[] bs2 = new byte[tmks.length + tmkHeads.length]; + System.arraycopy(tmkHeads, 0, bs2, 0, tmkHeads.length); + System.arraycopy(tmks, 0, bs2, tmkHeads.length, tmks.length); + retWrap.put("tmkKey", bs2); + + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + } + + //5.2将TMK、TPK或PVK从LMK转为另一TMK、TPK或PVK加密(+) -> PASS + public RetWrap tranKeyByTMKToAno(String tmkNow, String tmkStorage) { + ProtoAE proto = new ProtoAE(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("tmkNow", tmkNow); + data.put("tmkStorage", tmkStorage); + data.put("separator", ";"); + data.put("tmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + byte[] tmks = ((PacketSection) ret.get("tmkKey")).getBytes(); + byte[] tmkHeads = ((PacketSection) ret.get("tmkHead")).getBytes(); + byte[] bs = new byte[tmks.length + tmkHeads.length]; + System.arraycopy(tmkHeads, 0, bs, 0, tmkHeads.length); + System.arraycopy(tmks, 0, bs, tmkHeads.length, tmks.length); + retWrap.put("tmkKey", bs); + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + } + + //5.3将TMK、TPK或PVK从ZMK转为LMK加密(=) -> PASS + public RetWrap tranKeyByTMKFromZMKToLMK(String zmk, String tmk) { + ProtoFC proto = new ProtoFC(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("zmk", zmk); + data.put("tmk", tmk); + data.put("businessKey", 'N'); + data.put("separator", ";"); + data.put("zmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + byte[] tmks = ((PacketSection) ret.get("tmkKey")).getBytes(); + byte[] tmkHeads = ((PacketSection) ret.get("tmkHead")).getBytes(); + byte[] bs = new byte[tmks.length + tmkHeads.length]; + System.arraycopy(tmkHeads, 0, bs, 0, tmkHeads.length); + System.arraycopy(tmks, 0, bs, tmkHeads.length, tmks.length); + retWrap.put("tmkKey", bs); + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + } + + //5.4将TMK、TPK或PVK从LMK转为ZMK加密(=) -> PASS + public RetWrap tranKeyByTMKFromLMKToZMK(String zmk, String tmk) { + ProtoFE proto = new ProtoFE(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("zmk", zmk); + data.put("tmk", tmk); + data.put("businessKey", 'N'); + data.put("separator", ";"); + data.put("zmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + byte[] tmks = ((PacketSection) ret.get("tmkKey")).getBytes(); + byte[] tmkHeads = ((PacketSection) ret.get("tmkHead")).getBytes(); + byte[] bs = new byte[tmks.length + tmkHeads.length]; + System.arraycopy(tmkHeads, 0, bs, 0, tmkHeads.length); + System.arraycopy(tmks, 0, bs, tmkHeads.length, tmks.length); + retWrap.put("tmkKey", bs); + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + } + + //4.1生成一个ZEK/ZAK(=) -> pass + public RetWrap genZEKOrZAK(int key, String zmk) { + ProtoFI proto = new ProtoFI(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("key$option", key); + data.put("zmk", zmk); + data.put("businessKey", 'N'); + data.put("separator", ";"); + data.put("zmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + if (0 == key) { + byte[] lmks = ((PacketSection) ret.get("zekLmk")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("zekLmkHead")).getBytes(); + byte[] bs1 = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs1, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs1, lmkHeads.length, lmks.length); + retWrap.put("lmkKey", bs1); + + byte[] zmks = ((PacketSection) ret.get("zekZmk")).getBytes(); + byte[] zmkHeads = ((PacketSection) ret.get("zekZmkHead")).getBytes(); + byte[] bs2 = new byte[zmks.length + zmkHeads.length]; + System.arraycopy(zmkHeads, 0, bs2, 0, zmkHeads.length); + System.arraycopy(zmks, 0, bs2, zmkHeads.length, zmks.length); + retWrap.put("zmkKey", bs2); + } else { + byte[] lmks = ((PacketSection) ret.get("zakLmk")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("zakLmkHead")).getBytes(); + byte[] bs1 = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs1, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs1, lmkHeads.length, lmks.length); + retWrap.put("lmkKey", bs1); + + byte[] zmks = ((PacketSection) ret.get("zakZmk")).getBytes(); + byte[] zmkHeads = ((PacketSection) ret.get("zakZmkHead")).getBytes(); + byte[] bs2 = new byte[zmks.length + zmkHeads.length]; + System.arraycopy(zmkHeads, 0, bs2, 0, zmkHeads.length); + System.arraycopy(zmks, 0, bs2, zmkHeads.length, zmks.length); + retWrap.put("zmkKey", bs2); + } + + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + } + + //4.2将ZEK/ZAK从ZMK转为LMK加密(=) -> pass + public RetWrap tranZEAKFromZMKToLMK(int key, String zmk, String zekOrzak) { + ProtoFK proto = new ProtoFK(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("key$option", key); + data.put("zmk", zmk); + data.put("zekOrzak", zekOrzak); + data.put("businessKey", 'N'); + data.put("separator", ";"); + data.put("zmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + if (0 == key) { + byte[] lmks = ((PacketSection) ret.get("zekLmk")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("zekLmkHead")).getBytes(); + byte[] bs1 = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs1, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs1, lmkHeads.length, lmks.length); + retWrap.put("lmkKey", bs1); + } else { + byte[] lmks = ((PacketSection) ret.get("zakLmk")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("zakLmkHead")).getBytes(); + byte[] bs1 = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs1, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs1, lmkHeads.length, lmks.length); + retWrap.put("lmkKey", bs1); + } + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + } + + //4.3将ZEK/ZAK从LMK转为ZMK加密(=) -> pass + public RetWrap tranZEAKFromLMKToZMK(int key, String zmk, String zekOrzak) { + ProtoFM proto = new ProtoFM(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("key$option", key); + data.put("zmk", zmk); + data.put("zekOrzak", zekOrzak); + data.put("businessKey", 'N'); + data.put("separator", ";"); + data.put("zmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + if (0 == key) { + byte[] zmks = ((PacketSection) ret.get("zekZmk")).getBytes(); + byte[] zmkHeads = ((PacketSection) ret.get("zekZmkHead")).getBytes(); + byte[] bs1 = new byte[zmks.length + zmkHeads.length]; + System.arraycopy(zmkHeads, 0, bs1, 0, zmkHeads.length); + System.arraycopy(zmks, 0, bs1, zmkHeads.length, zmks.length); + retWrap.put("zmkKey", bs1); + } else { + byte[] zmks = ((PacketSection) ret.get("zakZmk")).getBytes(); + byte[] zmkHeads = ((PacketSection) ret.get("zakZmkHead")).getBytes(); + byte[] bs1 = new byte[zmks.length + zmkHeads.length]; + System.arraycopy(zmkHeads, 0, bs1, 0, zmkHeads.length); + System.arraycopy(zmks, 0, bs1, zmkHeads.length, zmks.length); + retWrap.put("zmkKey", bs1); + } + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + } + + //3.1生成一个ZPK(=) -> pass + public RetWrap genZPK(String zmk) { + ProtoIA proto = new ProtoIA(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("zmk", zmk); + data.put("businessKey", 'N'); + data.put("separator", ";"); + data.put("zmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + + byte[] lmks = ((PacketSection) ret.get("zpkLmk")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("zpkLmkHead")).getBytes(); + byte[] bs1 = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs1, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs1, lmkHeads.length, lmks.length); + retWrap.put("lmkKey", bs1); + + byte[] zmks = ((PacketSection) ret.get("zpkZmk")).getBytes(); + byte[] zmkHeads = ((PacketSection) ret.get("zpkZmkHead")).getBytes(); + byte[] bs2 = new byte[zmks.length + zmkHeads.length]; + System.arraycopy(zmkHeads, 0, bs2, 0, zmkHeads.length); + System.arraycopy(zmks, 0, bs2, zmkHeads.length, zmks.length); + retWrap.put("zmkKey", bs2); + + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + } + + //3.2将ZPK由ZMK转为LMK加密(=) -> pass + public RetWrap tranZPKFromZMKToLMK(String zmk, String zpk) { + ProtoFA proto = new ProtoFA(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("zmk", zmk); + data.put("zpk", zpk); + data.put("businessKey", 'N'); + data.put("separator", ";"); + data.put("zmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + + byte[] zpks = ((PacketSection) ret.get("zpk")).getBytes(); + byte[] zpkHeads = ((PacketSection) ret.get("zpkHead")).getBytes(); + byte[] bs1 = new byte[zpks.length + zpkHeads.length]; + System.arraycopy(zpkHeads, 0, bs1, 0, zpkHeads.length); + System.arraycopy(zpks, 0, bs1, zpkHeads.length, zpks.length); + retWrap.put("zpkKey", bs1); + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + } + + //3.3将ZPK由LMK转为ZMK加密 -> pass + public RetWrap tranZPKFromLMKToZMK(String zmk, String zpk) { + ProtoGC proto = new ProtoGC(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("zmk", zmk); + data.put("zpk", zpk); + data.put("businessKey", 'N'); + data.put("separator", ";"); + data.put("zmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + + byte[] zpks = ((PacketSection) ret.get("zpk")).getBytes(); + byte[] zpkHeads = ((PacketSection) ret.get("zpkHead")).getBytes(); + byte[] bs1 = new byte[zpks.length + zpkHeads.length]; + System.arraycopy(zpkHeads, 0, bs1, 0, zpkHeads.length); + System.arraycopy(zpks, 0, bs1, zpkHeads.length, zpks.length); + retWrap.put("zpkKey", bs1); + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + } + + //2.1生成并打印一个ZMK成份(=) -> : code = 23 ( 0x17 ) msg = 未定义的错误 + public RetWrap genZMKAndPrint() { + ProtoOC proto = new ProtoOC(); + + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("print", ""); + data.put("delimiter", '|'); + data.put("zmkSolution", "Z"); + data.put("lmkSolution", "Z"); + data.put("keyCheckType", "0"); + data.put("businessKey", 'N'); + + // 渲染发送 + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + // 响应解析 + bb = syncRead(syncSend(bb)); + } + + Packet p = proto.parse(bb); + Map ret = p.toMap(); + + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + byte[] be = error.getBytes(); + if ( + (0 != (be[0] ^ be[1])) + + ) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + + RetWrap retWrap = new RetWrap(); + byte[] lmks = ((PacketSection) ret.get("key")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("keyHead")).getBytes(); + byte[] bs = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs, lmkHeads.length, lmks.length); + retWrap.put("lmkKey", bs); + + return retWrap; + } + + //1.4由2-9个密钥成份组成一个密钥(=) -> : code = 23 ( 0x17 ) msg = 未定义的错误 + public RetWrap composeKey(String keyType, String[] keys) { + + ProtoA4 proto = new ProtoA4(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + int len = 0; + for (String key : keys) { + len += key.length(); + } + len = len / 2; + + byte[] ks = new byte[len]; + len = 0; + for (String key : keys) { + byte[] bs = Util.hexString2Bytes(key); + System.arraycopy(bs, 0, ks, len, bs.length); + len += bs.length; + } + + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + + data.put("num", keys.length); + data.put("keyType", keyType); + data.put("lmkSolution", 'X'); + data.put("keys", ks); + data.put("businessKey", 'N'); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap retWrap = new RetWrap(); + byte[] lmks = ((PacketSection) ret.get("key")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("keyHead")).getBytes(); + byte[] bs = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs, lmkHeads.length, lmks.length); + retWrap.put("lmkKey", bs); + retWrap.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return retWrap; + } + } + + } + + //1.1生成一个对称密钥(*) -> pass (对比之前添加了可产生ZMK加密下的密钥) + public RetWrap genSymKey(int mode,String keyType, char solution,String zmk) { + ProtoA0 proto = new ProtoA0(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("mode$option",mode); + data.put("keyType", keyType); + data.put("solution", solution); + data.put("zmk", zmk); + data.put("keySolution", 'X'); + data.put("businessKey", 'N'); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap rw = new RetWrap(); + byte[] lmks = ((PacketSection) ret.get("lmk")).getBytes(); + byte[] lmkHeads = ((PacketSection) ret.get("lmkHead")).getBytes(); + byte[] bs1 = new byte[lmks.length + lmkHeads.length]; + System.arraycopy(lmkHeads, 0, bs1, 0, lmkHeads.length); + System.arraycopy(lmks, 0, bs1, lmkHeads.length, lmks.length); + rw.put("lmkKey", bs1); + if(1== mode) { + byte[] zmks = ((PacketSection) ret.get("zmk")).getBytes(); + byte[] zmkHeads = ((PacketSection) ret.get("zmkHead")).getBytes(); + byte[] bs2 = new byte[zmks.length + zmkHeads.length]; + System.arraycopy(zmkHeads, 0, bs2, 0, zmkHeads.length); + System.arraycopy(zmks, 0, bs2, zmkHeads.length, zmks.length); + rw.put("zmkKey", bs2); + } + + rw.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getBytes()); + return rw; + } + } + } + + //17.9 角色认证(+) -> -> : code = 2 ( 0x2 ) msg = 签名验证错误 + public RetWrap roleVerify(String roleInfo) { + Proto61 proto = new Proto61(); + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + + packet.put("data", data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("roleInfo",roleInfo.getBytes()); + + ByteBuffer bb = proto.rend(packet); + + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + + Map ret = null; + Packet p = proto.parse(bb, packet); + ret = p.toMap(); + if (!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())) { + throw new SydApiException("包序号不匹配", -4); + } else { + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } else { + RetWrap rw = new RetWrap(); + rw.put("roleType", ((PacketSection) ret.get("roleType")).getInt()); + rw.put("roleId", ((PacketSection) ret.get("roleId")).getInt()); + return rw; + } + } + } + + //16.3由私钥解密随机密钥并以LMK加密输出(+) -> pass + @Override + public RetWrap SM2ConfirmSessionKey(String sk, String cipherKey) { + // 获取协议 + //ProtocolRender render = pset.getProtocolReqRender("73"); + Proto73 proto = new Proto73(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + //String sk = "00010000C530EFBC1971D6526BDAB640370EE9197BFB0D78F88417C1ED49981FFEF226980000000000000000000000000000000000000000000000000000000000000000"; + //data.put("privateKey", Util.hexString2Bytes(sk)); + data.put("privateKeyTag", "999999999999999999999999999"); + data.put("privateKey", Util.hexString2Bytes(sk)); + data.put("cipherKey", Util.hexString2Bytes(cipherKey)); + data.put("lmk", "X"); + + packet.put("data", data); + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb); + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + + rw.put(SydApi.RET_SESSION_KEY, ((PacketSection) ret.get("lmkHead")).getString() + + ((PacketSection) ret.get("lmk")).getString() + ); + + rw.put(SydApi.RET_KCV, ((PacketSection) ret.get("keyCheck")).getString()); + + return rw; + } + + //17.11 获取应用密钥明文(+) -> PASS + public RetWrap getPlainText(String key, int checkAlg){ + + ProtoAB proto = new ProtoAB(); + // 填充数据 + PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + + data.put("keyType", "002"); + data.put("key", key.getBytes()); + data.put("keyCheck", 'P'); + data.put("checkAlg$option", checkAlg); + data.put("businessKey", 'N'); + + packet.put("data", data); + // 渲染发送 耗时长 + ByteBuffer bb = proto.rend(packet); + synchronized (this) { + + // 响应解析 + bb = syncRead(syncSend(bb)); + } + //ProtocolParser parser = pset.getProtocolResParse(); + Packet p = proto.parse(bb,packet); + Map ret = p.toMap(); + if ( + !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) + ) { + throw new SydApiException("包序号不匹配", -4); + } + ret = (Map) ret.get("data"); + PacketSection error = (PacketSection) ret.get("error"); + if (!"00".equals(error.getString())) { + throw new SydApiException(error.getInfo(), error.autoInt()); + } + RetWrap rw = new RetWrap(); + + rw.put("keyCheck", ((PacketSection) ret.get("keyCheck")).getString()); + rw.put("key1", ((PacketSection) ret.get("key1")).getString()); + rw.put("key2", ((PacketSection) ret.get("key2")).getString()); + + return rw; + } + + @Override + public byte[] directBytes(byte[] data){ + //初始化一个和byte长度一样的bb + ByteBuffer bb = ByteBuffer.allocate(data.length); + // 数组放到bb中 + bb.put(data); + + //发送数据,解析 + synchronized (this) { + bb = syncRead(syncSend(bb)); + } + //重置 limit 和postion 值 + bb.flip(); + //获取bb中有效大小 + int len=bb.limit() - bb.position(); + + byte [] bytes=new byte[len]; + for (int i = 0; i < bytes.length; i++) { + bytes[i]=bb.get(); + } + return bytes; + }; + +} + + + + +//014100000000000000004530 +// 30 +// 38 +// 32 +// 30 +// 583733463443313841433445453533363345363135323531333434413643324139 +// 30 +// 30 +// 31 +// 30303030 +// 32 +// 0000000000000000000000000000000000000000000000000000000000000000 +// 304537 = 0E7 = 231 +// 462 = 231 +// +// 39333030303320E2809320E6ADA4E6A8A1E69DBFE7B1BBE59E8BE4B88DE883BDE794A8E69DA5E7949FE68890E5AF86E992A50A39313030303120E2809320E5AF86E992A5E6A8A1E69DBFE6A0BCE5BC8FE99499E8AFAF0A3631303030302D20E5AF86E992A5E7B1BBE59E8BE99499E8AFAF0A3938303030312D20E5BD93E5898DE7B3BBE7BB9FE4B88DE694AFE68C81E79A84E7AE97E6B3950A3635303030302D20E7949FE68890E5AF86E992A5E697B6E5AF86E992A5E5B7B2E5AD98E59CA80A3635303030312D20E69BB4E696B0E5AF86E992A5E697B6E5AF86E992A5E4B88DE5AD98E59CA80A diff --git a/src/main/java/racal/sunyard/main/SydApiBuilder.java b/src/main/java/racal/sunyard/main/SydApiBuilder.java new file mode 100644 index 0000000..505c2a8 --- /dev/null +++ b/src/main/java/racal/sunyard/main/SydApiBuilder.java @@ -0,0 +1,105 @@ +package racal.sunyard.main; + +import com.sunyard.SydApi; +import com.sunyard.SydApiException; + +public class SydApiBuilder { + + private String ip; + private int port = 8889; + private String pwd; + private int timeout = 3000; + private boolean debug = false; + private boolean useEBCDMode = false; + private boolean useETEncrypt = false; + private ClassLoader classLoader; + + + public SydApi build() throws ClassNotFoundException, IllegalAccessException, InstantiationException { + + if ( null == ip || "".equals(ip) ){ + throw new SydApiException("ip 配置不正确", 40000); + } + + if ( debug ){ + System.setProperty("com.sunyard.sydapi4j.debug", "true"); + } + + Class clazz = classLoader.loadClass("racal.sunyard.main.SydApi4j"); + Object api = clazz.newInstance(); + + +// SydApi4j api = new SydApi4j(); +// api.keepBuilder(this); +// api.connect( ip , port, pwd, timeout); + return (SydApi) api; + } + + + public ClassLoader getClassLoader() { + return classLoader; + } + + public void setClassLoader(ClassLoader classLoader) { + this.classLoader = classLoader; + } + + public String getIp() { + return ip; + } + + public SydApiBuilder setIp(String ip) { + this.ip = ip; + return this; + } + + public int getPort() { + return port; + } + + public SydApiBuilder setPort(int port) { + this.port = port; + return this; + } + + public String getPwd() { + return pwd; + } + + public SydApiBuilder setPwd(String pwd) { + this.pwd = pwd; + return this; + } + + public int getTimeout() { + return timeout; + } + + public SydApiBuilder setTimeout(int timeout) { + this.timeout = timeout; + return this; + } + + public boolean isUseEBCDMode() { + return useEBCDMode; + } + + public SydApiBuilder useEBCDMode() { + this.useEBCDMode = true; + return this; + } + + public boolean isUseETEncrypt() { + return useETEncrypt; + } + + public SydApiBuilder useETEncrypt() { + this.useETEncrypt = true; + return this; + } + + public SydApiBuilder useDebugMode() { + this.debug = true; + return this; + } +} diff --git a/src/main/java/racal/sunyard/main/TestClass.java b/src/main/java/racal/sunyard/main/TestClass.java new file mode 100644 index 0000000..1851b08 --- /dev/null +++ b/src/main/java/racal/sunyard/main/TestClass.java @@ -0,0 +1,10 @@ +package racal.sunyard.main; + +public class TestClass implements TestInf{ + + @Override + public void run() { + System.out.println( "class=" + TestClass.class.getName() ); + System.out.println( "classloader" + TestClass.class.getClassLoader().getClass().getName() ); + } +} diff --git a/src/main/java/racal/sunyard/main/TestDecryptDataWithFile.java b/src/main/java/racal/sunyard/main/TestDecryptDataWithFile.java new file mode 100644 index 0000000..568a111 --- /dev/null +++ b/src/main/java/racal/sunyard/main/TestDecryptDataWithFile.java @@ -0,0 +1,40 @@ +package racal.sunyard.main; + +import com.sunyard.SydApi; + +import java.util.Scanner; + +import java.io.UnsupportedEncodingException; + + +public class TestDecryptDataWithFile +{ + + public static void main(String[] args) throws Exception { + + System.out.println("SydApi 测试程序启动"); + SydApi key = new SydApi4j().connect("192.168.0.71",8889,null,10000); + System.out.println("连接成功"); + + String seesionKey = "X246F7CEC2EF09A7A8F0475C6B1CE4B05"; + String inputPath = "c:\\Users\\KJ-Z285\\Desktop\\dataEncrypt.txt"; + String outputPath = "c:\\Users\\KJ-Z285\\Desktop\\dataDncrypt.txt"; + + System.out.println("[Tips]:" + "正在解密,请稍候...\n" ); + + if (!key.SYMDecryptDataWithFile(0x01, seesionKey, inputPath, outputPath)) + { + System.out.println("[Error]:" + "解密失败!\n" ); + } + + System.out.println("[Tips]:" + "解密完成!\n" ); + + + System.out.println("执行结束\n\n" ); + key.disconnect(); +// +// Scanner scanner = new Scanner(System.in); +// String in = scanner.nextLine(); + + } +} diff --git a/src/main/java/racal/sunyard/main/TestInf.java b/src/main/java/racal/sunyard/main/TestInf.java new file mode 100644 index 0000000..afe48aa --- /dev/null +++ b/src/main/java/racal/sunyard/main/TestInf.java @@ -0,0 +1,5 @@ +package racal.sunyard.main; + +public interface TestInf { + public void run(); +} diff --git a/src/main/java/racal/sunyard/main/Vars.kt b/src/main/java/racal/sunyard/main/Vars.kt new file mode 100644 index 0000000..5331bf6 --- /dev/null +++ b/src/main/java/racal/sunyard/main/Vars.kt @@ -0,0 +1,410 @@ +package racal.sunyard.cloud + +import com.sunyard.proto.PacketSection +import java.nio.charset.Charset + + +class Vars(val vars : Map = HashMap()) { + + private inline fun remove(n : List){ + try { + var f : Any? = vars + for( i in 0..n.size-2 ){ + val p = n.get(i) + if ( p.startsWith("[") && p.endsWith("]") ){ + // 数组 + f as MutableList + val istr = p.substring(1, p.length -1) + var index = 0 + if ( "" == istr ){ + index = f.lastIndex + }else{ + index = istr.toInt() + if ( index < 0 ){ + index += f.size + } + } + if (index < 0){ + index = 0 + } + val fp = f.get( index ) + if ( null == fp ){ + return + }else { + f = fp + } + + }else { + f as MutableMap + val fp = f.get( p ) + if ( null == fp){ + return + }else{ + f = fp + } + } + } + + val nl = n.last() + if ( nl.startsWith("[") && nl.endsWith("]") ){ + f as MutableList + val istr = nl.substring(1, nl.length -1) + var index = 0 + if ( "" == istr ){ + index = f.lastIndex + }else{ + index = istr.toInt() + if ( index < 0 ){ + index += f.size + } + } + + if (index < 0){ + index = 0 + } + f.removeAt( index ) + + }else{ + f as MutableMap + f.remove(nl) + } + }catch ( e : ClassCastException){ + throw e + } + + + } + + private inline fun _set(n : List, data : Any) { + try { + var f : Any? = vars + for( i in 0..n.size-2 ){ + val p = n.get(i) + if ( p.startsWith("[") && p.endsWith("]") ){ + // 数组 + f as MutableList + val istr = p.substring(1, p.length -1) + var index = 0 + if ( "" == istr ){ + index = f.size + }else{ + index = istr.toInt() + if ( index < 0 ){ + index += f.size + } + } + if (index < 0){ + index = 0 + } + var fp = f.get( index ) + if ( null == fp ){ + // 参考下一级推断类型 + val pp = n.get(i + 1) + if( pp.startsWith("[") && pp.endsWith("]") ){ + fp = mutableListOf() + }else{ + fp = mutableMapOf() + } + f.set( index, fp) + } + + f = fp + + + }else { + f as MutableMap + var fp = f.get( p ) + if ( null == fp){ + // 参考下一级推断类型 + val pp = n.get(i + 1) + if( pp.startsWith("[") && pp.endsWith("]") ){ + fp = mutableListOf() + }else{ + fp = mutableMapOf() + } + + f.set( p, fp) + } + f = fp + } + + } + + val nl = n.last() + if ( nl.startsWith("[") && nl.endsWith("]") ){ + f as MutableList + val istr = nl.substring(1, nl.length -1) + var index = 0 + if ( "" == istr ){ + index = f.size + }else{ + index = istr.toInt() + if ( index < 0 ){ + index += f.size + } + } + if (index < 0){ + index = 0 + } + f.add( index , data) + + }else{ + f as MutableMap + f.put(nl, data) + } + }catch ( e : ClassCastException){ + throw e + } + + } + + private inline fun _get(n : List ) : Any? { + try { + var f : Any? = vars + for( i in 0..n.size-1 ){ + val p = n.get(i) + if ( p.startsWith("[") && p.endsWith("]") ){ + // 数组 + f as MutableList + val istr = p.substring(1, p.length -1) + var index = 0 + if ( "" == istr ){ + index = f.lastIndex + }else{ + index = istr.toInt() + if ( index < 0 ){ + index += f.size + } + } + if (index < 0){ + index = 0 + } + val fp = f.get( index ) + if ( null == fp ){ + return null + }else { + f = fp + } + + }else { + f as MutableMap + val fp = f.get( p ) + if ( null == fp){ + return null + }else{ + f = fp + } + } + + } + return f + }catch ( e : ClassCastException){ + throw e + } + } + + + fun cp(from: String, to: String) { + val v = _get( from.split(".") ) + if ( null != v ){ + set(to, v) + } + } + + fun mv(from: String, to: String) { + val v = _get( from.split(".") ) + if ( null != v ){ + set(to, v) + } + rm( from ) + } + + fun map(name: String) { + _set( name.split(".") , mutableMapOf() ) + } + + fun arr(name: String) { + _set( name.split(".") , mutableListOf() ) + } + + + fun get(name : String) : Any{ + val v = _get( name.split(".") ) + if ( null == v ){ + throw RuntimeException("$name 的值为 null") + } + return v + } + + fun getInt(name: String): Int { + val v = _get( name.split(".") ) + if( null == v ){ + return 0 + }else{ + if( v is Int ){ + return v as Int + } else { + return v.toString().toInt() + } + } + } + + fun getStr(name: String): String { + val v = _get( name.split(".") ) + if( null == v ){ + return "" + }else{ + when( v ){ + + v is PacketSection -> return (v as PacketSection).getString() + + v is ByteArray -> return String(v as ByteArray, Charset.forName("UTF-8") ) + + else -> return v.toString() + } + } + } + + fun getMap(name: String): MutableMap { + try { + val v = _get( name.split(".") ) + if( null == v ){ + return mutableMapOf() + }else{ + return v as MutableMap + } + }catch (e : Exception){ + throw java.lang.RuntimeException("$name 的值不是一个 map") + } + } + + fun getArr(name: String): MutableList { + try { + val v = _get( name.split(".") ) + if( null == v ){ + return mutableListOf() + }else{ + return v as MutableList + } + }catch (e : Exception){ + throw java.lang.RuntimeException("$name 的值不是一个 arr") + } + } + + fun put(name: String, value : Any ){ + _set( name.split("."), value ) + } + + + fun set(name: String, value : Any ){ + val names = name.split(".") + + try { + _set( names, value ) + }catch ( e : Exception){ + remove( names ) + _set( names, value ) + } + } + + fun rm(name : String ){ + try { + remove( name.split(".") ) + }catch (e : Exception){ + // pass 忽略异常 + } + + } + + fun contains(name: String) : Boolean { + try { + return null != _get( name.split(".") ) + }catch (e : Exception){ + // TODO 此处遇到过未知错误 故添加 + return false + } + } + + + fun eq(k1: String, k2 : String): Boolean { + try { + val v1 = _get( k1.split(".") ) + val v2 = _get( k2.split(".") ) + if ( null == v1 && null == v2 ){ + return true + } + if ( (null != v1 && null == v2) || + (null == v1 && null != v2) ){ + return false + } + + return v1!!.equals( v2 ) + }catch (e : Exception){ + return false + } + } + + fun eqs(key : String, other : String): Boolean { + try { + val v = getStr( key ) + return other.equals( v ) + }catch (e : Exception){ + return false + } + } + + + fun bool(name: String): Boolean { + val v = _get( name.split(".")) + if ( null == v ) { + return false + }else{ + when( v ){ + + null -> { + return false + } + + is Boolean ->{ + return v + } + + is Array<*> -> { + return v.size > 0 + } + + is List<*> ->{ + return v.size > 0 + } + + is Map<*, *> ->{ + return v.size > 0 + } + + is String -> { + return v.length > 0 + } + } + return true + + } + } + + fun vars(): Set { + return vars.keys + } + + + fun subVars(name : String) : Vars { + if( contains( name ) ){ + val c = get( name ) + if( c is Map<*, *> ){ + return Vars( c as HashMap ) + } + } + + map( name ) + val c = get( name ) + return Vars(c as HashMap) + } +} diff --git a/src/main/java/racal/sunyard/main/Version.java b/src/main/java/racal/sunyard/main/Version.java new file mode 100644 index 0000000..895d73a --- /dev/null +++ b/src/main/java/racal/sunyard/main/Version.java @@ -0,0 +1,9 @@ +package racal.sunyard.main; + +public class Version { + public static void main(String[] args) { + + System.out.println("您使用的本版是: " + SydApi4j.getVersion() ); + + } +} diff --git a/src/main/java/racal/sunyard/main/dto/DTO4D41.kt b/src/main/java/racal/sunyard/main/dto/DTO4D41.kt new file mode 100644 index 0000000..cd70f6f --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO4D41.kt @@ -0,0 +1,1283 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO4D41 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var tag : ByteArray? = null + private var alg : ByteArray? = null + private var type : ByteArray? = null + private var full : ByteArray? = null + private var macLen : ByteArray? = null + private var key : ByteArray? = null + private var mACData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getTagAsBin( ) : ByteArray? { + + return this.tag + } + + + + fun getTagAsStr( ) : String? { + + if( null == this.tag ) return null; + return String(tag!!) + } + + + + fun getTagAsHex( ) : String? { + + if( null == this.tag ) return null; + return Util.bytes2HexString(tag) + } + + + + fun setTag( bytes : ByteArray ) : Data { + + this.tag = bytes + return this + } + + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "3DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + return null + } + + + + fun getTypeAsBin( ) : ByteArray? { + + return this.type + } + + + + fun getTypeAsStr( ) : String? { + + if( null == this.type ) return null; + return String(type!!) + } + + + + fun getTypeAsHex( ) : String? { + + if( null == this.type ) return null; + return Util.bytes2HexString(type) + } + + + + fun setType( bytes : ByteArray ) : Data { + + this.type = bytes + return this + } + + + enum class TypeOptions( val bin : ByteArray ) { + +OPVZAK13DES认证密钥(Util.hexString2Bytes("30")), +OPVZAK2SM4认证密钥(Util.hexString2Bytes("31")), + } + + fun getTypeCn( ) : String? { + + if( null == type ) { return null } + +if( "30".equals(Util.bytes2HexString(this.type) ) ) { + + return "ZAK1(3DES 认证密钥) " + +} + + +if( "31".equals(Util.bytes2HexString(this.type) ) ) { + + return "ZAK2(SM4 认证密钥) " + +} + + return null + } + + + + fun getTypeOptionIndex( ) : Int? { + + if( null == type ) { return null } + +if( "30".equals(Util.bytes2HexString(this.type) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.type) ) ) { + + return 1 + +} + + return null + } + + + + fun getFullAsBin( ) : ByteArray? { + + return this.full + } + + + + fun getFullAsStr( ) : String? { + + if( null == this.full ) return null; + return String(full!!) + } + + + + fun getFullAsHex( ) : String? { + + if( null == this.full ) return null; + return Util.bytes2HexString(full) + } + + + + fun setFull( bytes : ByteArray ) : Data { + + this.full = bytes + return this + } + + + + fun getMacLenAsBin( ) : ByteArray? { + + return this.macLen + } + + + + fun getMacLenAsStr( ) : String? { + + if( null == this.macLen ) return null; + return String(macLen!!) + } + + + + fun getMacLenAsHex( ) : String? { + + if( null == this.macLen ) return null; + return Util.bytes2HexString(macLen) + } + + + + fun setMacLen( bytes : ByteArray ) : Data { + + this.macLen = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getMACDataAsBin( ) : ByteArray? { + + return this.mACData + } + + + + fun getMACDataAsStr( ) : String? { + + if( null == this.mACData ) return null; + return String(mACData!!) + } + + + + fun getMACDataAsHex( ) : String? { + + if( null == this.mACData ) return null; + return Util.bytes2HexString(mACData) + } + + + + fun setMACData( bytes : ByteArray ) : Data { + + this.mACData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + soup.put("tag", Util.hexString2Bytes("50")) + +if( null != tag ){ + + + soup.put("tag", this.tag!!) + } + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != type ){ + + + soup.put("type", this.type!!) + soup.put("type\$option", getTypeOptionIndex()!!) + } + soup.put("full", Util.hexString2Bytes("30")) + +if( null != full ){ + + + soup.put("full", this.full!!) + } + soup.put("macLen", Util.hexString2Bytes("31")) + +if( null != macLen ){ + + + soup.put("macLen", this.macLen!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != mACData ){ + + + soup.put("MACData", this.mACData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + this.tag = Util.hexString2Bytes("50") + +if( soup.containsKey("tag") ){ + + + this.tag = (soup.get("tag") as PacketSection).bytes +} + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("type") ){ + + + this.type = (soup.get("type") as PacketSection).bytes +} + + this.full = Util.hexString2Bytes("30") + +if( soup.containsKey("full") ){ + + + this.full = (soup.get("full") as PacketSection).bytes +} + + this.macLen = Util.hexString2Bytes("31") + +if( soup.containsKey("macLen") ){ + + + this.macLen = (soup.get("macLen") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("MACData") ){ + + + this.mACData = (soup.get("MACData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D41")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D41") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var mAC : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVMAC校验错(Util.hexString2Bytes("3031")), +OPVTAK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return "MAC校验错" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "TAK奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + return null + } + + + + fun getMACAsBin( ) : ByteArray? { + + return this.mAC + } + + + + fun getMACAsStr( ) : String? { + + if( null == this.mAC ) return null; + return String(mAC!!) + } + + + + fun getMACAsHex( ) : String? { + + if( null == this.mAC ) return null; + return Util.bytes2HexString(mAC) + } + + + + fun setMAC( bytes : ByteArray ) : Data { + + this.mAC = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != mAC ){ + + + soup.put("MAC", this.mAC!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("MAC") ){ + + + this.mAC = (soup.get("MAC") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D42")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D42") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO4D43.kt b/src/main/java/racal/sunyard/main/dto/DTO4D43.kt new file mode 100644 index 0000000..d68f37a --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO4D43.kt @@ -0,0 +1,1283 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO4D43 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var tag : ByteArray? = null + private var alg : ByteArray? = null + private var type : ByteArray? = null + private var full : ByteArray? = null + private var macLen : ByteArray? = null + private var key : ByteArray? = null + private var mAC : ByteArray? = null + private var mACData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getTagAsBin( ) : ByteArray? { + + return this.tag + } + + + + fun getTagAsStr( ) : String? { + + if( null == this.tag ) return null; + return String(tag!!) + } + + + + fun getTagAsHex( ) : String? { + + if( null == this.tag ) return null; + return Util.bytes2HexString(tag) + } + + + + fun setTag( bytes : ByteArray ) : Data { + + this.tag = bytes + return this + } + + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "3DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + return null + } + + + + fun getTypeAsBin( ) : ByteArray? { + + return this.type + } + + + + fun getTypeAsStr( ) : String? { + + if( null == this.type ) return null; + return String(type!!) + } + + + + fun getTypeAsHex( ) : String? { + + if( null == this.type ) return null; + return Util.bytes2HexString(type) + } + + + + fun setType( bytes : ByteArray ) : Data { + + this.type = bytes + return this + } + + + enum class TypeOptions( val bin : ByteArray ) { + +OPVZAK13DES认证密钥(Util.hexString2Bytes("30")), +OPVZAK2SM4认证密钥(Util.hexString2Bytes("31")), + } + + fun getTypeCn( ) : String? { + + if( null == type ) { return null } + +if( "30".equals(Util.bytes2HexString(this.type) ) ) { + + return "ZAK1(3DES 认证密钥) " + +} + + +if( "31".equals(Util.bytes2HexString(this.type) ) ) { + + return "ZAK2(SM4 认证密钥) " + +} + + return null + } + + + + fun getTypeOptionIndex( ) : Int? { + + if( null == type ) { return null } + +if( "30".equals(Util.bytes2HexString(this.type) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.type) ) ) { + + return 1 + +} + + return null + } + + + + fun getFullAsBin( ) : ByteArray? { + + return this.full + } + + + + fun getFullAsStr( ) : String? { + + if( null == this.full ) return null; + return String(full!!) + } + + + + fun getFullAsHex( ) : String? { + + if( null == this.full ) return null; + return Util.bytes2HexString(full) + } + + + + fun setFull( bytes : ByteArray ) : Data { + + this.full = bytes + return this + } + + + + fun getMacLenAsBin( ) : ByteArray? { + + return this.macLen + } + + + + fun getMacLenAsStr( ) : String? { + + if( null == this.macLen ) return null; + return String(macLen!!) + } + + + + fun getMacLenAsHex( ) : String? { + + if( null == this.macLen ) return null; + return Util.bytes2HexString(macLen) + } + + + + fun setMacLen( bytes : ByteArray ) : Data { + + this.macLen = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getMACAsBin( ) : ByteArray? { + + return this.mAC + } + + + + fun getMACAsStr( ) : String? { + + if( null == this.mAC ) return null; + return String(mAC!!) + } + + + + fun getMACAsHex( ) : String? { + + if( null == this.mAC ) return null; + return Util.bytes2HexString(mAC) + } + + + + fun setMAC( bytes : ByteArray ) : Data { + + this.mAC = bytes + return this + } + + + + fun getMACDataAsBin( ) : ByteArray? { + + return this.mACData + } + + + + fun getMACDataAsStr( ) : String? { + + if( null == this.mACData ) return null; + return String(mACData!!) + } + + + + fun getMACDataAsHex( ) : String? { + + if( null == this.mACData ) return null; + return Util.bytes2HexString(mACData) + } + + + + fun setMACData( bytes : ByteArray ) : Data { + + this.mACData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + soup.put("tag", Util.hexString2Bytes("50")) + +if( null != tag ){ + + + soup.put("tag", this.tag!!) + } + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != type ){ + + + soup.put("type", this.type!!) + soup.put("type\$option", getTypeOptionIndex()!!) + } + soup.put("full", Util.hexString2Bytes("30")) + +if( null != full ){ + + + soup.put("full", this.full!!) + } + soup.put("macLen", Util.hexString2Bytes("31")) + +if( null != macLen ){ + + + soup.put("macLen", this.macLen!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != mAC ){ + + + soup.put("MAC", this.mAC!!) + } + +if( null != mACData ){ + + + soup.put("MACData", this.mACData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + this.tag = Util.hexString2Bytes("50") + +if( soup.containsKey("tag") ){ + + + this.tag = (soup.get("tag") as PacketSection).bytes +} + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("type") ){ + + + this.type = (soup.get("type") as PacketSection).bytes +} + + this.full = Util.hexString2Bytes("30") + +if( soup.containsKey("full") ){ + + + this.full = (soup.get("full") as PacketSection).bytes +} + + this.macLen = Util.hexString2Bytes("31") + +if( soup.containsKey("macLen") ){ + + + this.macLen = (soup.get("macLen") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("MAC") ){ + + + this.mAC = (soup.get("MAC") as PacketSection).bytes +} + + +if( soup.containsKey("MACData") ){ + + + this.mACData = (soup.get("MACData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D43")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D43") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVMAC校验错(Util.hexString2Bytes("3031")), +OPVTAK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return "MAC校验错" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "TAK奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + return null + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D44")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D44") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO60.kt b/src/main/java/racal/sunyard/main/dto/DTO60.kt new file mode 100644 index 0000000..1c6fb2c --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO60.kt @@ -0,0 +1,937 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO60 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3630")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3630") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var dK : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效的成份号(Util.hexString2Bytes("3033")), +OPV成份奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV传输保护秘钥校验值和和实际不一致(Util.hexString2Bytes("3537")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的成份号" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "成份奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3537".equals(Util.bytes2HexString(this.error) ) ) { + + return "传输保护秘钥校验值和和实际不一致" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3537".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getDKAsBin( ) : ByteArray? { + + return this.dK + } + + + + fun getDKAsStr( ) : String? { + + if( null == this.dK ) return null; + return String(dK!!) + } + + + + fun getDKAsHex( ) : String? { + + if( null == this.dK ) return null; + return Util.bytes2HexString(dK) + } + + + + fun setDK( bytes : ByteArray ) : Data { + + this.dK = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != dK ){ + + + soup.put("DK", this.dK!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("DK") ){ + + + this.dK = (soup.get("DK") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3631")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3631") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO61.kt b/src/main/java/racal/sunyard/main/dto/DTO61.kt new file mode 100644 index 0000000..242a3ca --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO61.kt @@ -0,0 +1,982 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO61 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var roleInfo : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getRoleInfoAsBin( ) : ByteArray? { + + return this.roleInfo + } + + + + fun getRoleInfoAsStr( ) : String? { + + if( null == this.roleInfo ) return null; + return String(roleInfo!!) + } + + + + fun getRoleInfoAsHex( ) : String? { + + if( null == this.roleInfo ) return null; + return Util.bytes2HexString(roleInfo) + } + + + + fun setRoleInfo( bytes : ByteArray ) : Data { + + this.roleInfo = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != roleInfo ){ + + + soup.put("roleInfo", this.roleInfo!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("roleInfo") ){ + + + this.roleInfo = (soup.get("roleInfo") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3631")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3631") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var roleType : ByteArray? = null + private var roleId : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV验证失败(Util.hexString2Bytes("3032")), +OPV无效的成份号(Util.hexString2Bytes("3033")), +OPV成份奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3032".equals(Util.bytes2HexString(this.error) ) ) { + + return "验证失败" + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的成份号" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "成份奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3032".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getRoleTypeAsBin( ) : ByteArray? { + + return this.roleType + } + + + + fun getRoleTypeAsStr( ) : String? { + + if( null == this.roleType ) return null; + return String(roleType!!) + } + + + + fun getRoleTypeAsHex( ) : String? { + + if( null == this.roleType ) return null; + return Util.bytes2HexString(roleType) + } + + + + fun setRoleType( bytes : ByteArray ) : Data { + + this.roleType = bytes + return this + } + + + + fun getRoleIdAsBin( ) : ByteArray? { + + return this.roleId + } + + + + fun getRoleIdAsStr( ) : String? { + + if( null == this.roleId ) return null; + return String(roleId!!) + } + + + + fun getRoleIdAsHex( ) : String? { + + if( null == this.roleId ) return null; + return Util.bytes2HexString(roleId) + } + + + + fun setRoleId( bytes : ByteArray ) : Data { + + this.roleId = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != roleType ){ + + + soup.put("roleType", this.roleType!!) + } + +if( null != roleId ){ + + + soup.put("roleId", this.roleId!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("roleType") ){ + + + this.roleType = (soup.get("roleType") as PacketSection).bytes +} + + +if( soup.containsKey("roleId") ){ + + + this.roleId = (soup.get("roleId") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3632")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3632") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO62.kt b/src/main/java/racal/sunyard/main/dto/DTO62.kt new file mode 100644 index 0000000..87b3bc2 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO62.kt @@ -0,0 +1,1247 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO62 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var keyType : ByteArray? = null + private var key : ByteArray? = null + private var algorithmKey : ByteArray? = null + private var alg : ByteArray? = null + private var outputFormat : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPVIDEA(Util.hexString2Bytes("30")), +OPVSM1(Util.hexString2Bytes("31")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "IDEA" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM1" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + return null + } + + + + fun getOutputFormatAsBin( ) : ByteArray? { + + return this.outputFormat + } + + + + fun getOutputFormatAsStr( ) : String? { + + if( null == this.outputFormat ) return null; + return String(outputFormat!!) + } + + + + fun getOutputFormatAsHex( ) : String? { + + if( null == this.outputFormat ) return null; + return Util.bytes2HexString(outputFormat) + } + + + + fun setOutputFormat( bytes : ByteArray ) : Data { + + this.outputFormat = bytes + return this + } + + + enum class OutputFormatOptions( val bin : ByteArray ) { + +OPV软MD5后前8与后8异或后加密密押取前4位并转为8字节的HEX格式(Util.hexString2Bytes("30")), +OPV软MD5后取前8字节加密输出8节的BIN格式(Util.hexString2Bytes("31")), + } + + fun getOutputFormatCn( ) : String? { + + if( null == outputFormat ) { return null } + +if( "30".equals(Util.bytes2HexString(this.outputFormat) ) ) { + + return "软MD5后前8与后8异或后加密,密押取前4位并转为8字节的HEX格式" + +} + + +if( "31".equals(Util.bytes2HexString(this.outputFormat) ) ) { + + return "软MD5后取前8字节加密,输出8节的BIN格式" + +} + + return null + } + + + + fun getOutputFormatOptionIndex( ) : Int? { + + if( null == outputFormat ) { return null } + +if( "30".equals(Util.bytes2HexString(this.outputFormat) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.outputFormat) ) ) { + + return 1 + +} + + return null + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != algorithmKey ){ + + + soup.put("AlgorithmKey", this.algorithmKey!!) + } + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != outputFormat ){ + + + soup.put("outputFormat", this.outputFormat!!) + soup.put("outputFormat\$option", getOutputFormatOptionIndex()!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("AlgorithmKey") ){ + + + this.algorithmKey = (soup.get("AlgorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("outputFormat") ){ + + + this.outputFormat = (soup.get("outputFormat") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3632")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3632") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var mAC : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + return null + } + + + + fun getMACAsBin( ) : ByteArray? { + + return this.mAC + } + + + + fun getMACAsStr( ) : String? { + + if( null == this.mAC ) return null; + return String(mAC!!) + } + + + + fun getMACAsHex( ) : String? { + + if( null == this.mAC ) return null; + return Util.bytes2HexString(mAC) + } + + + + fun setMAC( bytes : ByteArray ) : Data { + + this.mAC = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != mAC ){ + + + soup.put("MAC", this.mAC!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("MAC") ){ + + + this.mAC = (soup.get("MAC") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3633")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3633") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO63.kt b/src/main/java/racal/sunyard/main/dto/DTO63.kt new file mode 100644 index 0000000..3df0eed --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO63.kt @@ -0,0 +1,1247 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO63 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var keyType : ByteArray? = null + private var key : ByteArray? = null + private var algorithmKey : ByteArray? = null + private var alg : ByteArray? = null + private var outputFormat : ByteArray? = null + private var secret : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPVIDEA(Util.hexString2Bytes("30")), +OPVSM1(Util.hexString2Bytes("31")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "IDEA" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM1" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + return null + } + + + + fun getOutputFormatAsBin( ) : ByteArray? { + + return this.outputFormat + } + + + + fun getOutputFormatAsStr( ) : String? { + + if( null == this.outputFormat ) return null; + return String(outputFormat!!) + } + + + + fun getOutputFormatAsHex( ) : String? { + + if( null == this.outputFormat ) return null; + return Util.bytes2HexString(outputFormat) + } + + + + fun setOutputFormat( bytes : ByteArray ) : Data { + + this.outputFormat = bytes + return this + } + + + enum class OutputFormatOptions( val bin : ByteArray ) { + +OPV软MD5后前8与后8异或后加密密押取前4位并转为8字节的HEX格式(Util.hexString2Bytes("30")), +OPV软MD5后取前8字节加密输出8节的BIN格式(Util.hexString2Bytes("31")), + } + + fun getOutputFormatCn( ) : String? { + + if( null == outputFormat ) { return null } + +if( "30".equals(Util.bytes2HexString(this.outputFormat) ) ) { + + return "软MD5后前8与后8异或后加密,密押取前4位并转为8字节的HEX格式" + +} + + +if( "31".equals(Util.bytes2HexString(this.outputFormat) ) ) { + + return "软MD5后取前8字节加密,输出8节的BIN格式" + +} + + return null + } + + + + fun getOutputFormatOptionIndex( ) : Int? { + + if( null == outputFormat ) { return null } + +if( "30".equals(Util.bytes2HexString(this.outputFormat) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.outputFormat) ) ) { + + return 1 + +} + + return null + } + + + + fun getSecretAsBin( ) : ByteArray? { + + return this.secret + } + + + + fun getSecretAsStr( ) : String? { + + if( null == this.secret ) return null; + return String(secret!!) + } + + + + fun getSecretAsHex( ) : String? { + + if( null == this.secret ) return null; + return Util.bytes2HexString(secret) + } + + + + fun setSecret( bytes : ByteArray ) : Data { + + this.secret = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != algorithmKey ){ + + + soup.put("AlgorithmKey", this.algorithmKey!!) + } + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != outputFormat ){ + + + soup.put("outputFormat", this.outputFormat!!) + soup.put("outputFormat\$option", getOutputFormatOptionIndex()!!) + } + +if( null != secret ){ + + + soup.put("secret", this.secret!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("AlgorithmKey") ){ + + + this.algorithmKey = (soup.get("AlgorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("outputFormat") ){ + + + this.outputFormat = (soup.get("outputFormat") as PacketSection).bytes +} + + +if( soup.containsKey("secret") ){ + + + this.secret = (soup.get("secret") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3633")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3633") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + return null + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3634")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3634") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO64.kt b/src/main/java/racal/sunyard/main/dto/DTO64.kt new file mode 100644 index 0000000..4599621 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO64.kt @@ -0,0 +1,1322 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO64 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var keyType : ByteArray? = null + private var key : ByteArray? = null + private var log : ByteArray? = null + private var algorithmKey : ByteArray? = null + private var alg : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getLogAsBin( ) : ByteArray? { + + return this.log + } + + + + fun getLogAsStr( ) : String? { + + if( null == this.log ) return null; + return String(log!!) + } + + + + fun getLogAsHex( ) : String? { + + if( null == this.log ) return null; + return Util.bytes2HexString(log) + } + + + + fun setLog( bytes : ByteArray ) : Data { + + this.log = bytes + return this + } + + + enum class LogOptions( val bin : ByteArray ) { + +OPV加密(Util.hexString2Bytes("30")), +OPV解密(Util.hexString2Bytes("31")), + } + + fun getLogCn( ) : String? { + + if( null == log ) { return null } + +if( "30".equals(Util.bytes2HexString(this.log) ) ) { + + return "加密" + +} + + +if( "31".equals(Util.bytes2HexString(this.log) ) ) { + + return "解密" + +} + + return null + } + + + + fun getLogOptionIndex( ) : Int? { + + if( null == log ) { return null } + +if( "30".equals(Util.bytes2HexString(this.log) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.log) ) ) { + + return 1 + +} + + return null + } + + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPVIDEA(Util.hexString2Bytes("30")), +OPVSM1(Util.hexString2Bytes("31")), +OPV3DES(Util.hexString2Bytes("32")), +OPVSM4(Util.hexString2Bytes("33")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "IDEA" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM1" + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return "3DES" + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return 2 + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return 3 + +} + + return null + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != log ){ + + + soup.put("log", this.log!!) + soup.put("log\$option", getLogOptionIndex()!!) + } + +if( null != algorithmKey ){ + + + soup.put("AlgorithmKey", this.algorithmKey!!) + } + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("log") ){ + + + this.log = (soup.get("log") as PacketSection).bytes +} + + +if( soup.containsKey("AlgorithmKey") ){ + + + this.algorithmKey = (soup.get("AlgorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3634")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3634") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var infoLen : ByteArray? = null + private var info : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + return null + } + + + + fun getInfoLenAsBin( ) : ByteArray? { + + return this.infoLen + } + + + + fun getInfoLenAsStr( ) : String? { + + if( null == this.infoLen ) return null; + return String(infoLen!!) + } + + + + fun getInfoLenAsHex( ) : String? { + + if( null == this.infoLen ) return null; + return Util.bytes2HexString(infoLen) + } + + + + fun setInfoLen( bytes : ByteArray ) : Data { + + this.infoLen = bytes + return this + } + + + + fun getInfoAsBin( ) : ByteArray? { + + return this.info + } + + + + fun getInfoAsStr( ) : String? { + + if( null == this.info ) return null; + return String(info!!) + } + + + + fun getInfoAsHex( ) : String? { + + if( null == this.info ) return null; + return Util.bytes2HexString(info) + } + + + + fun setInfo( bytes : ByteArray ) : Data { + + this.info = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != infoLen ){ + + + soup.put("infoLen", this.infoLen!!) + } + +if( null != info ){ + + + soup.put("info", this.info!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("infoLen") ){ + + + this.infoLen = (soup.get("infoLen") as PacketSection).bytes +} + + +if( soup.containsKey("info") ){ + + + this.info = (soup.get("info") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3635")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3635") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO65.kt b/src/main/java/racal/sunyard/main/dto/DTO65.kt new file mode 100644 index 0000000..bcb2dd5 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO65.kt @@ -0,0 +1,1272 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO65 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var keyType : ByteArray? = null + private var srcKey : ByteArray? = null + private var aimKey : ByteArray? = null + private var algorithmKey : ByteArray? = null + private var alg : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getSrcKeyAsBin( ) : ByteArray? { + + return this.srcKey + } + + + + fun getSrcKeyAsStr( ) : String? { + + if( null == this.srcKey ) return null; + return String(srcKey!!) + } + + + + fun getSrcKeyAsHex( ) : String? { + + if( null == this.srcKey ) return null; + return Util.bytes2HexString(srcKey) + } + + + + fun setSrcKey( bytes : ByteArray ) : Data { + + this.srcKey = bytes + return this + } + + + + fun getAimKeyAsBin( ) : ByteArray? { + + return this.aimKey + } + + + + fun getAimKeyAsStr( ) : String? { + + if( null == this.aimKey ) return null; + return String(aimKey!!) + } + + + + fun getAimKeyAsHex( ) : String? { + + if( null == this.aimKey ) return null; + return Util.bytes2HexString(aimKey) + } + + + + fun setAimKey( bytes : ByteArray ) : Data { + + this.aimKey = bytes + return this + } + + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPVIDEA(Util.hexString2Bytes("30")), +OPVSM1(Util.hexString2Bytes("31")), +OPV3DES(Util.hexString2Bytes("32")), +OPVSM4(Util.hexString2Bytes("33")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "IDEA" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM1" + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return "3DES" + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return 2 + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return 3 + +} + + return null + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + +if( null != srcKey ){ + + + soup.put("srcKey", this.srcKey!!) + } + +if( null != aimKey ){ + + + soup.put("aimKey", this.aimKey!!) + } + +if( null != algorithmKey ){ + + + soup.put("AlgorithmKey", this.algorithmKey!!) + } + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("srcKey") ){ + + + this.srcKey = (soup.get("srcKey") as PacketSection).bytes +} + + +if( soup.containsKey("aimKey") ){ + + + this.aimKey = (soup.get("aimKey") as PacketSection).bytes +} + + +if( soup.containsKey("AlgorithmKey") ){ + + + this.algorithmKey = (soup.get("AlgorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3635")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3635") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var infoLen : ByteArray? = null + private var info : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + return null + } + + + + fun getInfoLenAsBin( ) : ByteArray? { + + return this.infoLen + } + + + + fun getInfoLenAsStr( ) : String? { + + if( null == this.infoLen ) return null; + return String(infoLen!!) + } + + + + fun getInfoLenAsHex( ) : String? { + + if( null == this.infoLen ) return null; + return Util.bytes2HexString(infoLen) + } + + + + fun setInfoLen( bytes : ByteArray ) : Data { + + this.infoLen = bytes + return this + } + + + + fun getInfoAsBin( ) : ByteArray? { + + return this.info + } + + + + fun getInfoAsStr( ) : String? { + + if( null == this.info ) return null; + return String(info!!) + } + + + + fun getInfoAsHex( ) : String? { + + if( null == this.info ) return null; + return Util.bytes2HexString(info) + } + + + + fun setInfo( bytes : ByteArray ) : Data { + + this.info = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != infoLen ){ + + + soup.put("infoLen", this.infoLen!!) + } + +if( null != info ){ + + + soup.put("info", this.info!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("infoLen") ){ + + + this.infoLen = (soup.get("infoLen") as PacketSection).bytes +} + + +if( soup.containsKey("info") ){ + + + this.info = (soup.get("info") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3636")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3636") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO66.kt b/src/main/java/racal/sunyard/main/dto/DTO66.kt new file mode 100644 index 0000000..889b695 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO66.kt @@ -0,0 +1,1112 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO66 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var key : ByteArray? = null + private var log : ByteArray? = null + private var algorithmKey : ByteArray? = null + private var alg : ByteArray? = null + private var pin : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getLogAsBin( ) : ByteArray? { + + return this.log + } + + + + fun getLogAsStr( ) : String? { + + if( null == this.log ) return null; + return String(log!!) + } + + + + fun getLogAsHex( ) : String? { + + if( null == this.log ) return null; + return Util.bytes2HexString(log) + } + + + + fun setLog( bytes : ByteArray ) : Data { + + this.log = bytes + return this + } + + + enum class LogOptions( val bin : ByteArray ) { + +OPV加密(Util.hexString2Bytes("30")), +OPV解密(Util.hexString2Bytes("31")), + } + + fun getLogCn( ) : String? { + + if( null == log ) { return null } + +if( "30".equals(Util.bytes2HexString(this.log) ) ) { + + return "加密" + +} + + +if( "31".equals(Util.bytes2HexString(this.log) ) ) { + + return "解密" + +} + + return null + } + + + + fun getLogOptionIndex( ) : Int? { + + if( null == log ) { return null } + +if( "30".equals(Util.bytes2HexString(this.log) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.log) ) ) { + + return 1 + +} + + return null + } + + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("30")), +OPVSM4(Util.hexString2Bytes("31")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "3DES" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + return null + } + + + + fun getPinAsBin( ) : ByteArray? { + + return this.pin + } + + + + fun getPinAsStr( ) : String? { + + if( null == this.pin ) return null; + return String(pin!!) + } + + + + fun getPinAsHex( ) : String? { + + if( null == this.pin ) return null; + return Util.bytes2HexString(pin) + } + + + + fun setPin( bytes : ByteArray ) : Data { + + this.pin = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != log ){ + + + soup.put("log", this.log!!) + soup.put("log\$option", getLogOptionIndex()!!) + } + +if( null != algorithmKey ){ + + + soup.put("AlgorithmKey", this.algorithmKey!!) + } + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != pin ){ + + + soup.put("pin", this.pin!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("log") ){ + + + this.log = (soup.get("log") as PacketSection).bytes +} + + +if( soup.containsKey("AlgorithmKey") ){ + + + this.algorithmKey = (soup.get("AlgorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("pin") ){ + + + this.pin = (soup.get("pin") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3636")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3636") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var info : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + return null + } + + + + fun getInfoAsBin( ) : ByteArray? { + + return this.info + } + + + + fun getInfoAsStr( ) : String? { + + if( null == this.info ) return null; + return String(info!!) + } + + + + fun getInfoAsHex( ) : String? { + + if( null == this.info ) return null; + return Util.bytes2HexString(info) + } + + + + fun setInfo( bytes : ByteArray ) : Data { + + this.info = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != info ){ + + + soup.put("info", this.info!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("info") ){ + + + this.info = (soup.get("info") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3637")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3637") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO67.kt b/src/main/java/racal/sunyard/main/dto/DTO67.kt new file mode 100644 index 0000000..409c2f0 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO67.kt @@ -0,0 +1,1062 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO67 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var srcKey : ByteArray? = null + private var aimKey : ByteArray? = null + private var algorithmKey : ByteArray? = null + private var alg : ByteArray? = null + private var pin : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getSrcKeyAsBin( ) : ByteArray? { + + return this.srcKey + } + + + + fun getSrcKeyAsStr( ) : String? { + + if( null == this.srcKey ) return null; + return String(srcKey!!) + } + + + + fun getSrcKeyAsHex( ) : String? { + + if( null == this.srcKey ) return null; + return Util.bytes2HexString(srcKey) + } + + + + fun setSrcKey( bytes : ByteArray ) : Data { + + this.srcKey = bytes + return this + } + + + + fun getAimKeyAsBin( ) : ByteArray? { + + return this.aimKey + } + + + + fun getAimKeyAsStr( ) : String? { + + if( null == this.aimKey ) return null; + return String(aimKey!!) + } + + + + fun getAimKeyAsHex( ) : String? { + + if( null == this.aimKey ) return null; + return Util.bytes2HexString(aimKey) + } + + + + fun setAimKey( bytes : ByteArray ) : Data { + + this.aimKey = bytes + return this + } + + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("30")), +OPVSM4(Util.hexString2Bytes("31")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "3DES" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + return null + } + + + + fun getPinAsBin( ) : ByteArray? { + + return this.pin + } + + + + fun getPinAsStr( ) : String? { + + if( null == this.pin ) return null; + return String(pin!!) + } + + + + fun getPinAsHex( ) : String? { + + if( null == this.pin ) return null; + return Util.bytes2HexString(pin) + } + + + + fun setPin( bytes : ByteArray ) : Data { + + this.pin = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != srcKey ){ + + + soup.put("srcKey", this.srcKey!!) + } + +if( null != aimKey ){ + + + soup.put("aimKey", this.aimKey!!) + } + +if( null != algorithmKey ){ + + + soup.put("AlgorithmKey", this.algorithmKey!!) + } + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != pin ){ + + + soup.put("pin", this.pin!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("srcKey") ){ + + + this.srcKey = (soup.get("srcKey") as PacketSection).bytes +} + + +if( soup.containsKey("aimKey") ){ + + + this.aimKey = (soup.get("aimKey") as PacketSection).bytes +} + + +if( soup.containsKey("AlgorithmKey") ){ + + + this.algorithmKey = (soup.get("AlgorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("pin") ){ + + + this.pin = (soup.get("pin") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3637")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3637") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var info : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + return null + } + + + + fun getInfoAsBin( ) : ByteArray? { + + return this.info + } + + + + fun getInfoAsStr( ) : String? { + + if( null == this.info ) return null; + return String(info!!) + } + + + + fun getInfoAsHex( ) : String? { + + if( null == this.info ) return null; + return Util.bytes2HexString(info) + } + + + + fun setInfo( bytes : ByteArray ) : Data { + + this.info = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != info ){ + + + soup.put("info", this.info!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("info") ){ + + + this.info = (soup.get("info") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3638")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3638") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO68.kt b/src/main/java/racal/sunyard/main/dto/DTO68.kt new file mode 100644 index 0000000..0eb5b18 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO68.kt @@ -0,0 +1,1617 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO68 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var dEK : ByteArray? = null + private var infoDataLen : ByteArray? = null + private var infoData : ByteArray? = null + private var alg : ByteArray? = null + private var fillKey : ByteArray? = null + private var publicKeyLen : ByteArray? = null + private var publicKey : ByteArray? = null + private var algorithmKey1 : ByteArray? = null + private var encryAlgorithm1 : ByteArray? = null + private var algorithmKey2 : ByteArray? = null + private var encryAlgorithm2 : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getDEKAsBin( ) : ByteArray? { + + return this.dEK + } + + + + fun getDEKAsStr( ) : String? { + + if( null == this.dEK ) return null; + return String(dEK!!) + } + + + + fun getDEKAsHex( ) : String? { + + if( null == this.dEK ) return null; + return Util.bytes2HexString(dEK) + } + + + + fun setDEK( bytes : ByteArray ) : Data { + + this.dEK = bytes + return this + } + + + + fun getInfoDataLenAsBin( ) : ByteArray? { + + return this.infoDataLen + } + + + + fun getInfoDataLenAsStr( ) : String? { + + if( null == this.infoDataLen ) return null; + return String(infoDataLen!!) + } + + + + fun getInfoDataLenAsHex( ) : String? { + + if( null == this.infoDataLen ) return null; + return Util.bytes2HexString(infoDataLen) + } + + + + fun setInfoDataLen( bytes : ByteArray ) : Data { + + this.infoDataLen = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPVRSA(Util.hexString2Bytes("30")), +OPVSM2(Util.hexString2Bytes("31")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "RSA" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM2" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + return null + } + + + + fun getFillKeyAsBin( ) : ByteArray? { + + return this.fillKey + } + + + + fun getFillKeyAsStr( ) : String? { + + if( null == this.fillKey ) return null; + return String(fillKey!!) + } + + + + fun getFillKeyAsHex( ) : String? { + + if( null == this.fillKey ) return null; + return Util.bytes2HexString(fillKey) + } + + + + fun setFillKey( bytes : ByteArray ) : Data { + + this.fillKey = bytes + return this + } + + + enum class FillKeyOptions( val bin : ByteArray ) { + +OPV数据长度必须等于密钥长度DER对应的数据长度(Util.hexString2Bytes("30")), +OPVPKCS1v15填充方式(Util.hexString2Bytes("31")), + } + + fun getFillKeyCn( ) : String? { + + if( null == fillKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return "数据长度必须等于密钥长度(DER对应的数据长度)" + +} + + +if( "31".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return "PKCS#1 v1.5 填充方式" + +} + + return null + } + + + + fun getFillKeyOptionIndex( ) : Int? { + + if( null == fillKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return 1 + +} + + return null + } + + + + fun getPublicKeyLenAsBin( ) : ByteArray? { + + return this.publicKeyLen + } + + + + fun getPublicKeyLenAsStr( ) : String? { + + if( null == this.publicKeyLen ) return null; + return String(publicKeyLen!!) + } + + + + fun getPublicKeyLenAsHex( ) : String? { + + if( null == this.publicKeyLen ) return null; + return Util.bytes2HexString(publicKeyLen) + } + + + + fun setPublicKeyLen( bytes : ByteArray ) : Data { + + this.publicKeyLen = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getAlgorithmKey1AsBin( ) : ByteArray? { + + return this.algorithmKey1 + } + + + + fun getAlgorithmKey1AsStr( ) : String? { + + if( null == this.algorithmKey1 ) return null; + return String(algorithmKey1!!) + } + + + + fun getAlgorithmKey1AsHex( ) : String? { + + if( null == this.algorithmKey1 ) return null; + return Util.bytes2HexString(algorithmKey1) + } + + + + fun setAlgorithmKey1( bytes : ByteArray ) : Data { + + this.algorithmKey1 = bytes + return this + } + + + + fun getEncryAlgorithm1AsBin( ) : ByteArray? { + + return this.encryAlgorithm1 + } + + + + fun getEncryAlgorithm1AsStr( ) : String? { + + if( null == this.encryAlgorithm1 ) return null; + return String(encryAlgorithm1!!) + } + + + + fun getEncryAlgorithm1AsHex( ) : String? { + + if( null == this.encryAlgorithm1 ) return null; + return Util.bytes2HexString(encryAlgorithm1) + } + + + + fun setEncryAlgorithm1( bytes : ByteArray ) : Data { + + this.encryAlgorithm1 = bytes + return this + } + + + enum class EncryAlgorithm1Options( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("30")), +OPVSM4(Util.hexString2Bytes("31")), + } + + fun getEncryAlgorithm1Cn( ) : String? { + + if( null == encryAlgorithm1 ) { return null } + +if( "30".equals(Util.bytes2HexString(this.encryAlgorithm1) ) ) { + + return "3DES" + +} + + +if( "31".equals(Util.bytes2HexString(this.encryAlgorithm1) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getEncryAlgorithm1OptionIndex( ) : Int? { + + if( null == encryAlgorithm1 ) { return null } + +if( "30".equals(Util.bytes2HexString(this.encryAlgorithm1) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.encryAlgorithm1) ) ) { + + return 1 + +} + + return null + } + + + + fun getAlgorithmKey2AsBin( ) : ByteArray? { + + return this.algorithmKey2 + } + + + + fun getAlgorithmKey2AsStr( ) : String? { + + if( null == this.algorithmKey2 ) return null; + return String(algorithmKey2!!) + } + + + + fun getAlgorithmKey2AsHex( ) : String? { + + if( null == this.algorithmKey2 ) return null; + return Util.bytes2HexString(algorithmKey2) + } + + + + fun setAlgorithmKey2( bytes : ByteArray ) : Data { + + this.algorithmKey2 = bytes + return this + } + + + + fun getEncryAlgorithm2AsBin( ) : ByteArray? { + + return this.encryAlgorithm2 + } + + + + fun getEncryAlgorithm2AsStr( ) : String? { + + if( null == this.encryAlgorithm2 ) return null; + return String(encryAlgorithm2!!) + } + + + + fun getEncryAlgorithm2AsHex( ) : String? { + + if( null == this.encryAlgorithm2 ) return null; + return Util.bytes2HexString(encryAlgorithm2) + } + + + + fun setEncryAlgorithm2( bytes : ByteArray ) : Data { + + this.encryAlgorithm2 = bytes + return this + } + + + enum class EncryAlgorithm2Options( val bin : ByteArray ) { + +OPVECB(Util.hexString2Bytes("30")), +OPVCBC(Util.hexString2Bytes("31")), + } + + fun getEncryAlgorithm2Cn( ) : String? { + + if( null == encryAlgorithm2 ) { return null } + +if( "30".equals(Util.bytes2HexString(this.encryAlgorithm2) ) ) { + + return "ECB" + +} + + +if( "31".equals(Util.bytes2HexString(this.encryAlgorithm2) ) ) { + + return "CBC" + +} + + return null + } + + + + fun getEncryAlgorithm2OptionIndex( ) : Int? { + + if( null == encryAlgorithm2 ) { return null } + +if( "30".equals(Util.bytes2HexString(this.encryAlgorithm2) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.encryAlgorithm2) ) ) { + + return 1 + +} + + return null + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != dEK ){ + + + soup.put("DEK", this.dEK!!) + } + +if( null != infoDataLen ){ + + + soup.put("infoDataLen", this.infoDataLen!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != fillKey ){ + + + soup.put("fillKey", this.fillKey!!) + soup.put("fillKey\$option", getFillKeyOptionIndex()!!) + } + +if( null != publicKeyLen ){ + + + soup.put("publicKeyLen", this.publicKeyLen!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + +if( null != algorithmKey1 ){ + + + soup.put("AlgorithmKey1", this.algorithmKey1!!) + } + +if( null != encryAlgorithm1 ){ + + + soup.put("EncryAlgorithm1", this.encryAlgorithm1!!) + soup.put("EncryAlgorithm1\$option", getEncryAlgorithm1OptionIndex()!!) + } + +if( null != algorithmKey2 ){ + + + soup.put("AlgorithmKey2", this.algorithmKey2!!) + } + +if( null != encryAlgorithm2 ){ + + + soup.put("EncryAlgorithm2", this.encryAlgorithm2!!) + soup.put("EncryAlgorithm2\$option", getEncryAlgorithm2OptionIndex()!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("DEK") ){ + + + this.dEK = (soup.get("DEK") as PacketSection).bytes +} + + +if( soup.containsKey("infoDataLen") ){ + + + this.infoDataLen = (soup.get("infoDataLen") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("fillKey") ){ + + + this.fillKey = (soup.get("fillKey") as PacketSection).bytes +} + + +if( soup.containsKey("publicKeyLen") ){ + + + this.publicKeyLen = (soup.get("publicKeyLen") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + +if( soup.containsKey("AlgorithmKey1") ){ + + + this.algorithmKey1 = (soup.get("AlgorithmKey1") as PacketSection).bytes +} + + +if( soup.containsKey("EncryAlgorithm1") ){ + + + this.encryAlgorithm1 = (soup.get("EncryAlgorithm1") as PacketSection).bytes +} + + +if( soup.containsKey("AlgorithmKey2") ){ + + + this.algorithmKey2 = (soup.get("AlgorithmKey2") as PacketSection).bytes +} + + +if( soup.containsKey("EncryAlgorithm2") ){ + + + this.encryAlgorithm2 = (soup.get("EncryAlgorithm2") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3638")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3638") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var keyLen : ByteArray? = null + private var key : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getKeyLenAsBin( ) : ByteArray? { + + return this.keyLen + } + + + + fun getKeyLenAsStr( ) : String? { + + if( null == this.keyLen ) return null; + return String(keyLen!!) + } + + + + fun getKeyLenAsHex( ) : String? { + + if( null == this.keyLen ) return null; + return Util.bytes2HexString(keyLen) + } + + + + fun setKeyLen( bytes : ByteArray ) : Data { + + this.keyLen = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != keyLen ){ + + + soup.put("keyLen", this.keyLen!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("keyLen") ){ + + + this.keyLen = (soup.get("keyLen") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3639")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3639") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO69.kt b/src/main/java/racal/sunyard/main/dto/DTO69.kt new file mode 100644 index 0000000..4711a0d --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO69.kt @@ -0,0 +1,1677 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO69 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var alg : ByteArray? = null + private var fillKey : ByteArray? = null + private var privateKeyTag : ByteArray? = null + private var privateKeyLength : ByteArray? = null + private var privateKey : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var dEK : ByteArray? = null + private var algorithmKey1 : ByteArray? = null + private var encryAlgorithm1 : ByteArray? = null + private var algorithmKey2 : ByteArray? = null + private var encryAlgorithm2 : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPVRSA(Util.hexString2Bytes("30")), +OPVSM2(Util.hexString2Bytes("31")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "RSA" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM2" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + return null + } + + + + fun getFillKeyAsBin( ) : ByteArray? { + + return this.fillKey + } + + + + fun getFillKeyAsStr( ) : String? { + + if( null == this.fillKey ) return null; + return String(fillKey!!) + } + + + + fun getFillKeyAsHex( ) : String? { + + if( null == this.fillKey ) return null; + return Util.bytes2HexString(fillKey) + } + + + + fun setFillKey( bytes : ByteArray ) : Data { + + this.fillKey = bytes + return this + } + + + enum class FillKeyOptions( val bin : ByteArray ) { + +OPV数据长度必须等于密钥长度DER对应的数据长度(Util.hexString2Bytes("30")), +OPVPKCS1v15填充方式(Util.hexString2Bytes("31")), + } + + fun getFillKeyCn( ) : String? { + + if( null == fillKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return "数据长度必须等于密钥长度(DER对应的数据长度)" + +} + + +if( "31".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return "PKCS#1 v1.5 填充方式" + +} + + return null + } + + + + fun getFillKeyOptionIndex( ) : Int? { + + if( null == fillKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return 1 + +} + + return null + } + + + + fun getPrivateKeyTagAsBin( ) : ByteArray? { + + return this.privateKeyTag + } + + + + fun getPrivateKeyTagAsStr( ) : String? { + + if( null == this.privateKeyTag ) return null; + return String(privateKeyTag!!) + } + + + + fun getPrivateKeyTagAsHex( ) : String? { + + if( null == this.privateKeyTag ) return null; + return Util.bytes2HexString(privateKeyTag) + } + + + + fun setPrivateKeyTag( bytes : ByteArray ) : Data { + + this.privateKeyTag = bytes + return this + } + + + + fun getPrivateKeyLengthAsBin( ) : ByteArray? { + + return this.privateKeyLength + } + + + + fun getPrivateKeyLengthAsStr( ) : String? { + + if( null == this.privateKeyLength ) return null; + return String(privateKeyLength!!) + } + + + + fun getPrivateKeyLengthAsHex( ) : String? { + + if( null == this.privateKeyLength ) return null; + return Util.bytes2HexString(privateKeyLength) + } + + + + fun setPrivateKeyLength( bytes : ByteArray ) : Data { + + this.privateKeyLength = bytes + return this + } + + + + fun getPrivateKeyAsBin( ) : ByteArray? { + + return this.privateKey + } + + + + fun getPrivateKeyAsStr( ) : String? { + + if( null == this.privateKey ) return null; + return String(privateKey!!) + } + + + + fun getPrivateKeyAsHex( ) : String? { + + if( null == this.privateKey ) return null; + return Util.bytes2HexString(privateKey) + } + + + + fun setPrivateKey( bytes : ByteArray ) : Data { + + this.privateKey = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getDEKAsBin( ) : ByteArray? { + + return this.dEK + } + + + + fun getDEKAsStr( ) : String? { + + if( null == this.dEK ) return null; + return String(dEK!!) + } + + + + fun getDEKAsHex( ) : String? { + + if( null == this.dEK ) return null; + return Util.bytes2HexString(dEK) + } + + + + fun setDEK( bytes : ByteArray ) : Data { + + this.dEK = bytes + return this + } + + + + fun getAlgorithmKey1AsBin( ) : ByteArray? { + + return this.algorithmKey1 + } + + + + fun getAlgorithmKey1AsStr( ) : String? { + + if( null == this.algorithmKey1 ) return null; + return String(algorithmKey1!!) + } + + + + fun getAlgorithmKey1AsHex( ) : String? { + + if( null == this.algorithmKey1 ) return null; + return Util.bytes2HexString(algorithmKey1) + } + + + + fun setAlgorithmKey1( bytes : ByteArray ) : Data { + + this.algorithmKey1 = bytes + return this + } + + + + fun getEncryAlgorithm1AsBin( ) : ByteArray? { + + return this.encryAlgorithm1 + } + + + + fun getEncryAlgorithm1AsStr( ) : String? { + + if( null == this.encryAlgorithm1 ) return null; + return String(encryAlgorithm1!!) + } + + + + fun getEncryAlgorithm1AsHex( ) : String? { + + if( null == this.encryAlgorithm1 ) return null; + return Util.bytes2HexString(encryAlgorithm1) + } + + + + fun setEncryAlgorithm1( bytes : ByteArray ) : Data { + + this.encryAlgorithm1 = bytes + return this + } + + + enum class EncryAlgorithm1Options( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("30")), +OPVSM4(Util.hexString2Bytes("31")), + } + + fun getEncryAlgorithm1Cn( ) : String? { + + if( null == encryAlgorithm1 ) { return null } + +if( "30".equals(Util.bytes2HexString(this.encryAlgorithm1) ) ) { + + return "3DES" + +} + + +if( "31".equals(Util.bytes2HexString(this.encryAlgorithm1) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getEncryAlgorithm1OptionIndex( ) : Int? { + + if( null == encryAlgorithm1 ) { return null } + +if( "30".equals(Util.bytes2HexString(this.encryAlgorithm1) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.encryAlgorithm1) ) ) { + + return 1 + +} + + return null + } + + + + fun getAlgorithmKey2AsBin( ) : ByteArray? { + + return this.algorithmKey2 + } + + + + fun getAlgorithmKey2AsStr( ) : String? { + + if( null == this.algorithmKey2 ) return null; + return String(algorithmKey2!!) + } + + + + fun getAlgorithmKey2AsHex( ) : String? { + + if( null == this.algorithmKey2 ) return null; + return Util.bytes2HexString(algorithmKey2) + } + + + + fun setAlgorithmKey2( bytes : ByteArray ) : Data { + + this.algorithmKey2 = bytes + return this + } + + + + fun getEncryAlgorithm2AsBin( ) : ByteArray? { + + return this.encryAlgorithm2 + } + + + + fun getEncryAlgorithm2AsStr( ) : String? { + + if( null == this.encryAlgorithm2 ) return null; + return String(encryAlgorithm2!!) + } + + + + fun getEncryAlgorithm2AsHex( ) : String? { + + if( null == this.encryAlgorithm2 ) return null; + return Util.bytes2HexString(encryAlgorithm2) + } + + + + fun setEncryAlgorithm2( bytes : ByteArray ) : Data { + + this.encryAlgorithm2 = bytes + return this + } + + + enum class EncryAlgorithm2Options( val bin : ByteArray ) { + +OPVECB(Util.hexString2Bytes("30")), +OPVCBC(Util.hexString2Bytes("31")), + } + + fun getEncryAlgorithm2Cn( ) : String? { + + if( null == encryAlgorithm2 ) { return null } + +if( "30".equals(Util.bytes2HexString(this.encryAlgorithm2) ) ) { + + return "ECB" + +} + + +if( "31".equals(Util.bytes2HexString(this.encryAlgorithm2) ) ) { + + return "CBC" + +} + + return null + } + + + + fun getEncryAlgorithm2OptionIndex( ) : Int? { + + if( null == encryAlgorithm2 ) { return null } + +if( "30".equals(Util.bytes2HexString(this.encryAlgorithm2) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.encryAlgorithm2) ) ) { + + return 1 + +} + + return null + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != fillKey ){ + + + soup.put("fillKey", this.fillKey!!) + soup.put("fillKey\$option", getFillKeyOptionIndex()!!) + } + +if( null != privateKeyTag ){ + + + soup.put("privateKeyTag", this.privateKeyTag!!) + } + +if( null != privateKeyLength ){ + + + soup.put("privateKeyLength", this.privateKeyLength!!) + } + +if( null != privateKey ){ + + + soup.put("privateKey", this.privateKey!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + +if( null != dEK ){ + + + soup.put("DEK", this.dEK!!) + } + +if( null != algorithmKey1 ){ + + + soup.put("AlgorithmKey1", this.algorithmKey1!!) + } + +if( null != encryAlgorithm1 ){ + + + soup.put("EncryAlgorithm1", this.encryAlgorithm1!!) + soup.put("EncryAlgorithm1\$option", getEncryAlgorithm1OptionIndex()!!) + } + +if( null != algorithmKey2 ){ + + + soup.put("AlgorithmKey2", this.algorithmKey2!!) + } + +if( null != encryAlgorithm2 ){ + + + soup.put("EncryAlgorithm2", this.encryAlgorithm2!!) + soup.put("EncryAlgorithm2\$option", getEncryAlgorithm2OptionIndex()!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("fillKey") ){ + + + this.fillKey = (soup.get("fillKey") as PacketSection).bytes +} + + +if( soup.containsKey("privateKeyTag") ){ + + + this.privateKeyTag = (soup.get("privateKeyTag") as PacketSection).bytes +} + + +if( soup.containsKey("privateKeyLength") ){ + + + this.privateKeyLength = (soup.get("privateKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("privateKey") ){ + + + this.privateKey = (soup.get("privateKey") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + +if( soup.containsKey("DEK") ){ + + + this.dEK = (soup.get("DEK") as PacketSection).bytes +} + + +if( soup.containsKey("AlgorithmKey1") ){ + + + this.algorithmKey1 = (soup.get("AlgorithmKey1") as PacketSection).bytes +} + + +if( soup.containsKey("EncryAlgorithm1") ){ + + + this.encryAlgorithm1 = (soup.get("EncryAlgorithm1") as PacketSection).bytes +} + + +if( soup.containsKey("AlgorithmKey2") ){ + + + this.algorithmKey2 = (soup.get("AlgorithmKey2") as PacketSection).bytes +} + + +if( soup.containsKey("EncryAlgorithm2") ){ + + + this.encryAlgorithm2 = (soup.get("EncryAlgorithm2") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3639")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3639") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var keyLen : ByteArray? = null + private var key : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的对称密钥类型(Util.hexString2Bytes("3035")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的对称密钥类型" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getKeyLenAsBin( ) : ByteArray? { + + return this.keyLen + } + + + + fun getKeyLenAsStr( ) : String? { + + if( null == this.keyLen ) return null; + return String(keyLen!!) + } + + + + fun getKeyLenAsHex( ) : String? { + + if( null == this.keyLen ) return null; + return Util.bytes2HexString(keyLen) + } + + + + fun setKeyLen( bytes : ByteArray ) : Data { + + this.keyLen = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != keyLen ){ + + + soup.put("keyLen", this.keyLen!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("keyLen") ){ + + + this.keyLen = (soup.get("keyLen") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3641")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3641") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO6A.kt b/src/main/java/racal/sunyard/main/dto/DTO6A.kt new file mode 100644 index 0000000..1c670fb --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO6A.kt @@ -0,0 +1,1427 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO6A { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var alg : ByteArray? = null + private var certificateModel : ByteArray? = null + private var certificateLen : ByteArray? = null + private var certificateSn : ByteArray? = null + private var certificateDn : ByteArray? = null + private var keyType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPVRSA2048AES256ECB(Util.hexString2Bytes("30")), +OPVSM2SM4ECB(Util.hexString2Bytes("31")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "RSA2048_AES256_ECB" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM2_SM4_ECB" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + return null + } + + + + fun getCertificateModelAsBin( ) : ByteArray? { + + return this.certificateModel + } + + + + fun getCertificateModelAsStr( ) : String? { + + if( null == this.certificateModel ) return null; + return String(certificateModel!!) + } + + + + fun getCertificateModelAsHex( ) : String? { + + if( null == this.certificateModel ) return null; + return Util.bytes2HexString(certificateModel) + } + + + + fun setCertificateModel( bytes : ByteArray ) : Data { + + this.certificateModel = bytes + return this + } + + + enum class CertificateModelOptions( val bin : ByteArray ) { + +OPV证书序号(Util.hexString2Bytes("30")), +OPV证书DN(Util.hexString2Bytes("31")), + } + + fun getCertificateModelCn( ) : String? { + + if( null == certificateModel ) { return null } + +if( "30".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return "证书序号" + +} + + +if( "31".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return "证书 DN" + +} + + return null + } + + + + fun getCertificateModelOptionIndex( ) : Int? { + + if( null == certificateModel ) { return null } + +if( "30".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return 1 + +} + + return null + } + + + + fun getCertificateLenAsBin( ) : ByteArray? { + + return this.certificateLen + } + + + + fun getCertificateLenAsStr( ) : String? { + + if( null == this.certificateLen ) return null; + return String(certificateLen!!) + } + + + + fun getCertificateLenAsHex( ) : String? { + + if( null == this.certificateLen ) return null; + return Util.bytes2HexString(certificateLen) + } + + + + fun setCertificateLen( bytes : ByteArray ) : Data { + + this.certificateLen = bytes + return this + } + + + + fun getCertificateSnAsBin( ) : ByteArray? { + + return this.certificateSn + } + + + + fun getCertificateSnAsStr( ) : String? { + + if( null == this.certificateSn ) return null; + return String(certificateSn!!) + } + + + + fun getCertificateSnAsHex( ) : String? { + + if( null == this.certificateSn ) return null; + return Util.bytes2HexString(certificateSn) + } + + + + fun setCertificateSn( bytes : ByteArray ) : Data { + + this.certificateSn = bytes + return this + } + + + + fun getCertificateDnAsBin( ) : ByteArray? { + + return this.certificateDn + } + + + + fun getCertificateDnAsStr( ) : String? { + + if( null == this.certificateDn ) return null; + return String(certificateDn!!) + } + + + + fun getCertificateDnAsHex( ) : String? { + + if( null == this.certificateDn ) return null; + return Util.bytes2HexString(certificateDn) + } + + + + fun setCertificateDn( bytes : ByteArray ) : Data { + + this.certificateDn = bytes + return this + } + + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != certificateModel ){ + + + soup.put("certificateModel", this.certificateModel!!) + soup.put("certificateModel\$option", getCertificateModelOptionIndex()!!) + } + +if( null != certificateLen ){ + + + soup.put("certificateLen", this.certificateLen!!) + } + +if( null != certificateSn ){ + + + soup.put("certificateSn", this.certificateSn!!) + } + +if( null != certificateDn ){ + + + soup.put("certificateDn", this.certificateDn!!) + } + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("certificateModel") ){ + + + this.certificateModel = (soup.get("certificateModel") as PacketSection).bytes +} + + +if( soup.containsKey("certificateLen") ){ + + + this.certificateLen = (soup.get("certificateLen") as PacketSection).bytes +} + + +if( soup.containsKey("certificateSn") ){ + + + this.certificateSn = (soup.get("certificateSn") as PacketSection).bytes +} + + +if( soup.containsKey("certificateDn") ){ + + + this.certificateDn = (soup.get("certificateDn") as PacketSection).bytes +} + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3641")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3641") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var keyLen : ByteArray? = null + private var key : ByteArray? = null + private var lmkHead : ByteArray? = null + private var lmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getKeyLenAsBin( ) : ByteArray? { + + return this.keyLen + } + + + + fun getKeyLenAsStr( ) : String? { + + if( null == this.keyLen ) return null; + return String(keyLen!!) + } + + + + fun getKeyLenAsHex( ) : String? { + + if( null == this.keyLen ) return null; + return Util.bytes2HexString(keyLen) + } + + + + fun setKeyLen( bytes : ByteArray ) : Data { + + this.keyLen = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getLmkHeadAsBin( ) : ByteArray? { + + return this.lmkHead + } + + + + fun getLmkHeadAsStr( ) : String? { + + if( null == this.lmkHead ) return null; + return String(lmkHead!!) + } + + + + fun getLmkHeadAsHex( ) : String? { + + if( null == this.lmkHead ) return null; + return Util.bytes2HexString(lmkHead) + } + + + + fun setLmkHead( bytes : ByteArray ) : Data { + + this.lmkHead = bytes + return this + } + + + + fun getLmkAsBin( ) : ByteArray? { + + return this.lmk + } + + + + fun getLmkAsStr( ) : String? { + + if( null == this.lmk ) return null; + return String(lmk!!) + } + + + + fun getLmkAsHex( ) : String? { + + if( null == this.lmk ) return null; + return Util.bytes2HexString(lmk) + } + + + + fun setLmk( bytes : ByteArray ) : Data { + + this.lmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != keyLen ){ + + + soup.put("keyLen", this.keyLen!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != lmkHead ){ + + + soup.put("lmkHead", this.lmkHead!!) + } + +if( null != lmk ){ + + + soup.put("lmk", this.lmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("keyLen") ){ + + + this.keyLen = (soup.get("keyLen") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("lmkHead") ){ + + + this.lmkHead = (soup.get("lmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("lmk") ){ + + + this.lmk = (soup.get("lmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3642")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3642") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO6B.kt b/src/main/java/racal/sunyard/main/dto/DTO6B.kt new file mode 100644 index 0000000..51a9bcb --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO6B.kt @@ -0,0 +1,1347 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO6B { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var certificateModel : ByteArray? = null + private var certificateLen : ByteArray? = null + private var certificateSn : ByteArray? = null + private var certificateDn : ByteArray? = null + private var keyLen : ByteArray? = null + private var key : ByteArray? = null + private var keyType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getCertificateModelAsBin( ) : ByteArray? { + + return this.certificateModel + } + + + + fun getCertificateModelAsStr( ) : String? { + + if( null == this.certificateModel ) return null; + return String(certificateModel!!) + } + + + + fun getCertificateModelAsHex( ) : String? { + + if( null == this.certificateModel ) return null; + return Util.bytes2HexString(certificateModel) + } + + + + fun setCertificateModel( bytes : ByteArray ) : Data { + + this.certificateModel = bytes + return this + } + + + enum class CertificateModelOptions( val bin : ByteArray ) { + +OPV证书序号(Util.hexString2Bytes("30")), +OPV证书DN(Util.hexString2Bytes("31")), + } + + fun getCertificateModelCn( ) : String? { + + if( null == certificateModel ) { return null } + +if( "30".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return "证书序号" + +} + + +if( "31".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return "证书 DN" + +} + + return null + } + + + + fun getCertificateModelOptionIndex( ) : Int? { + + if( null == certificateModel ) { return null } + +if( "30".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return 1 + +} + + return null + } + + + + fun getCertificateLenAsBin( ) : ByteArray? { + + return this.certificateLen + } + + + + fun getCertificateLenAsStr( ) : String? { + + if( null == this.certificateLen ) return null; + return String(certificateLen!!) + } + + + + fun getCertificateLenAsHex( ) : String? { + + if( null == this.certificateLen ) return null; + return Util.bytes2HexString(certificateLen) + } + + + + fun setCertificateLen( bytes : ByteArray ) : Data { + + this.certificateLen = bytes + return this + } + + + + fun getCertificateSnAsBin( ) : ByteArray? { + + return this.certificateSn + } + + + + fun getCertificateSnAsStr( ) : String? { + + if( null == this.certificateSn ) return null; + return String(certificateSn!!) + } + + + + fun getCertificateSnAsHex( ) : String? { + + if( null == this.certificateSn ) return null; + return Util.bytes2HexString(certificateSn) + } + + + + fun setCertificateSn( bytes : ByteArray ) : Data { + + this.certificateSn = bytes + return this + } + + + + fun getCertificateDnAsBin( ) : ByteArray? { + + return this.certificateDn + } + + + + fun getCertificateDnAsStr( ) : String? { + + if( null == this.certificateDn ) return null; + return String(certificateDn!!) + } + + + + fun getCertificateDnAsHex( ) : String? { + + if( null == this.certificateDn ) return null; + return Util.bytes2HexString(certificateDn) + } + + + + fun setCertificateDn( bytes : ByteArray ) : Data { + + this.certificateDn = bytes + return this + } + + + + fun getKeyLenAsBin( ) : ByteArray? { + + return this.keyLen + } + + + + fun getKeyLenAsStr( ) : String? { + + if( null == this.keyLen ) return null; + return String(keyLen!!) + } + + + + fun getKeyLenAsHex( ) : String? { + + if( null == this.keyLen ) return null; + return Util.bytes2HexString(keyLen) + } + + + + fun setKeyLen( bytes : ByteArray ) : Data { + + this.keyLen = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != certificateModel ){ + + + soup.put("certificateModel", this.certificateModel!!) + soup.put("certificateModel\$option", getCertificateModelOptionIndex()!!) + } + +if( null != certificateLen ){ + + + soup.put("certificateLen", this.certificateLen!!) + } + +if( null != certificateSn ){ + + + soup.put("certificateSn", this.certificateSn!!) + } + +if( null != certificateDn ){ + + + soup.put("certificateDn", this.certificateDn!!) + } + +if( null != keyLen ){ + + + soup.put("keyLen", this.keyLen!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("certificateModel") ){ + + + this.certificateModel = (soup.get("certificateModel") as PacketSection).bytes +} + + +if( soup.containsKey("certificateLen") ){ + + + this.certificateLen = (soup.get("certificateLen") as PacketSection).bytes +} + + +if( soup.containsKey("certificateSn") ){ + + + this.certificateSn = (soup.get("certificateSn") as PacketSection).bytes +} + + +if( soup.containsKey("certificateDn") ){ + + + this.certificateDn = (soup.get("certificateDn") as PacketSection).bytes +} + + +if( soup.containsKey("keyLen") ){ + + + this.keyLen = (soup.get("keyLen") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3642")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3642") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var lmkHead : ByteArray? = null + private var lmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV输入的数据格式错误(Util.hexString2Bytes("3231")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入的数据格式错误" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getLmkHeadAsBin( ) : ByteArray? { + + return this.lmkHead + } + + + + fun getLmkHeadAsStr( ) : String? { + + if( null == this.lmkHead ) return null; + return String(lmkHead!!) + } + + + + fun getLmkHeadAsHex( ) : String? { + + if( null == this.lmkHead ) return null; + return Util.bytes2HexString(lmkHead) + } + + + + fun setLmkHead( bytes : ByteArray ) : Data { + + this.lmkHead = bytes + return this + } + + + + fun getLmkAsBin( ) : ByteArray? { + + return this.lmk + } + + + + fun getLmkAsStr( ) : String? { + + if( null == this.lmk ) return null; + return String(lmk!!) + } + + + + fun getLmkAsHex( ) : String? { + + if( null == this.lmk ) return null; + return Util.bytes2HexString(lmk) + } + + + + fun setLmk( bytes : ByteArray ) : Data { + + this.lmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != lmkHead ){ + + + soup.put("lmkHead", this.lmkHead!!) + } + +if( null != lmk ){ + + + soup.put("lmk", this.lmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("lmkHead") ){ + + + this.lmkHead = (soup.get("lmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("lmk") ){ + + + this.lmk = (soup.get("lmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3643")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3643") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO6C.kt b/src/main/java/racal/sunyard/main/dto/DTO6C.kt new file mode 100644 index 0000000..6b5eb0c --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO6C.kt @@ -0,0 +1,1242 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO6C { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var certificateModel : ByteArray? = null + private var certificateLen : ByteArray? = null + private var certificateSn : ByteArray? = null + private var certificateDn : ByteArray? = null + private var dataLen : ByteArray? = null + private var inData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getCertificateModelAsBin( ) : ByteArray? { + + return this.certificateModel + } + + + + fun getCertificateModelAsStr( ) : String? { + + if( null == this.certificateModel ) return null; + return String(certificateModel!!) + } + + + + fun getCertificateModelAsHex( ) : String? { + + if( null == this.certificateModel ) return null; + return Util.bytes2HexString(certificateModel) + } + + + + fun setCertificateModel( bytes : ByteArray ) : Data { + + this.certificateModel = bytes + return this + } + + + enum class CertificateModelOptions( val bin : ByteArray ) { + +OPV证书序号(Util.hexString2Bytes("30")), +OPV证书DN(Util.hexString2Bytes("31")), + } + + fun getCertificateModelCn( ) : String? { + + if( null == certificateModel ) { return null } + +if( "30".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return "证书序号" + +} + + +if( "31".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return "证书 DN" + +} + + return null + } + + + + fun getCertificateModelOptionIndex( ) : Int? { + + if( null == certificateModel ) { return null } + +if( "30".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return 1 + +} + + return null + } + + + + fun getCertificateLenAsBin( ) : ByteArray? { + + return this.certificateLen + } + + + + fun getCertificateLenAsStr( ) : String? { + + if( null == this.certificateLen ) return null; + return String(certificateLen!!) + } + + + + fun getCertificateLenAsHex( ) : String? { + + if( null == this.certificateLen ) return null; + return Util.bytes2HexString(certificateLen) + } + + + + fun setCertificateLen( bytes : ByteArray ) : Data { + + this.certificateLen = bytes + return this + } + + + + fun getCertificateSnAsBin( ) : ByteArray? { + + return this.certificateSn + } + + + + fun getCertificateSnAsStr( ) : String? { + + if( null == this.certificateSn ) return null; + return String(certificateSn!!) + } + + + + fun getCertificateSnAsHex( ) : String? { + + if( null == this.certificateSn ) return null; + return Util.bytes2HexString(certificateSn) + } + + + + fun setCertificateSn( bytes : ByteArray ) : Data { + + this.certificateSn = bytes + return this + } + + + + fun getCertificateDnAsBin( ) : ByteArray? { + + return this.certificateDn + } + + + + fun getCertificateDnAsStr( ) : String? { + + if( null == this.certificateDn ) return null; + return String(certificateDn!!) + } + + + + fun getCertificateDnAsHex( ) : String? { + + if( null == this.certificateDn ) return null; + return Util.bytes2HexString(certificateDn) + } + + + + fun setCertificateDn( bytes : ByteArray ) : Data { + + this.certificateDn = bytes + return this + } + + + + fun getDataLenAsBin( ) : ByteArray? { + + return this.dataLen + } + + + + fun getDataLenAsStr( ) : String? { + + if( null == this.dataLen ) return null; + return String(dataLen!!) + } + + + + fun getDataLenAsHex( ) : String? { + + if( null == this.dataLen ) return null; + return Util.bytes2HexString(dataLen) + } + + + + fun setDataLen( bytes : ByteArray ) : Data { + + this.dataLen = bytes + return this + } + + + + fun getInDataAsBin( ) : ByteArray? { + + return this.inData + } + + + + fun getInDataAsStr( ) : String? { + + if( null == this.inData ) return null; + return String(inData!!) + } + + + + fun getInDataAsHex( ) : String? { + + if( null == this.inData ) return null; + return Util.bytes2HexString(inData) + } + + + + fun setInData( bytes : ByteArray ) : Data { + + this.inData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != certificateModel ){ + + + soup.put("certificateModel", this.certificateModel!!) + soup.put("certificateModel\$option", getCertificateModelOptionIndex()!!) + } + +if( null != certificateLen ){ + + + soup.put("certificateLen", this.certificateLen!!) + } + +if( null != certificateSn ){ + + + soup.put("certificateSn", this.certificateSn!!) + } + +if( null != certificateDn ){ + + + soup.put("certificateDn", this.certificateDn!!) + } + +if( null != dataLen ){ + + + soup.put("dataLen", this.dataLen!!) + } + +if( null != inData ){ + + + soup.put("inData", this.inData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("certificateModel") ){ + + + this.certificateModel = (soup.get("certificateModel") as PacketSection).bytes +} + + +if( soup.containsKey("certificateLen") ){ + + + this.certificateLen = (soup.get("certificateLen") as PacketSection).bytes +} + + +if( soup.containsKey("certificateSn") ){ + + + this.certificateSn = (soup.get("certificateSn") as PacketSection).bytes +} + + +if( soup.containsKey("certificateDn") ){ + + + this.certificateDn = (soup.get("certificateDn") as PacketSection).bytes +} + + +if( soup.containsKey("dataLen") ){ + + + this.dataLen = (soup.get("dataLen") as PacketSection).bytes +} + + +if( soup.containsKey("inData") ){ + + + this.inData = (soup.get("inData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3643")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3643") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var signLen : ByteArray? = null + private var sign : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getSignLenAsBin( ) : ByteArray? { + + return this.signLen + } + + + + fun getSignLenAsStr( ) : String? { + + if( null == this.signLen ) return null; + return String(signLen!!) + } + + + + fun getSignLenAsHex( ) : String? { + + if( null == this.signLen ) return null; + return Util.bytes2HexString(signLen) + } + + + + fun setSignLen( bytes : ByteArray ) : Data { + + this.signLen = bytes + return this + } + + + + fun getSignAsBin( ) : ByteArray? { + + return this.sign + } + + + + fun getSignAsStr( ) : String? { + + if( null == this.sign ) return null; + return String(sign!!) + } + + + + fun getSignAsHex( ) : String? { + + if( null == this.sign ) return null; + return Util.bytes2HexString(sign) + } + + + + fun setSign( bytes : ByteArray ) : Data { + + this.sign = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != signLen ){ + + + soup.put("signLen", this.signLen!!) + } + +if( null != sign ){ + + + soup.put("sign", this.sign!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("signLen") ){ + + + this.signLen = (soup.get("signLen") as PacketSection).bytes +} + + +if( soup.containsKey("sign") ){ + + + this.sign = (soup.get("sign") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3644")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3644") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO6D.kt b/src/main/java/racal/sunyard/main/dto/DTO6D.kt new file mode 100644 index 0000000..dcf8052 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO6D.kt @@ -0,0 +1,1302 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO6D { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var certificateModel : ByteArray? = null + private var certificateLen : ByteArray? = null + private var certificateSn : ByteArray? = null + private var certificateDn : ByteArray? = null + private var organizationNum : ByteArray? = null + private var dataLen : ByteArray? = null + private var inData : ByteArray? = null + private var signLen : ByteArray? = null + private var sign : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getCertificateModelAsBin( ) : ByteArray? { + + return this.certificateModel + } + + + + fun getCertificateModelAsStr( ) : String? { + + if( null == this.certificateModel ) return null; + return String(certificateModel!!) + } + + + + fun getCertificateModelAsHex( ) : String? { + + if( null == this.certificateModel ) return null; + return Util.bytes2HexString(certificateModel) + } + + + + fun setCertificateModel( bytes : ByteArray ) : Data { + + this.certificateModel = bytes + return this + } + + + enum class CertificateModelOptions( val bin : ByteArray ) { + +OPV证书序号(Util.hexString2Bytes("30")), +OPV证书DN(Util.hexString2Bytes("31")), +OPV机构号(Util.hexString2Bytes("32")), + } + + fun getCertificateModelCn( ) : String? { + + if( null == certificateModel ) { return null } + +if( "30".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return "证书序号" + +} + + +if( "31".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return "证书 DN" + +} + + +if( "32".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return "机构号" + +} + + return null + } + + + + fun getCertificateModelOptionIndex( ) : Int? { + + if( null == certificateModel ) { return null } + +if( "30".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return 2 + +} + + return null + } + + + + fun getCertificateLenAsBin( ) : ByteArray? { + + return this.certificateLen + } + + + + fun getCertificateLenAsStr( ) : String? { + + if( null == this.certificateLen ) return null; + return String(certificateLen!!) + } + + + + fun getCertificateLenAsHex( ) : String? { + + if( null == this.certificateLen ) return null; + return Util.bytes2HexString(certificateLen) + } + + + + fun setCertificateLen( bytes : ByteArray ) : Data { + + this.certificateLen = bytes + return this + } + + + + fun getCertificateSnAsBin( ) : ByteArray? { + + return this.certificateSn + } + + + + fun getCertificateSnAsStr( ) : String? { + + if( null == this.certificateSn ) return null; + return String(certificateSn!!) + } + + + + fun getCertificateSnAsHex( ) : String? { + + if( null == this.certificateSn ) return null; + return Util.bytes2HexString(certificateSn) + } + + + + fun setCertificateSn( bytes : ByteArray ) : Data { + + this.certificateSn = bytes + return this + } + + + + fun getCertificateDnAsBin( ) : ByteArray? { + + return this.certificateDn + } + + + + fun getCertificateDnAsStr( ) : String? { + + if( null == this.certificateDn ) return null; + return String(certificateDn!!) + } + + + + fun getCertificateDnAsHex( ) : String? { + + if( null == this.certificateDn ) return null; + return Util.bytes2HexString(certificateDn) + } + + + + fun setCertificateDn( bytes : ByteArray ) : Data { + + this.certificateDn = bytes + return this + } + + + + fun getOrganizationNumAsBin( ) : ByteArray? { + + return this.organizationNum + } + + + + fun getOrganizationNumAsStr( ) : String? { + + if( null == this.organizationNum ) return null; + return String(organizationNum!!) + } + + + + fun getOrganizationNumAsHex( ) : String? { + + if( null == this.organizationNum ) return null; + return Util.bytes2HexString(organizationNum) + } + + + + fun setOrganizationNum( bytes : ByteArray ) : Data { + + this.organizationNum = bytes + return this + } + + + + fun getDataLenAsBin( ) : ByteArray? { + + return this.dataLen + } + + + + fun getDataLenAsStr( ) : String? { + + if( null == this.dataLen ) return null; + return String(dataLen!!) + } + + + + fun getDataLenAsHex( ) : String? { + + if( null == this.dataLen ) return null; + return Util.bytes2HexString(dataLen) + } + + + + fun setDataLen( bytes : ByteArray ) : Data { + + this.dataLen = bytes + return this + } + + + + fun getInDataAsBin( ) : ByteArray? { + + return this.inData + } + + + + fun getInDataAsStr( ) : String? { + + if( null == this.inData ) return null; + return String(inData!!) + } + + + + fun getInDataAsHex( ) : String? { + + if( null == this.inData ) return null; + return Util.bytes2HexString(inData) + } + + + + fun setInData( bytes : ByteArray ) : Data { + + this.inData = bytes + return this + } + + + + fun getSignLenAsBin( ) : ByteArray? { + + return this.signLen + } + + + + fun getSignLenAsStr( ) : String? { + + if( null == this.signLen ) return null; + return String(signLen!!) + } + + + + fun getSignLenAsHex( ) : String? { + + if( null == this.signLen ) return null; + return Util.bytes2HexString(signLen) + } + + + + fun setSignLen( bytes : ByteArray ) : Data { + + this.signLen = bytes + return this + } + + + + fun getSignAsBin( ) : ByteArray? { + + return this.sign + } + + + + fun getSignAsStr( ) : String? { + + if( null == this.sign ) return null; + return String(sign!!) + } + + + + fun getSignAsHex( ) : String? { + + if( null == this.sign ) return null; + return Util.bytes2HexString(sign) + } + + + + fun setSign( bytes : ByteArray ) : Data { + + this.sign = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != certificateModel ){ + + + soup.put("certificateModel", this.certificateModel!!) + soup.put("certificateModel\$option", getCertificateModelOptionIndex()!!) + } + +if( null != certificateLen ){ + + + soup.put("certificateLen", this.certificateLen!!) + } + +if( null != certificateSn ){ + + + soup.put("certificateSn", this.certificateSn!!) + } + +if( null != certificateDn ){ + + + soup.put("certificateDn", this.certificateDn!!) + } + +if( null != organizationNum ){ + + + soup.put("organizationNum", this.organizationNum!!) + } + +if( null != dataLen ){ + + + soup.put("dataLen", this.dataLen!!) + } + +if( null != inData ){ + + + soup.put("inData", this.inData!!) + } + +if( null != signLen ){ + + + soup.put("signLen", this.signLen!!) + } + +if( null != sign ){ + + + soup.put("sign", this.sign!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("certificateModel") ){ + + + this.certificateModel = (soup.get("certificateModel") as PacketSection).bytes +} + + +if( soup.containsKey("certificateLen") ){ + + + this.certificateLen = (soup.get("certificateLen") as PacketSection).bytes +} + + +if( soup.containsKey("certificateSn") ){ + + + this.certificateSn = (soup.get("certificateSn") as PacketSection).bytes +} + + +if( soup.containsKey("certificateDn") ){ + + + this.certificateDn = (soup.get("certificateDn") as PacketSection).bytes +} + + +if( soup.containsKey("organizationNum") ){ + + + this.organizationNum = (soup.get("organizationNum") as PacketSection).bytes +} + + +if( soup.containsKey("dataLen") ){ + + + this.dataLen = (soup.get("dataLen") as PacketSection).bytes +} + + +if( soup.containsKey("inData") ){ + + + this.inData = (soup.get("inData") as PacketSection).bytes +} + + +if( soup.containsKey("signLen") ){ + + + this.signLen = (soup.get("signLen") as PacketSection).bytes +} + + +if( soup.containsKey("sign") ){ + + + this.sign = (soup.get("sign") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3644")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3644") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3645")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3645") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO6E.kt b/src/main/java/racal/sunyard/main/dto/DTO6E.kt new file mode 100644 index 0000000..3ec2f0d --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO6E.kt @@ -0,0 +1,1002 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO6E { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var certificateModel : ByteArray? = null + private var dnLen : ByteArray? = null + private var certificateDn : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getCertificateModelAsBin( ) : ByteArray? { + + return this.certificateModel + } + + + + fun getCertificateModelAsStr( ) : String? { + + if( null == this.certificateModel ) return null; + return String(certificateModel!!) + } + + + + fun getCertificateModelAsHex( ) : String? { + + if( null == this.certificateModel ) return null; + return Util.bytes2HexString(certificateModel) + } + + + + fun setCertificateModel( bytes : ByteArray ) : Data { + + this.certificateModel = bytes + return this + } + + + enum class CertificateModelOptions( val bin : ByteArray ) { + +OPV签名证书(Util.hexString2Bytes("30")), +OPV加密证书(Util.hexString2Bytes("31")), + } + + fun getCertificateModelCn( ) : String? { + + if( null == certificateModel ) { return null } + +if( "30".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return "签名证书" + +} + + +if( "31".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return "加密证书" + +} + + return null + } + + + + fun getCertificateModelOptionIndex( ) : Int? { + + if( null == certificateModel ) { return null } + +if( "30".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.certificateModel) ) ) { + + return 1 + +} + + return null + } + + + + fun getDnLenAsBin( ) : ByteArray? { + + return this.dnLen + } + + + + fun getDnLenAsStr( ) : String? { + + if( null == this.dnLen ) return null; + return String(dnLen!!) + } + + + + fun getDnLenAsHex( ) : String? { + + if( null == this.dnLen ) return null; + return Util.bytes2HexString(dnLen) + } + + + + fun setDnLen( bytes : ByteArray ) : Data { + + this.dnLen = bytes + return this + } + + + + fun getCertificateDnAsBin( ) : ByteArray? { + + return this.certificateDn + } + + + + fun getCertificateDnAsStr( ) : String? { + + if( null == this.certificateDn ) return null; + return String(certificateDn!!) + } + + + + fun getCertificateDnAsHex( ) : String? { + + if( null == this.certificateDn ) return null; + return Util.bytes2HexString(certificateDn) + } + + + + fun setCertificateDn( bytes : ByteArray ) : Data { + + this.certificateDn = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != certificateModel ){ + + + soup.put("certificateModel", this.certificateModel!!) + soup.put("certificateModel\$option", getCertificateModelOptionIndex()!!) + } + +if( null != dnLen ){ + + + soup.put("dnLen", this.dnLen!!) + } + +if( null != certificateDn ){ + + + soup.put("certificateDn", this.certificateDn!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("certificateModel") ){ + + + this.certificateModel = (soup.get("certificateModel") as PacketSection).bytes +} + + +if( soup.containsKey("dnLen") ){ + + + this.dnLen = (soup.get("dnLen") as PacketSection).bytes +} + + +if( soup.containsKey("certificateDn") ){ + + + this.certificateDn = (soup.get("certificateDn") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3645")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3645") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var snLen : ByteArray? = null + private var sn : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效的DN(Util.hexString2Bytes("3231")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的DN" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + return null + } + + + + fun getSnLenAsBin( ) : ByteArray? { + + return this.snLen + } + + + + fun getSnLenAsStr( ) : String? { + + if( null == this.snLen ) return null; + return String(snLen!!) + } + + + + fun getSnLenAsHex( ) : String? { + + if( null == this.snLen ) return null; + return Util.bytes2HexString(snLen) + } + + + + fun setSnLen( bytes : ByteArray ) : Data { + + this.snLen = bytes + return this + } + + + + fun getSnAsBin( ) : ByteArray? { + + return this.sn + } + + + + fun getSnAsStr( ) : String? { + + if( null == this.sn ) return null; + return String(sn!!) + } + + + + fun getSnAsHex( ) : String? { + + if( null == this.sn ) return null; + return Util.bytes2HexString(sn) + } + + + + fun setSn( bytes : ByteArray ) : Data { + + this.sn = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != snLen ){ + + + soup.put("snLen", this.snLen!!) + } + +if( null != sn ){ + + + soup.put("sn", this.sn!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("snLen") ){ + + + this.snLen = (soup.get("snLen") as PacketSection).bytes +} + + +if( soup.containsKey("sn") ){ + + + this.sn = (soup.get("sn") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3646")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3646") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO71.kt b/src/main/java/racal/sunyard/main/dto/DTO71.kt new file mode 100644 index 0000000..5a2276c --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO71.kt @@ -0,0 +1,965 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO71 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var publicKeyLength : ByteArray? = null + private var publicKey : ByteArray? = null + private var key : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getPublicKeyLengthAsBin( ) : ByteArray? { + + return this.publicKeyLength + } + + + + fun getPublicKeyLengthAsStr( ) : String? { + + if( null == this.publicKeyLength ) return null; + return String(publicKeyLength!!) + } + + + + fun getPublicKeyLengthAsHex( ) : String? { + + if( null == this.publicKeyLength ) return null; + return Util.bytes2HexString(publicKeyLength) + } + + + + fun setPublicKeyLength( bytes : ByteArray ) : Data { + + this.publicKeyLength = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != publicKeyLength ){ + + + soup.put("publicKeyLength", this.publicKeyLength!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("publicKeyLength") ){ + + + this.publicKeyLength = (soup.get("publicKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3731")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3731") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var keyLength : ByteArray? = null + private var key : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的签名标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV信息长度错(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的签名标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "信息长度错" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getKeyLengthAsBin( ) : ByteArray? { + + return this.keyLength + } + + + + fun getKeyLengthAsStr( ) : String? { + + if( null == this.keyLength ) return null; + return String(keyLength!!) + } + + + + fun getKeyLengthAsHex( ) : String? { + + if( null == this.keyLength ) return null; + return Util.bytes2HexString(keyLength) + } + + + + fun setKeyLength( bytes : ByteArray ) : Data { + + this.keyLength = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != keyLength ){ + + + soup.put("keyLength", this.keyLength!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("keyLength") ){ + + + this.keyLength = (soup.get("keyLength") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3732")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3732") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO72.kt b/src/main/java/racal/sunyard/main/dto/DTO72.kt new file mode 100644 index 0000000..e659fa8 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO72.kt @@ -0,0 +1,1192 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO72 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var publicKeyLength : ByteArray? = null + private var publicKey : ByteArray? = null + private var lmk : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getPublicKeyLengthAsBin( ) : ByteArray? { + + return this.publicKeyLength + } + + + + fun getPublicKeyLengthAsStr( ) : String? { + + if( null == this.publicKeyLength ) return null; + return String(publicKeyLength!!) + } + + + + fun getPublicKeyLengthAsHex( ) : String? { + + if( null == this.publicKeyLength ) return null; + return Util.bytes2HexString(publicKeyLength) + } + + + + fun setPublicKeyLength( bytes : ByteArray ) : Data { + + this.publicKeyLength = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getLmkAsBin( ) : ByteArray? { + + return this.lmk + } + + + + fun getLmkAsStr( ) : String? { + + if( null == this.lmk ) return null; + return String(lmk!!) + } + + + + fun getLmkAsHex( ) : String? { + + if( null == this.lmk ) return null; + return Util.bytes2HexString(lmk) + } + + + + fun setLmk( bytes : ByteArray ) : Data { + + this.lmk = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != publicKeyLength ){ + + + soup.put("publicKeyLength", this.publicKeyLength!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + +if( null != lmk ){ + + + soup.put("lmk", this.lmk!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("publicKeyLength") ){ + + + this.publicKeyLength = (soup.get("publicKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + +if( soup.containsKey("lmk") ){ + + + this.lmk = (soup.get("lmk") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3732")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3732") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var keyLen : ByteArray? = null + private var key : ByteArray? = null + private var lmkHead : ByteArray? = null + private var lmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getKeyLenAsBin( ) : ByteArray? { + + return this.keyLen + } + + + + fun getKeyLenAsStr( ) : String? { + + if( null == this.keyLen ) return null; + return String(keyLen!!) + } + + + + fun getKeyLenAsHex( ) : String? { + + if( null == this.keyLen ) return null; + return Util.bytes2HexString(keyLen) + } + + + + fun setKeyLen( bytes : ByteArray ) : Data { + + this.keyLen = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getLmkHeadAsBin( ) : ByteArray? { + + return this.lmkHead + } + + + + fun getLmkHeadAsStr( ) : String? { + + if( null == this.lmkHead ) return null; + return String(lmkHead!!) + } + + + + fun getLmkHeadAsHex( ) : String? { + + if( null == this.lmkHead ) return null; + return Util.bytes2HexString(lmkHead) + } + + + + fun setLmkHead( bytes : ByteArray ) : Data { + + this.lmkHead = bytes + return this + } + + + + fun getLmkAsBin( ) : ByteArray? { + + return this.lmk + } + + + + fun getLmkAsStr( ) : String? { + + if( null == this.lmk ) return null; + return String(lmk!!) + } + + + + fun getLmkAsHex( ) : String? { + + if( null == this.lmk ) return null; + return Util.bytes2HexString(lmk) + } + + + + fun setLmk( bytes : ByteArray ) : Data { + + this.lmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != keyLen ){ + + + soup.put("keyLen", this.keyLen!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != lmkHead ){ + + + soup.put("lmkHead", this.lmkHead!!) + } + +if( null != lmk ){ + + + soup.put("lmk", this.lmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("keyLen") ){ + + + this.keyLen = (soup.get("keyLen") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("lmkHead") ){ + + + this.lmkHead = (soup.get("lmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("lmk") ){ + + + this.lmk = (soup.get("lmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3733")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3733") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO73.kt b/src/main/java/racal/sunyard/main/dto/DTO73.kt new file mode 100644 index 0000000..9a0b5e5 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO73.kt @@ -0,0 +1,1237 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO73 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var privateKeyTag : ByteArray? = null + private var privateKeyLength : ByteArray? = null + private var privateKey : ByteArray? = null + private var cipherKeyLength : ByteArray? = null + private var cipherKey : ByteArray? = null + private var lmk : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getPrivateKeyTagAsBin( ) : ByteArray? { + + return this.privateKeyTag + } + + + + fun getPrivateKeyTagAsStr( ) : String? { + + if( null == this.privateKeyTag ) return null; + return String(privateKeyTag!!) + } + + + + fun getPrivateKeyTagAsHex( ) : String? { + + if( null == this.privateKeyTag ) return null; + return Util.bytes2HexString(privateKeyTag) + } + + + + fun setPrivateKeyTag( bytes : ByteArray ) : Data { + + this.privateKeyTag = bytes + return this + } + + + + fun getPrivateKeyLengthAsBin( ) : ByteArray? { + + return this.privateKeyLength + } + + + + fun getPrivateKeyLengthAsStr( ) : String? { + + if( null == this.privateKeyLength ) return null; + return String(privateKeyLength!!) + } + + + + fun getPrivateKeyLengthAsHex( ) : String? { + + if( null == this.privateKeyLength ) return null; + return Util.bytes2HexString(privateKeyLength) + } + + + + fun setPrivateKeyLength( bytes : ByteArray ) : Data { + + this.privateKeyLength = bytes + return this + } + + + + fun getPrivateKeyAsBin( ) : ByteArray? { + + return this.privateKey + } + + + + fun getPrivateKeyAsStr( ) : String? { + + if( null == this.privateKey ) return null; + return String(privateKey!!) + } + + + + fun getPrivateKeyAsHex( ) : String? { + + if( null == this.privateKey ) return null; + return Util.bytes2HexString(privateKey) + } + + + + fun setPrivateKey( bytes : ByteArray ) : Data { + + this.privateKey = bytes + return this + } + + + + fun getCipherKeyLengthAsBin( ) : ByteArray? { + + return this.cipherKeyLength + } + + + + fun getCipherKeyLengthAsStr( ) : String? { + + if( null == this.cipherKeyLength ) return null; + return String(cipherKeyLength!!) + } + + + + fun getCipherKeyLengthAsHex( ) : String? { + + if( null == this.cipherKeyLength ) return null; + return Util.bytes2HexString(cipherKeyLength) + } + + + + fun setCipherKeyLength( bytes : ByteArray ) : Data { + + this.cipherKeyLength = bytes + return this + } + + + + fun getCipherKeyAsBin( ) : ByteArray? { + + return this.cipherKey + } + + + + fun getCipherKeyAsStr( ) : String? { + + if( null == this.cipherKey ) return null; + return String(cipherKey!!) + } + + + + fun getCipherKeyAsHex( ) : String? { + + if( null == this.cipherKey ) return null; + return Util.bytes2HexString(cipherKey) + } + + + + fun setCipherKey( bytes : ByteArray ) : Data { + + this.cipherKey = bytes + return this + } + + + + fun getLmkAsBin( ) : ByteArray? { + + return this.lmk + } + + + + fun getLmkAsStr( ) : String? { + + if( null == this.lmk ) return null; + return String(lmk!!) + } + + + + fun getLmkAsHex( ) : String? { + + if( null == this.lmk ) return null; + return Util.bytes2HexString(lmk) + } + + + + fun setLmk( bytes : ByteArray ) : Data { + + this.lmk = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != privateKeyTag ){ + + + soup.put("privateKeyTag", this.privateKeyTag!!) + } + +if( null != privateKeyLength ){ + + + soup.put("privateKeyLength", this.privateKeyLength!!) + } + +if( null != privateKey ){ + + + soup.put("privateKey", this.privateKey!!) + } + +if( null != cipherKeyLength ){ + + + soup.put("cipherKeyLength", this.cipherKeyLength!!) + } + +if( null != cipherKey ){ + + + soup.put("cipherKey", this.cipherKey!!) + } + +if( null != lmk ){ + + + soup.put("lmk", this.lmk!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("privateKeyTag") ){ + + + this.privateKeyTag = (soup.get("privateKeyTag") as PacketSection).bytes +} + + +if( soup.containsKey("privateKeyLength") ){ + + + this.privateKeyLength = (soup.get("privateKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("privateKey") ){ + + + this.privateKey = (soup.get("privateKey") as PacketSection).bytes +} + + +if( soup.containsKey("cipherKeyLength") ){ + + + this.cipherKeyLength = (soup.get("cipherKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("cipherKey") ){ + + + this.cipherKey = (soup.get("cipherKey") as PacketSection).bytes +} + + +if( soup.containsKey("lmk") ){ + + + this.lmk = (soup.get("lmk") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3733")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3733") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var lmkHead : ByteArray? = null + private var lmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getLmkHeadAsBin( ) : ByteArray? { + + return this.lmkHead + } + + + + fun getLmkHeadAsStr( ) : String? { + + if( null == this.lmkHead ) return null; + return String(lmkHead!!) + } + + + + fun getLmkHeadAsHex( ) : String? { + + if( null == this.lmkHead ) return null; + return Util.bytes2HexString(lmkHead) + } + + + + fun setLmkHead( bytes : ByteArray ) : Data { + + this.lmkHead = bytes + return this + } + + + + fun getLmkAsBin( ) : ByteArray? { + + return this.lmk + } + + + + fun getLmkAsStr( ) : String? { + + if( null == this.lmk ) return null; + return String(lmk!!) + } + + + + fun getLmkAsHex( ) : String? { + + if( null == this.lmk ) return null; + return Util.bytes2HexString(lmk) + } + + + + fun setLmk( bytes : ByteArray ) : Data { + + this.lmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != lmkHead ){ + + + soup.put("lmkHead", this.lmkHead!!) + } + +if( null != lmk ){ + + + soup.put("lmk", this.lmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("lmkHead") ){ + + + this.lmkHead = (soup.get("lmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("lmk") ){ + + + this.lmk = (soup.get("lmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3734")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3734") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO74.kt b/src/main/java/racal/sunyard/main/dto/DTO74.kt new file mode 100644 index 0000000..b40102a --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO74.kt @@ -0,0 +1,1527 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO74 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var signatureDataType : ByteArray? = null + private var hashData : ByteArray? = null + private var userIdLength : ByteArray? = null + private var userId : ByteArray? = null + private var publicKeyLength : ByteArray? = null + private var publicKey : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var privateKeyTag : ByteArray? = null + private var privateKeyLength : ByteArray? = null + private var privateKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getSignatureDataTypeAsBin( ) : ByteArray? { + + return this.signatureDataType + } + + + + fun getSignatureDataTypeAsStr( ) : String? { + + if( null == this.signatureDataType ) return null; + return String(signatureDataType!!) + } + + + + fun getSignatureDataTypeAsHex( ) : String? { + + if( null == this.signatureDataType ) return null; + return Util.bytes2HexString(signatureDataType) + } + + + + fun setSignatureDataType( bytes : ByteArray ) : Data { + + this.signatureDataType = bytes + return this + } + + + enum class SignatureDataTypeOptions( val bin : ByteArray ) { + +OPVHASH(Util.hexString2Bytes("30")), +OPV原数据(Util.hexString2Bytes("31")), + } + + fun getSignatureDataTypeCn( ) : String? { + + if( null == signatureDataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return "HASH" + +} + + +if( "31".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return "原数据" + +} + + return null + } + + + + fun getSignatureDataTypeOptionIndex( ) : Int? { + + if( null == signatureDataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return 1 + +} + + return null + } + + + + fun getHashDataAsBin( ) : ByteArray? { + + return this.hashData + } + + + + fun getHashDataAsStr( ) : String? { + + if( null == this.hashData ) return null; + return String(hashData!!) + } + + + + fun getHashDataAsHex( ) : String? { + + if( null == this.hashData ) return null; + return Util.bytes2HexString(hashData) + } + + + + fun setHashData( bytes : ByteArray ) : Data { + + this.hashData = bytes + return this + } + + + + fun getUserIdLengthAsBin( ) : ByteArray? { + + return this.userIdLength + } + + + + fun getUserIdLengthAsStr( ) : String? { + + if( null == this.userIdLength ) return null; + return String(userIdLength!!) + } + + + + fun getUserIdLengthAsHex( ) : String? { + + if( null == this.userIdLength ) return null; + return Util.bytes2HexString(userIdLength) + } + + + + fun setUserIdLength( bytes : ByteArray ) : Data { + + this.userIdLength = bytes + return this + } + + + + fun getUserIdAsBin( ) : ByteArray? { + + return this.userId + } + + + + fun getUserIdAsStr( ) : String? { + + if( null == this.userId ) return null; + return String(userId!!) + } + + + + fun getUserIdAsHex( ) : String? { + + if( null == this.userId ) return null; + return Util.bytes2HexString(userId) + } + + + + fun setUserId( bytes : ByteArray ) : Data { + + this.userId = bytes + return this + } + + + + fun getPublicKeyLengthAsBin( ) : ByteArray? { + + return this.publicKeyLength + } + + + + fun getPublicKeyLengthAsStr( ) : String? { + + if( null == this.publicKeyLength ) return null; + return String(publicKeyLength!!) + } + + + + fun getPublicKeyLengthAsHex( ) : String? { + + if( null == this.publicKeyLength ) return null; + return Util.bytes2HexString(publicKeyLength) + } + + + + fun setPublicKeyLength( bytes : ByteArray ) : Data { + + this.publicKeyLength = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getPrivateKeyTagAsBin( ) : ByteArray? { + + return this.privateKeyTag + } + + + + fun getPrivateKeyTagAsStr( ) : String? { + + if( null == this.privateKeyTag ) return null; + return String(privateKeyTag!!) + } + + + + fun getPrivateKeyTagAsHex( ) : String? { + + if( null == this.privateKeyTag ) return null; + return Util.bytes2HexString(privateKeyTag) + } + + + + fun setPrivateKeyTag( bytes : ByteArray ) : Data { + + this.privateKeyTag = bytes + return this + } + + + + fun getPrivateKeyLengthAsBin( ) : ByteArray? { + + return this.privateKeyLength + } + + + + fun getPrivateKeyLengthAsStr( ) : String? { + + if( null == this.privateKeyLength ) return null; + return String(privateKeyLength!!) + } + + + + fun getPrivateKeyLengthAsHex( ) : String? { + + if( null == this.privateKeyLength ) return null; + return Util.bytes2HexString(privateKeyLength) + } + + + + fun setPrivateKeyLength( bytes : ByteArray ) : Data { + + this.privateKeyLength = bytes + return this + } + + + + fun getPrivateKeyAsBin( ) : ByteArray? { + + return this.privateKey + } + + + + fun getPrivateKeyAsStr( ) : String? { + + if( null == this.privateKey ) return null; + return String(privateKey!!) + } + + + + fun getPrivateKeyAsHex( ) : String? { + + if( null == this.privateKey ) return null; + return Util.bytes2HexString(privateKey) + } + + + + fun setPrivateKey( bytes : ByteArray ) : Data { + + this.privateKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != signatureDataType ){ + + + soup.put("signatureDataType", this.signatureDataType!!) + soup.put("signatureDataType\$option", getSignatureDataTypeOptionIndex()!!) + } + +if( null != hashData ){ + + + soup.put("hashData", this.hashData!!) + } + +if( null != userIdLength ){ + + + soup.put("userIdLength", this.userIdLength!!) + } + +if( null != userId ){ + + + soup.put("userId", this.userId!!) + } + +if( null != publicKeyLength ){ + + + soup.put("publicKeyLength", this.publicKeyLength!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + +if( null != privateKeyTag ){ + + + soup.put("privateKeyTag", this.privateKeyTag!!) + } + +if( null != privateKeyLength ){ + + + soup.put("privateKeyLength", this.privateKeyLength!!) + } + +if( null != privateKey ){ + + + soup.put("privateKey", this.privateKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("signatureDataType") ){ + + + this.signatureDataType = (soup.get("signatureDataType") as PacketSection).bytes +} + + +if( soup.containsKey("hashData") ){ + + + this.hashData = (soup.get("hashData") as PacketSection).bytes +} + + +if( soup.containsKey("userIdLength") ){ + + + this.userIdLength = (soup.get("userIdLength") as PacketSection).bytes +} + + +if( soup.containsKey("userId") ){ + + + this.userId = (soup.get("userId") as PacketSection).bytes +} + + +if( soup.containsKey("publicKeyLength") ){ + + + this.publicKeyLength = (soup.get("publicKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + +if( soup.containsKey("privateKeyTag") ){ + + + this.privateKeyTag = (soup.get("privateKeyTag") as PacketSection).bytes +} + + +if( soup.containsKey("privateKeyLength") ){ + + + this.privateKeyLength = (soup.get("privateKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("privateKey") ){ + + + this.privateKey = (soup.get("privateKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3734")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3734") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var signatureLen : ByteArray? = null + private var signature : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效的私钥类型(Util.hexString2Bytes("3033")), +OPV无效私钥标记(Util.hexString2Bytes("3034")), +OPV无效的哈希标识(Util.hexString2Bytes("3035")), +OPV无效的签名标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV无效摘要信息语法仅仅无哈希模式(Util.hexString2Bytes("3734")), +OPV公钥长度错误(Util.hexString2Bytes("3736")), +OPV私钥长度错误(Util.hexString2Bytes("3738")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的私钥类型" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效私钥标记" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的哈希标识" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的签名标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效摘要信息语法(仅仅无哈希模式)" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥长度错误" + +} + + +if( "3738".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + +if( "3738".equals(Util.bytes2HexString(this.error) ) ) { + + return 12 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 13 + +} + + return null + } + + + + fun getSignatureLenAsBin( ) : ByteArray? { + + return this.signatureLen + } + + + + fun getSignatureLenAsStr( ) : String? { + + if( null == this.signatureLen ) return null; + return String(signatureLen!!) + } + + + + fun getSignatureLenAsHex( ) : String? { + + if( null == this.signatureLen ) return null; + return Util.bytes2HexString(signatureLen) + } + + + + fun setSignatureLen( bytes : ByteArray ) : Data { + + this.signatureLen = bytes + return this + } + + + + fun getSignatureAsBin( ) : ByteArray? { + + return this.signature + } + + + + fun getSignatureAsStr( ) : String? { + + if( null == this.signature ) return null; + return String(signature!!) + } + + + + fun getSignatureAsHex( ) : String? { + + if( null == this.signature ) return null; + return Util.bytes2HexString(signature) + } + + + + fun setSignature( bytes : ByteArray ) : Data { + + this.signature = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != signatureLen ){ + + + soup.put("signatureLen", this.signatureLen!!) + } + +if( null != signature ){ + + + soup.put("signature", this.signature!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("signatureLen") ){ + + + this.signatureLen = (soup.get("signatureLen") as PacketSection).bytes +} + + +if( soup.containsKey("signature") ){ + + + this.signature = (soup.get("signature") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3735")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3735") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO75.kt b/src/main/java/racal/sunyard/main/dto/DTO75.kt new file mode 100644 index 0000000..ac35516 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO75.kt @@ -0,0 +1,1407 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO75 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var signatureLen : ByteArray? = null + private var signature : ByteArray? = null + private var signatureDataType : ByteArray? = null + private var hashData : ByteArray? = null + private var userIdLength : ByteArray? = null + private var userId : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var publicKeyLength : ByteArray? = null + private var publicKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getSignatureLenAsBin( ) : ByteArray? { + + return this.signatureLen + } + + + + fun getSignatureLenAsStr( ) : String? { + + if( null == this.signatureLen ) return null; + return String(signatureLen!!) + } + + + + fun getSignatureLenAsHex( ) : String? { + + if( null == this.signatureLen ) return null; + return Util.bytes2HexString(signatureLen) + } + + + + fun setSignatureLen( bytes : ByteArray ) : Data { + + this.signatureLen = bytes + return this + } + + + + fun getSignatureAsBin( ) : ByteArray? { + + return this.signature + } + + + + fun getSignatureAsStr( ) : String? { + + if( null == this.signature ) return null; + return String(signature!!) + } + + + + fun getSignatureAsHex( ) : String? { + + if( null == this.signature ) return null; + return Util.bytes2HexString(signature) + } + + + + fun setSignature( bytes : ByteArray ) : Data { + + this.signature = bytes + return this + } + + + + fun getSignatureDataTypeAsBin( ) : ByteArray? { + + return this.signatureDataType + } + + + + fun getSignatureDataTypeAsStr( ) : String? { + + if( null == this.signatureDataType ) return null; + return String(signatureDataType!!) + } + + + + fun getSignatureDataTypeAsHex( ) : String? { + + if( null == this.signatureDataType ) return null; + return Util.bytes2HexString(signatureDataType) + } + + + + fun setSignatureDataType( bytes : ByteArray ) : Data { + + this.signatureDataType = bytes + return this + } + + + enum class SignatureDataTypeOptions( val bin : ByteArray ) { + +OPVHASH(Util.hexString2Bytes("30")), +OPV原数据(Util.hexString2Bytes("31")), + } + + fun getSignatureDataTypeCn( ) : String? { + + if( null == signatureDataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return "HASH" + +} + + +if( "31".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return "原数据" + +} + + return null + } + + + + fun getSignatureDataTypeOptionIndex( ) : Int? { + + if( null == signatureDataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return 1 + +} + + return null + } + + + + fun getHashDataAsBin( ) : ByteArray? { + + return this.hashData + } + + + + fun getHashDataAsStr( ) : String? { + + if( null == this.hashData ) return null; + return String(hashData!!) + } + + + + fun getHashDataAsHex( ) : String? { + + if( null == this.hashData ) return null; + return Util.bytes2HexString(hashData) + } + + + + fun setHashData( bytes : ByteArray ) : Data { + + this.hashData = bytes + return this + } + + + + fun getUserIdLengthAsBin( ) : ByteArray? { + + return this.userIdLength + } + + + + fun getUserIdLengthAsStr( ) : String? { + + if( null == this.userIdLength ) return null; + return String(userIdLength!!) + } + + + + fun getUserIdLengthAsHex( ) : String? { + + if( null == this.userIdLength ) return null; + return Util.bytes2HexString(userIdLength) + } + + + + fun setUserIdLength( bytes : ByteArray ) : Data { + + this.userIdLength = bytes + return this + } + + + + fun getUserIdAsBin( ) : ByteArray? { + + return this.userId + } + + + + fun getUserIdAsStr( ) : String? { + + if( null == this.userId ) return null; + return String(userId!!) + } + + + + fun getUserIdAsHex( ) : String? { + + if( null == this.userId ) return null; + return Util.bytes2HexString(userId) + } + + + + fun setUserId( bytes : ByteArray ) : Data { + + this.userId = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getPublicKeyLengthAsBin( ) : ByteArray? { + + return this.publicKeyLength + } + + + + fun getPublicKeyLengthAsStr( ) : String? { + + if( null == this.publicKeyLength ) return null; + return String(publicKeyLength!!) + } + + + + fun getPublicKeyLengthAsHex( ) : String? { + + if( null == this.publicKeyLength ) return null; + return Util.bytes2HexString(publicKeyLength) + } + + + + fun setPublicKeyLength( bytes : ByteArray ) : Data { + + this.publicKeyLength = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != signatureLen ){ + + + soup.put("signatureLen", this.signatureLen!!) + } + +if( null != signature ){ + + + soup.put("signature", this.signature!!) + } + +if( null != signatureDataType ){ + + + soup.put("signatureDataType", this.signatureDataType!!) + soup.put("signatureDataType\$option", getSignatureDataTypeOptionIndex()!!) + } + +if( null != hashData ){ + + + soup.put("hashData", this.hashData!!) + } + +if( null != userIdLength ){ + + + soup.put("userIdLength", this.userIdLength!!) + } + +if( null != userId ){ + + + soup.put("userId", this.userId!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + +if( null != publicKeyLength ){ + + + soup.put("publicKeyLength", this.publicKeyLength!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("signatureLen") ){ + + + this.signatureLen = (soup.get("signatureLen") as PacketSection).bytes +} + + +if( soup.containsKey("signature") ){ + + + this.signature = (soup.get("signature") as PacketSection).bytes +} + + +if( soup.containsKey("signatureDataType") ){ + + + this.signatureDataType = (soup.get("signatureDataType") as PacketSection).bytes +} + + +if( soup.containsKey("hashData") ){ + + + this.hashData = (soup.get("hashData") as PacketSection).bytes +} + + +if( soup.containsKey("userIdLength") ){ + + + this.userIdLength = (soup.get("userIdLength") as PacketSection).bytes +} + + +if( soup.containsKey("userId") ){ + + + this.userId = (soup.get("userId") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + +if( soup.containsKey("publicKeyLength") ){ + + + this.publicKeyLength = (soup.get("publicKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3735")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3735") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV签名校验失败(Util.hexString2Bytes("3032")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的哈希标识(Util.hexString2Bytes("3035")), +OPV无效的签名标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV无效摘要信息语法仅仅无哈希模式(Util.hexString2Bytes("3734")), +OPV公钥长度错误(Util.hexString2Bytes("3736")), +OPV明文数据块错误(Util.hexString2Bytes("3737")), +OPV哈希算法对象标识错误(Util.hexString2Bytes("3739")), +OPV信息长度错(Util.hexString2Bytes("3830")), +OPV签名长度错(Util.hexString2Bytes("3831")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3032".equals(Util.bytes2HexString(this.error) ) ) { + + return "签名校验失败" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的哈希标识" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的签名标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效摘要信息语法(仅仅无哈希模式)" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥长度错误" + +} + + +if( "3737".equals(Util.bytes2HexString(this.error) ) ) { + + return "明文数据块错误" + +} + + +if( "3739".equals(Util.bytes2HexString(this.error) ) ) { + + return "哈希算法对象标识错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "信息长度错" + +} + + +if( "3831".equals(Util.bytes2HexString(this.error) ) ) { + + return "签名长度错" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3032".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3737".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + +if( "3739".equals(Util.bytes2HexString(this.error) ) ) { + + return 12 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 13 + +} + + +if( "3831".equals(Util.bytes2HexString(this.error) ) ) { + + return 14 + +} + + return null + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3736")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3736") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO76.kt b/src/main/java/racal/sunyard/main/dto/DTO76.kt new file mode 100644 index 0000000..8bccd16 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO76.kt @@ -0,0 +1,1255 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO76 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var packSn : ByteArray? = null + private var dataLength : ByteArray? = null + private var msg : ByteArray? = null + private var userIdLength : ByteArray? = null + private var userId : ByteArray? = null + private var publicKeyLength : ByteArray? = null + private var publicKey : ByteArray? = null + private var filterDataLen : ByteArray? = null + private var filterData : ByteArray? = null + + + fun getPackSnAsBin( ) : ByteArray? { + + return this.packSn + } + + + + fun getPackSnAsStr( ) : String? { + + if( null == this.packSn ) return null; + return String(packSn!!) + } + + + + fun getPackSnAsHex( ) : String? { + + if( null == this.packSn ) return null; + return Util.bytes2HexString(packSn) + } + + + + fun setPackSn( bytes : ByteArray ) : Data { + + this.packSn = bytes + return this + } + + + enum class PackSnOptions( val bin : ByteArray ) { + +OPV仅一块(Util.hexString2Bytes("30")), +OPV第一块(Util.hexString2Bytes("31")), +OPV中间块(Util.hexString2Bytes("32")), +OPV最后块(Util.hexString2Bytes("33")), + } + + fun getPackSnCn( ) : String? { + + if( null == packSn ) { return null } + +if( "30".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "仅一块" + +} + + +if( "31".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "第一块" + +} + + +if( "32".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "中间块" + +} + + +if( "33".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "最后块" + +} + + return null + } + + + + fun getPackSnOptionIndex( ) : Int? { + + if( null == packSn ) { return null } + +if( "30".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 2 + +} + + +if( "33".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 3 + +} + + return null + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getMsgAsBin( ) : ByteArray? { + + return this.msg + } + + + + fun getMsgAsStr( ) : String? { + + if( null == this.msg ) return null; + return String(msg!!) + } + + + + fun getMsgAsHex( ) : String? { + + if( null == this.msg ) return null; + return Util.bytes2HexString(msg) + } + + + + fun setMsg( bytes : ByteArray ) : Data { + + this.msg = bytes + return this + } + + + + fun getUserIdLengthAsBin( ) : ByteArray? { + + return this.userIdLength + } + + + + fun getUserIdLengthAsStr( ) : String? { + + if( null == this.userIdLength ) return null; + return String(userIdLength!!) + } + + + + fun getUserIdLengthAsHex( ) : String? { + + if( null == this.userIdLength ) return null; + return Util.bytes2HexString(userIdLength) + } + + + + fun setUserIdLength( bytes : ByteArray ) : Data { + + this.userIdLength = bytes + return this + } + + + + fun getUserIdAsBin( ) : ByteArray? { + + return this.userId + } + + + + fun getUserIdAsStr( ) : String? { + + if( null == this.userId ) return null; + return String(userId!!) + } + + + + fun getUserIdAsHex( ) : String? { + + if( null == this.userId ) return null; + return Util.bytes2HexString(userId) + } + + + + fun setUserId( bytes : ByteArray ) : Data { + + this.userId = bytes + return this + } + + + + fun getPublicKeyLengthAsBin( ) : ByteArray? { + + return this.publicKeyLength + } + + + + fun getPublicKeyLengthAsStr( ) : String? { + + if( null == this.publicKeyLength ) return null; + return String(publicKeyLength!!) + } + + + + fun getPublicKeyLengthAsHex( ) : String? { + + if( null == this.publicKeyLength ) return null; + return Util.bytes2HexString(publicKeyLength) + } + + + + fun setPublicKeyLength( bytes : ByteArray ) : Data { + + this.publicKeyLength = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getFilterDataLenAsBin( ) : ByteArray? { + + return this.filterDataLen + } + + + + fun getFilterDataLenAsStr( ) : String? { + + if( null == this.filterDataLen ) return null; + return String(filterDataLen!!) + } + + + + fun getFilterDataLenAsHex( ) : String? { + + if( null == this.filterDataLen ) return null; + return Util.bytes2HexString(filterDataLen) + } + + + + fun setFilterDataLen( bytes : ByteArray ) : Data { + + this.filterDataLen = bytes + return this + } + + + + fun getFilterDataAsBin( ) : ByteArray? { + + return this.filterData + } + + + + fun getFilterDataAsStr( ) : String? { + + if( null == this.filterData ) return null; + return String(filterData!!) + } + + + + fun getFilterDataAsHex( ) : String? { + + if( null == this.filterData ) return null; + return Util.bytes2HexString(filterData) + } + + + + fun setFilterData( bytes : ByteArray ) : Data { + + this.filterData = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != packSn ){ + + + soup.put("packSn", this.packSn!!) + soup.put("packSn\$option", getPackSnOptionIndex()!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != msg ){ + + + soup.put("msg", this.msg!!) + } + +if( null != userIdLength ){ + + + soup.put("userIdLength", this.userIdLength!!) + } + +if( null != userId ){ + + + soup.put("userId", this.userId!!) + } + +if( null != publicKeyLength ){ + + + soup.put("publicKeyLength", this.publicKeyLength!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + +if( null != filterDataLen ){ + + + soup.put("filterDataLen", this.filterDataLen!!) + } + +if( null != filterData ){ + + + soup.put("filterData", this.filterData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("packSn") ){ + + + this.packSn = (soup.get("packSn") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("msg") ){ + + + this.msg = (soup.get("msg") as PacketSection).bytes +} + + +if( soup.containsKey("userIdLength") ){ + + + this.userIdLength = (soup.get("userIdLength") as PacketSection).bytes +} + + +if( soup.containsKey("userId") ){ + + + this.userId = (soup.get("userId") as PacketSection).bytes +} + + +if( soup.containsKey("publicKeyLength") ){ + + + this.publicKeyLength = (soup.get("publicKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + +if( soup.containsKey("filterDataLen") ){ + + + this.filterDataLen = (soup.get("filterDataLen") as PacketSection).bytes +} + + +if( soup.containsKey("filterData") ){ + + + this.filterData = (soup.get("filterData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3736")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3736") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var hash : ByteArray? = null + private var filterDataLen : ByteArray? = null + private var filterData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV数据长度错(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + return null + } + + + + fun getHashAsBin( ) : ByteArray? { + + return this.hash + } + + + + fun getHashAsStr( ) : String? { + + if( null == this.hash ) return null; + return String(hash!!) + } + + + + fun getHashAsHex( ) : String? { + + if( null == this.hash ) return null; + return Util.bytes2HexString(hash) + } + + + + fun setHash( bytes : ByteArray ) : Data { + + this.hash = bytes + return this + } + + + + fun getFilterDataLenAsBin( ) : ByteArray? { + + return this.filterDataLen + } + + + + fun getFilterDataLenAsStr( ) : String? { + + if( null == this.filterDataLen ) return null; + return String(filterDataLen!!) + } + + + + fun getFilterDataLenAsHex( ) : String? { + + if( null == this.filterDataLen ) return null; + return Util.bytes2HexString(filterDataLen) + } + + + + fun setFilterDataLen( bytes : ByteArray ) : Data { + + this.filterDataLen = bytes + return this + } + + + + fun getFilterDataAsBin( ) : ByteArray? { + + return this.filterData + } + + + + fun getFilterDataAsStr( ) : String? { + + if( null == this.filterData ) return null; + return String(filterData!!) + } + + + + fun getFilterDataAsHex( ) : String? { + + if( null == this.filterData ) return null; + return Util.bytes2HexString(filterData) + } + + + + fun setFilterData( bytes : ByteArray ) : Data { + + this.filterData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != hash ){ + + + soup.put("hash", this.hash!!) + } + +if( null != filterDataLen ){ + + + soup.put("filterDataLen", this.filterDataLen!!) + } + +if( null != filterData ){ + + + soup.put("filterData", this.filterData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("hash") ){ + + + this.hash = (soup.get("hash") as PacketSection).bytes +} + + +if( soup.containsKey("filterDataLen") ){ + + + this.filterDataLen = (soup.get("filterDataLen") as PacketSection).bytes +} + + +if( soup.containsKey("filterData") ){ + + + this.filterData = (soup.get("filterData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3737")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3737") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO77.kt b/src/main/java/racal/sunyard/main/dto/DTO77.kt new file mode 100644 index 0000000..80d6a9a --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO77.kt @@ -0,0 +1,1093 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO77 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var algorithmKey : ByteArray? = null + private var fillKey : ByteArray? = null + private var publicKeyLength : ByteArray? = null + private var publicKey : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + enum class AlgorithmKeyOptions( val bin : ByteArray ) { + +OPVRSA(Util.hexString2Bytes("30")), +OPVSM2(Util.hexString2Bytes("31")), + } + + fun getAlgorithmKeyCn( ) : String? { + + if( null == algorithmKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return "RSA" + +} + + +if( "31".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return "SM2" + +} + + return null + } + + + + fun getAlgorithmKeyOptionIndex( ) : Int? { + + if( null == algorithmKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return 1 + +} + + return null + } + + + + fun getFillKeyAsBin( ) : ByteArray? { + + return this.fillKey + } + + + + fun getFillKeyAsStr( ) : String? { + + if( null == this.fillKey ) return null; + return String(fillKey!!) + } + + + + fun getFillKeyAsHex( ) : String? { + + if( null == this.fillKey ) return null; + return Util.bytes2HexString(fillKey) + } + + + + fun setFillKey( bytes : ByteArray ) : Data { + + this.fillKey = bytes + return this + } + + + enum class FillKeyOptions( val bin : ByteArray ) { + +OPV数据长度必须等于密钥长度(Util.hexString2Bytes("30")), +OPVPKCS1v15填充方式(Util.hexString2Bytes("31")), + } + + fun getFillKeyCn( ) : String? { + + if( null == fillKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return "数据长度必须等于密钥长度" + +} + + +if( "31".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return "PKCS#1 v1.5 填充方式" + +} + + return null + } + + + + fun getFillKeyOptionIndex( ) : Int? { + + if( null == fillKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return 1 + +} + + return null + } + + + + fun getPublicKeyLengthAsBin( ) : ByteArray? { + + return this.publicKeyLength + } + + + + fun getPublicKeyLengthAsStr( ) : String? { + + if( null == this.publicKeyLength ) return null; + return String(publicKeyLength!!) + } + + + + fun getPublicKeyLengthAsHex( ) : String? { + + if( null == this.publicKeyLength ) return null; + return Util.bytes2HexString(publicKeyLength) + } + + + + fun setPublicKeyLength( bytes : ByteArray ) : Data { + + this.publicKeyLength = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != algorithmKey ){ + + + soup.put("AlgorithmKey", this.algorithmKey!!) + soup.put("AlgorithmKey\$option", getAlgorithmKeyOptionIndex()!!) + } + +if( null != fillKey ){ + + + soup.put("fillKey", this.fillKey!!) + soup.put("fillKey\$option", getFillKeyOptionIndex()!!) + } + +if( null != publicKeyLength ){ + + + soup.put("publicKeyLength", this.publicKeyLength!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("AlgorithmKey") ){ + + + this.algorithmKey = (soup.get("AlgorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("fillKey") ){ + + + this.fillKey = (soup.get("fillKey") as PacketSection).bytes +} + + +if( soup.containsKey("publicKeyLength") ){ + + + this.publicKeyLength = (soup.get("publicKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3737")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3737") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var dataLen : ByteArray? = null + private var cipherData : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的算法标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的算法标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + return null + } + + + + fun getDataLenAsBin( ) : ByteArray? { + + return this.dataLen + } + + + + fun getDataLenAsStr( ) : String? { + + if( null == this.dataLen ) return null; + return String(dataLen!!) + } + + + + fun getDataLenAsHex( ) : String? { + + if( null == this.dataLen ) return null; + return Util.bytes2HexString(dataLen) + } + + + + fun setDataLen( bytes : ByteArray ) : Data { + + this.dataLen = bytes + return this + } + + + + fun getCipherDataAsBin( ) : ByteArray? { + + return this.cipherData + } + + + + fun getCipherDataAsStr( ) : String? { + + if( null == this.cipherData ) return null; + return String(cipherData!!) + } + + + + fun getCipherDataAsHex( ) : String? { + + if( null == this.cipherData ) return null; + return Util.bytes2HexString(cipherData) + } + + + + fun setCipherData( bytes : ByteArray ) : Data { + + this.cipherData = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != dataLen ){ + + + soup.put("dataLen", this.dataLen!!) + } + +if( null != cipherData ){ + + + soup.put("cipherData", this.cipherData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("dataLen") ){ + + + this.dataLen = (soup.get("dataLen") as PacketSection).bytes +} + + +if( soup.containsKey("cipherData") ){ + + + this.cipherData = (soup.get("cipherData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3738")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3738") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO78.kt b/src/main/java/racal/sunyard/main/dto/DTO78.kt new file mode 100644 index 0000000..e42f7dc --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO78.kt @@ -0,0 +1,1337 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO78 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var algorithmKey : ByteArray? = null + private var fillKey : ByteArray? = null + private var privateKeyTag : ByteArray? = null + private var privateKeyLength : ByteArray? = null + private var privateKey : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + enum class AlgorithmKeyOptions( val bin : ByteArray ) { + +OPVRSA(Util.hexString2Bytes("30")), +OPVSM2(Util.hexString2Bytes("31")), + } + + fun getAlgorithmKeyCn( ) : String? { + + if( null == algorithmKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return "RSA" + +} + + +if( "31".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return "SM2" + +} + + return null + } + + + + fun getAlgorithmKeyOptionIndex( ) : Int? { + + if( null == algorithmKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return 1 + +} + + return null + } + + + + fun getFillKeyAsBin( ) : ByteArray? { + + return this.fillKey + } + + + + fun getFillKeyAsStr( ) : String? { + + if( null == this.fillKey ) return null; + return String(fillKey!!) + } + + + + fun getFillKeyAsHex( ) : String? { + + if( null == this.fillKey ) return null; + return Util.bytes2HexString(fillKey) + } + + + + fun setFillKey( bytes : ByteArray ) : Data { + + this.fillKey = bytes + return this + } + + + enum class FillKeyOptions( val bin : ByteArray ) { + +OPV数据长度必须等于密钥长度(Util.hexString2Bytes("30")), +OPVPKCS1v15填充方式(Util.hexString2Bytes("31")), + } + + fun getFillKeyCn( ) : String? { + + if( null == fillKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return "数据长度必须等于密钥长度" + +} + + +if( "31".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return "PKCS#1 v1.5 填充方式" + +} + + return null + } + + + + fun getFillKeyOptionIndex( ) : Int? { + + if( null == fillKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return 1 + +} + + return null + } + + + + fun getPrivateKeyTagAsBin( ) : ByteArray? { + + return this.privateKeyTag + } + + + + fun getPrivateKeyTagAsStr( ) : String? { + + if( null == this.privateKeyTag ) return null; + return String(privateKeyTag!!) + } + + + + fun getPrivateKeyTagAsHex( ) : String? { + + if( null == this.privateKeyTag ) return null; + return Util.bytes2HexString(privateKeyTag) + } + + + + fun setPrivateKeyTag( bytes : ByteArray ) : Data { + + this.privateKeyTag = bytes + return this + } + + + + fun getPrivateKeyLengthAsBin( ) : ByteArray? { + + return this.privateKeyLength + } + + + + fun getPrivateKeyLengthAsStr( ) : String? { + + if( null == this.privateKeyLength ) return null; + return String(privateKeyLength!!) + } + + + + fun getPrivateKeyLengthAsHex( ) : String? { + + if( null == this.privateKeyLength ) return null; + return Util.bytes2HexString(privateKeyLength) + } + + + + fun setPrivateKeyLength( bytes : ByteArray ) : Data { + + this.privateKeyLength = bytes + return this + } + + + + fun getPrivateKeyAsBin( ) : ByteArray? { + + return this.privateKey + } + + + + fun getPrivateKeyAsStr( ) : String? { + + if( null == this.privateKey ) return null; + return String(privateKey!!) + } + + + + fun getPrivateKeyAsHex( ) : String? { + + if( null == this.privateKey ) return null; + return Util.bytes2HexString(privateKey) + } + + + + fun setPrivateKey( bytes : ByteArray ) : Data { + + this.privateKey = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != algorithmKey ){ + + + soup.put("AlgorithmKey", this.algorithmKey!!) + soup.put("AlgorithmKey\$option", getAlgorithmKeyOptionIndex()!!) + } + +if( null != fillKey ){ + + + soup.put("fillKey", this.fillKey!!) + soup.put("fillKey\$option", getFillKeyOptionIndex()!!) + } + +if( null != privateKeyTag ){ + + + soup.put("privateKeyTag", this.privateKeyTag!!) + } + +if( null != privateKeyLength ){ + + + soup.put("privateKeyLength", this.privateKeyLength!!) + } + +if( null != privateKey ){ + + + soup.put("privateKey", this.privateKey!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("AlgorithmKey") ){ + + + this.algorithmKey = (soup.get("AlgorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("fillKey") ){ + + + this.fillKey = (soup.get("fillKey") as PacketSection).bytes +} + + +if( soup.containsKey("privateKeyTag") ){ + + + this.privateKeyTag = (soup.get("privateKeyTag") as PacketSection).bytes +} + + +if( soup.containsKey("privateKeyLength") ){ + + + this.privateKeyLength = (soup.get("privateKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("privateKey") ){ + + + this.privateKey = (soup.get("privateKey") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3738")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3738") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var dataLen : ByteArray? = null + private var data : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV私钥格式不对(Util.hexString2Bytes("3034")), +OPV无效的算法标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPV解密错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥格式不对" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的算法标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "解密错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getDataLenAsBin( ) : ByteArray? { + + return this.dataLen + } + + + + fun getDataLenAsStr( ) : String? { + + if( null == this.dataLen ) return null; + return String(dataLen!!) + } + + + + fun getDataLenAsHex( ) : String? { + + if( null == this.dataLen ) return null; + return Util.bytes2HexString(dataLen) + } + + + + fun setDataLen( bytes : ByteArray ) : Data { + + this.dataLen = bytes + return this + } + + + + fun getDataAsBin( ) : ByteArray? { + + return this.data + } + + + + fun getDataAsStr( ) : String? { + + if( null == this.data ) return null; + return String(data!!) + } + + + + fun getDataAsHex( ) : String? { + + if( null == this.data ) return null; + return Util.bytes2HexString(data) + } + + + + fun setData( bytes : ByteArray ) : Data { + + this.data = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != dataLen ){ + + + soup.put("dataLen", this.dataLen!!) + } + +if( null != data ){ + + + soup.put("data", this.data!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("dataLen") ){ + + + this.dataLen = (soup.get("dataLen") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + + + this.data = (soup.get("data") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3739")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3739") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO79.kt b/src/main/java/racal/sunyard/main/dto/DTO79.kt new file mode 100644 index 0000000..547dcef --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO79.kt @@ -0,0 +1,1138 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO79 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var algorithmKey : ByteArray? = null + private var fillKey : ByteArray? = null + private var privateKeyTag : ByteArray? = null + private var privateKeyLength : ByteArray? = null + private var privateKey : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + enum class AlgorithmKeyOptions( val bin : ByteArray ) { + +OPVRSA(Util.hexString2Bytes("30")), +OPVSM2(Util.hexString2Bytes("31")), + } + + fun getAlgorithmKeyCn( ) : String? { + + if( null == algorithmKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return "RSA" + +} + + +if( "31".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return "SM2" + +} + + return null + } + + + + fun getAlgorithmKeyOptionIndex( ) : Int? { + + if( null == algorithmKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return 1 + +} + + return null + } + + + + fun getFillKeyAsBin( ) : ByteArray? { + + return this.fillKey + } + + + + fun getFillKeyAsStr( ) : String? { + + if( null == this.fillKey ) return null; + return String(fillKey!!) + } + + + + fun getFillKeyAsHex( ) : String? { + + if( null == this.fillKey ) return null; + return Util.bytes2HexString(fillKey) + } + + + + fun setFillKey( bytes : ByteArray ) : Data { + + this.fillKey = bytes + return this + } + + + enum class FillKeyOptions( val bin : ByteArray ) { + +OPV数据长度必须等于密钥长度(Util.hexString2Bytes("30")), +OPVPKCS1v15填充方式(Util.hexString2Bytes("31")), + } + + fun getFillKeyCn( ) : String? { + + if( null == fillKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return "数据长度必须等于密钥长度" + +} + + +if( "31".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return "PKCS#1 v1.5 填充方式" + +} + + return null + } + + + + fun getFillKeyOptionIndex( ) : Int? { + + if( null == fillKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return 1 + +} + + return null + } + + + + fun getPrivateKeyTagAsBin( ) : ByteArray? { + + return this.privateKeyTag + } + + + + fun getPrivateKeyTagAsStr( ) : String? { + + if( null == this.privateKeyTag ) return null; + return String(privateKeyTag!!) + } + + + + fun getPrivateKeyTagAsHex( ) : String? { + + if( null == this.privateKeyTag ) return null; + return Util.bytes2HexString(privateKeyTag) + } + + + + fun setPrivateKeyTag( bytes : ByteArray ) : Data { + + this.privateKeyTag = bytes + return this + } + + + + fun getPrivateKeyLengthAsBin( ) : ByteArray? { + + return this.privateKeyLength + } + + + + fun getPrivateKeyLengthAsStr( ) : String? { + + if( null == this.privateKeyLength ) return null; + return String(privateKeyLength!!) + } + + + + fun getPrivateKeyLengthAsHex( ) : String? { + + if( null == this.privateKeyLength ) return null; + return Util.bytes2HexString(privateKeyLength) + } + + + + fun setPrivateKeyLength( bytes : ByteArray ) : Data { + + this.privateKeyLength = bytes + return this + } + + + + fun getPrivateKeyAsBin( ) : ByteArray? { + + return this.privateKey + } + + + + fun getPrivateKeyAsStr( ) : String? { + + if( null == this.privateKey ) return null; + return String(privateKey!!) + } + + + + fun getPrivateKeyAsHex( ) : String? { + + if( null == this.privateKey ) return null; + return Util.bytes2HexString(privateKey) + } + + + + fun setPrivateKey( bytes : ByteArray ) : Data { + + this.privateKey = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != algorithmKey ){ + + + soup.put("AlgorithmKey", this.algorithmKey!!) + soup.put("AlgorithmKey\$option", getAlgorithmKeyOptionIndex()!!) + } + +if( null != fillKey ){ + + + soup.put("fillKey", this.fillKey!!) + soup.put("fillKey\$option", getFillKeyOptionIndex()!!) + } + +if( null != privateKeyTag ){ + + + soup.put("privateKeyTag", this.privateKeyTag!!) + } + +if( null != privateKeyLength ){ + + + soup.put("privateKeyLength", this.privateKeyLength!!) + } + +if( null != privateKey ){ + + + soup.put("privateKey", this.privateKey!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("AlgorithmKey") ){ + + + this.algorithmKey = (soup.get("AlgorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("fillKey") ){ + + + this.fillKey = (soup.get("fillKey") as PacketSection).bytes +} + + +if( soup.containsKey("privateKeyTag") ){ + + + this.privateKeyTag = (soup.get("privateKeyTag") as PacketSection).bytes +} + + +if( soup.containsKey("privateKeyLength") ){ + + + this.privateKeyLength = (soup.get("privateKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("privateKey") ){ + + + this.privateKey = (soup.get("privateKey") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3739")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3739") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var dataLen : ByteArray? = null + private var cipherData : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV私钥格式不对(Util.hexString2Bytes("3034")), +OPV无效的算法标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥格式不对" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的算法标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + return null + } + + + + fun getDataLenAsBin( ) : ByteArray? { + + return this.dataLen + } + + + + fun getDataLenAsStr( ) : String? { + + if( null == this.dataLen ) return null; + return String(dataLen!!) + } + + + + fun getDataLenAsHex( ) : String? { + + if( null == this.dataLen ) return null; + return Util.bytes2HexString(dataLen) + } + + + + fun setDataLen( bytes : ByteArray ) : Data { + + this.dataLen = bytes + return this + } + + + + fun getCipherDataAsBin( ) : ByteArray? { + + return this.cipherData + } + + + + fun getCipherDataAsStr( ) : String? { + + if( null == this.cipherData ) return null; + return String(cipherData!!) + } + + + + fun getCipherDataAsHex( ) : String? { + + if( null == this.cipherData ) return null; + return Util.bytes2HexString(cipherData) + } + + + + fun setCipherData( bytes : ByteArray ) : Data { + + this.cipherData = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != dataLen ){ + + + soup.put("dataLen", this.dataLen!!) + } + +if( null != cipherData ){ + + + soup.put("cipherData", this.cipherData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("dataLen") ){ + + + this.dataLen = (soup.get("dataLen") as PacketSection).bytes +} + + +if( soup.containsKey("cipherData") ){ + + + this.cipherData = (soup.get("cipherData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3741")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3741") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO7A.kt b/src/main/java/racal/sunyard/main/dto/DTO7A.kt new file mode 100644 index 0000000..9c74aec --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO7A.kt @@ -0,0 +1,1093 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO7A { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var algorithmKey : ByteArray? = null + private var fillKey : ByteArray? = null + private var publicKeyLength : ByteArray? = null + private var publicKey : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + enum class AlgorithmKeyOptions( val bin : ByteArray ) { + +OPVRSA(Util.hexString2Bytes("30")), +OPVSM2(Util.hexString2Bytes("31")), + } + + fun getAlgorithmKeyCn( ) : String? { + + if( null == algorithmKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return "RSA" + +} + + +if( "31".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return "SM2" + +} + + return null + } + + + + fun getAlgorithmKeyOptionIndex( ) : Int? { + + if( null == algorithmKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.algorithmKey) ) ) { + + return 1 + +} + + return null + } + + + + fun getFillKeyAsBin( ) : ByteArray? { + + return this.fillKey + } + + + + fun getFillKeyAsStr( ) : String? { + + if( null == this.fillKey ) return null; + return String(fillKey!!) + } + + + + fun getFillKeyAsHex( ) : String? { + + if( null == this.fillKey ) return null; + return Util.bytes2HexString(fillKey) + } + + + + fun setFillKey( bytes : ByteArray ) : Data { + + this.fillKey = bytes + return this + } + + + enum class FillKeyOptions( val bin : ByteArray ) { + +OPV数据长度必须等于密钥长度(Util.hexString2Bytes("30")), +OPVPKCS1v15填充方式(Util.hexString2Bytes("31")), + } + + fun getFillKeyCn( ) : String? { + + if( null == fillKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return "数据长度必须等于密钥长度" + +} + + +if( "31".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return "PKCS#1 v1.5 填充方式" + +} + + return null + } + + + + fun getFillKeyOptionIndex( ) : Int? { + + if( null == fillKey ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.fillKey) ) ) { + + return 1 + +} + + return null + } + + + + fun getPublicKeyLengthAsBin( ) : ByteArray? { + + return this.publicKeyLength + } + + + + fun getPublicKeyLengthAsStr( ) : String? { + + if( null == this.publicKeyLength ) return null; + return String(publicKeyLength!!) + } + + + + fun getPublicKeyLengthAsHex( ) : String? { + + if( null == this.publicKeyLength ) return null; + return Util.bytes2HexString(publicKeyLength) + } + + + + fun setPublicKeyLength( bytes : ByteArray ) : Data { + + this.publicKeyLength = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != algorithmKey ){ + + + soup.put("AlgorithmKey", this.algorithmKey!!) + soup.put("AlgorithmKey\$option", getAlgorithmKeyOptionIndex()!!) + } + +if( null != fillKey ){ + + + soup.put("fillKey", this.fillKey!!) + soup.put("fillKey\$option", getFillKeyOptionIndex()!!) + } + +if( null != publicKeyLength ){ + + + soup.put("publicKeyLength", this.publicKeyLength!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("AlgorithmKey") ){ + + + this.algorithmKey = (soup.get("AlgorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("fillKey") ){ + + + this.fillKey = (soup.get("fillKey") as PacketSection).bytes +} + + +if( soup.containsKey("publicKeyLength") ){ + + + this.publicKeyLength = (soup.get("publicKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3741")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3741") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var dataLen : ByteArray? = null + private var cipherData : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的算法标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的算法标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + return null + } + + + + fun getDataLenAsBin( ) : ByteArray? { + + return this.dataLen + } + + + + fun getDataLenAsStr( ) : String? { + + if( null == this.dataLen ) return null; + return String(dataLen!!) + } + + + + fun getDataLenAsHex( ) : String? { + + if( null == this.dataLen ) return null; + return Util.bytes2HexString(dataLen) + } + + + + fun setDataLen( bytes : ByteArray ) : Data { + + this.dataLen = bytes + return this + } + + + + fun getCipherDataAsBin( ) : ByteArray? { + + return this.cipherData + } + + + + fun getCipherDataAsStr( ) : String? { + + if( null == this.cipherData ) return null; + return String(cipherData!!) + } + + + + fun getCipherDataAsHex( ) : String? { + + if( null == this.cipherData ) return null; + return Util.bytes2HexString(cipherData) + } + + + + fun setCipherData( bytes : ByteArray ) : Data { + + this.cipherData = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != dataLen ){ + + + soup.put("dataLen", this.dataLen!!) + } + +if( null != cipherData ){ + + + soup.put("cipherData", this.cipherData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("dataLen") ){ + + + this.dataLen = (soup.get("dataLen") as PacketSection).bytes +} + + +if( soup.containsKey("cipherData") ){ + + + this.cipherData = (soup.get("cipherData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3742")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3742") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO7B.kt b/src/main/java/racal/sunyard/main/dto/DTO7B.kt new file mode 100644 index 0000000..6544470 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO7B.kt @@ -0,0 +1,1382 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO7B { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var signatureDataType : ByteArray? = null + private var hashMark : ByteArray? = null + private var hashData : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var privateKeyTag : ByteArray? = null + private var privateKeyLength : ByteArray? = null + private var privateKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getSignatureDataTypeAsBin( ) : ByteArray? { + + return this.signatureDataType + } + + + + fun getSignatureDataTypeAsStr( ) : String? { + + if( null == this.signatureDataType ) return null; + return String(signatureDataType!!) + } + + + + fun getSignatureDataTypeAsHex( ) : String? { + + if( null == this.signatureDataType ) return null; + return Util.bytes2HexString(signatureDataType) + } + + + + fun setSignatureDataType( bytes : ByteArray ) : Data { + + this.signatureDataType = bytes + return this + } + + + enum class SignatureDataTypeOptions( val bin : ByteArray ) { + +OPVHASH(Util.hexString2Bytes("30")), +OPV原数据(Util.hexString2Bytes("31")), + } + + fun getSignatureDataTypeCn( ) : String? { + + if( null == signatureDataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return "HASH" + +} + + +if( "31".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return "原数据" + +} + + return null + } + + + + fun getSignatureDataTypeOptionIndex( ) : Int? { + + if( null == signatureDataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return 1 + +} + + return null + } + + + + fun getHashMarkAsBin( ) : ByteArray? { + + return this.hashMark + } + + + + fun getHashMarkAsStr( ) : String? { + + if( null == this.hashMark ) return null; + return String(hashMark!!) + } + + + + fun getHashMarkAsHex( ) : String? { + + if( null == this.hashMark ) return null; + return Util.bytes2HexString(hashMark) + } + + + + fun setHashMark( bytes : ByteArray ) : Data { + + this.hashMark = bytes + return this + } + + + enum class HashMarkOptions( val bin : ByteArray ) { + +OPVSHA1(Util.hexString2Bytes("30")), +OPVSHA256(Util.hexString2Bytes("31")), +OPVMD5(Util.hexString2Bytes("32")), + } + + fun getHashMarkCn( ) : String? { + + if( null == hashMark ) { return null } + +if( "30".equals(Util.bytes2HexString(this.hashMark) ) ) { + + return "SHA1" + +} + + +if( "31".equals(Util.bytes2HexString(this.hashMark) ) ) { + + return "SHA256" + +} + + +if( "32".equals(Util.bytes2HexString(this.hashMark) ) ) { + + return "MD5" + +} + + return null + } + + + + fun getHashMarkOptionIndex( ) : Int? { + + if( null == hashMark ) { return null } + +if( "30".equals(Util.bytes2HexString(this.hashMark) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.hashMark) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.hashMark) ) ) { + + return 2 + +} + + return null + } + + + + fun getHashDataAsBin( ) : ByteArray? { + + return this.hashData + } + + + + fun getHashDataAsStr( ) : String? { + + if( null == this.hashData ) return null; + return String(hashData!!) + } + + + + fun getHashDataAsHex( ) : String? { + + if( null == this.hashData ) return null; + return Util.bytes2HexString(hashData) + } + + + + fun setHashData( bytes : ByteArray ) : Data { + + this.hashData = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getPrivateKeyTagAsBin( ) : ByteArray? { + + return this.privateKeyTag + } + + + + fun getPrivateKeyTagAsStr( ) : String? { + + if( null == this.privateKeyTag ) return null; + return String(privateKeyTag!!) + } + + + + fun getPrivateKeyTagAsHex( ) : String? { + + if( null == this.privateKeyTag ) return null; + return Util.bytes2HexString(privateKeyTag) + } + + + + fun setPrivateKeyTag( bytes : ByteArray ) : Data { + + this.privateKeyTag = bytes + return this + } + + + + fun getPrivateKeyLengthAsBin( ) : ByteArray? { + + return this.privateKeyLength + } + + + + fun getPrivateKeyLengthAsStr( ) : String? { + + if( null == this.privateKeyLength ) return null; + return String(privateKeyLength!!) + } + + + + fun getPrivateKeyLengthAsHex( ) : String? { + + if( null == this.privateKeyLength ) return null; + return Util.bytes2HexString(privateKeyLength) + } + + + + fun setPrivateKeyLength( bytes : ByteArray ) : Data { + + this.privateKeyLength = bytes + return this + } + + + + fun getPrivateKeyAsBin( ) : ByteArray? { + + return this.privateKey + } + + + + fun getPrivateKeyAsStr( ) : String? { + + if( null == this.privateKey ) return null; + return String(privateKey!!) + } + + + + fun getPrivateKeyAsHex( ) : String? { + + if( null == this.privateKey ) return null; + return Util.bytes2HexString(privateKey) + } + + + + fun setPrivateKey( bytes : ByteArray ) : Data { + + this.privateKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != signatureDataType ){ + + + soup.put("signatureDataType", this.signatureDataType!!) + soup.put("signatureDataType\$option", getSignatureDataTypeOptionIndex()!!) + } + +if( null != hashMark ){ + + + soup.put("hashMark", this.hashMark!!) + soup.put("hashMark\$option", getHashMarkOptionIndex()!!) + } + +if( null != hashData ){ + + + soup.put("hashData", this.hashData!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + +if( null != privateKeyTag ){ + + + soup.put("privateKeyTag", this.privateKeyTag!!) + } + +if( null != privateKeyLength ){ + + + soup.put("privateKeyLength", this.privateKeyLength!!) + } + +if( null != privateKey ){ + + + soup.put("privateKey", this.privateKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("signatureDataType") ){ + + + this.signatureDataType = (soup.get("signatureDataType") as PacketSection).bytes +} + + +if( soup.containsKey("hashMark") ){ + + + this.hashMark = (soup.get("hashMark") as PacketSection).bytes +} + + +if( soup.containsKey("hashData") ){ + + + this.hashData = (soup.get("hashData") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + +if( soup.containsKey("privateKeyTag") ){ + + + this.privateKeyTag = (soup.get("privateKeyTag") as PacketSection).bytes +} + + +if( soup.containsKey("privateKeyLength") ){ + + + this.privateKeyLength = (soup.get("privateKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("privateKey") ){ + + + this.privateKey = (soup.get("privateKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3742")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3742") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var signatureLen : ByteArray? = null + private var signature : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV私钥格式不对(Util.hexString2Bytes("3034")), +OPV无效的算法标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV公钥长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥格式不对" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的算法标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + return null + } + + + + fun getSignatureLenAsBin( ) : ByteArray? { + + return this.signatureLen + } + + + + fun getSignatureLenAsStr( ) : String? { + + if( null == this.signatureLen ) return null; + return String(signatureLen!!) + } + + + + fun getSignatureLenAsHex( ) : String? { + + if( null == this.signatureLen ) return null; + return Util.bytes2HexString(signatureLen) + } + + + + fun setSignatureLen( bytes : ByteArray ) : Data { + + this.signatureLen = bytes + return this + } + + + + fun getSignatureAsBin( ) : ByteArray? { + + return this.signature + } + + + + fun getSignatureAsStr( ) : String? { + + if( null == this.signature ) return null; + return String(signature!!) + } + + + + fun getSignatureAsHex( ) : String? { + + if( null == this.signature ) return null; + return Util.bytes2HexString(signature) + } + + + + fun setSignature( bytes : ByteArray ) : Data { + + this.signature = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != signatureLen ){ + + + soup.put("signatureLen", this.signatureLen!!) + } + +if( null != signature ){ + + + soup.put("signature", this.signature!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("signatureLen") ){ + + + this.signatureLen = (soup.get("signatureLen") as PacketSection).bytes +} + + +if( soup.containsKey("signature") ){ + + + this.signature = (soup.get("signature") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3743")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3743") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO7C.kt b/src/main/java/racal/sunyard/main/dto/DTO7C.kt new file mode 100644 index 0000000..769fbfd --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO7C.kt @@ -0,0 +1,1427 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO7C { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var signatureLen : ByteArray? = null + private var signature : ByteArray? = null + private var signatureDataType : ByteArray? = null + private var hashMark : ByteArray? = null + private var hashData : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var publicKeyLength : ByteArray? = null + private var publicKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getSignatureLenAsBin( ) : ByteArray? { + + return this.signatureLen + } + + + + fun getSignatureLenAsStr( ) : String? { + + if( null == this.signatureLen ) return null; + return String(signatureLen!!) + } + + + + fun getSignatureLenAsHex( ) : String? { + + if( null == this.signatureLen ) return null; + return Util.bytes2HexString(signatureLen) + } + + + + fun setSignatureLen( bytes : ByteArray ) : Data { + + this.signatureLen = bytes + return this + } + + + + fun getSignatureAsBin( ) : ByteArray? { + + return this.signature + } + + + + fun getSignatureAsStr( ) : String? { + + if( null == this.signature ) return null; + return String(signature!!) + } + + + + fun getSignatureAsHex( ) : String? { + + if( null == this.signature ) return null; + return Util.bytes2HexString(signature) + } + + + + fun setSignature( bytes : ByteArray ) : Data { + + this.signature = bytes + return this + } + + + + fun getSignatureDataTypeAsBin( ) : ByteArray? { + + return this.signatureDataType + } + + + + fun getSignatureDataTypeAsStr( ) : String? { + + if( null == this.signatureDataType ) return null; + return String(signatureDataType!!) + } + + + + fun getSignatureDataTypeAsHex( ) : String? { + + if( null == this.signatureDataType ) return null; + return Util.bytes2HexString(signatureDataType) + } + + + + fun setSignatureDataType( bytes : ByteArray ) : Data { + + this.signatureDataType = bytes + return this + } + + + enum class SignatureDataTypeOptions( val bin : ByteArray ) { + +OPVHASH(Util.hexString2Bytes("30")), +OPV原数据(Util.hexString2Bytes("31")), + } + + fun getSignatureDataTypeCn( ) : String? { + + if( null == signatureDataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return "HASH" + +} + + +if( "31".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return "原数据" + +} + + return null + } + + + + fun getSignatureDataTypeOptionIndex( ) : Int? { + + if( null == signatureDataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return 1 + +} + + return null + } + + + + fun getHashMarkAsBin( ) : ByteArray? { + + return this.hashMark + } + + + + fun getHashMarkAsStr( ) : String? { + + if( null == this.hashMark ) return null; + return String(hashMark!!) + } + + + + fun getHashMarkAsHex( ) : String? { + + if( null == this.hashMark ) return null; + return Util.bytes2HexString(hashMark) + } + + + + fun setHashMark( bytes : ByteArray ) : Data { + + this.hashMark = bytes + return this + } + + + enum class HashMarkOptions( val bin : ByteArray ) { + +OPVSHA1(Util.hexString2Bytes("30")), +OPVSHA256(Util.hexString2Bytes("31")), +OPVMD5(Util.hexString2Bytes("32")), + } + + fun getHashMarkCn( ) : String? { + + if( null == hashMark ) { return null } + +if( "30".equals(Util.bytes2HexString(this.hashMark) ) ) { + + return "SHA1" + +} + + +if( "31".equals(Util.bytes2HexString(this.hashMark) ) ) { + + return "SHA256" + +} + + +if( "32".equals(Util.bytes2HexString(this.hashMark) ) ) { + + return "MD5" + +} + + return null + } + + + + fun getHashMarkOptionIndex( ) : Int? { + + if( null == hashMark ) { return null } + +if( "30".equals(Util.bytes2HexString(this.hashMark) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.hashMark) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.hashMark) ) ) { + + return 2 + +} + + return null + } + + + + fun getHashDataAsBin( ) : ByteArray? { + + return this.hashData + } + + + + fun getHashDataAsStr( ) : String? { + + if( null == this.hashData ) return null; + return String(hashData!!) + } + + + + fun getHashDataAsHex( ) : String? { + + if( null == this.hashData ) return null; + return Util.bytes2HexString(hashData) + } + + + + fun setHashData( bytes : ByteArray ) : Data { + + this.hashData = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getPublicKeyLengthAsBin( ) : ByteArray? { + + return this.publicKeyLength + } + + + + fun getPublicKeyLengthAsStr( ) : String? { + + if( null == this.publicKeyLength ) return null; + return String(publicKeyLength!!) + } + + + + fun getPublicKeyLengthAsHex( ) : String? { + + if( null == this.publicKeyLength ) return null; + return Util.bytes2HexString(publicKeyLength) + } + + + + fun setPublicKeyLength( bytes : ByteArray ) : Data { + + this.publicKeyLength = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != signatureLen ){ + + + soup.put("signatureLen", this.signatureLen!!) + } + +if( null != signature ){ + + + soup.put("signature", this.signature!!) + } + +if( null != signatureDataType ){ + + + soup.put("signatureDataType", this.signatureDataType!!) + soup.put("signatureDataType\$option", getSignatureDataTypeOptionIndex()!!) + } + +if( null != hashMark ){ + + + soup.put("hashMark", this.hashMark!!) + soup.put("hashMark\$option", getHashMarkOptionIndex()!!) + } + +if( null != hashData ){ + + + soup.put("hashData", this.hashData!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + +if( null != publicKeyLength ){ + + + soup.put("publicKeyLength", this.publicKeyLength!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("signatureLen") ){ + + + this.signatureLen = (soup.get("signatureLen") as PacketSection).bytes +} + + +if( soup.containsKey("signature") ){ + + + this.signature = (soup.get("signature") as PacketSection).bytes +} + + +if( soup.containsKey("signatureDataType") ){ + + + this.signatureDataType = (soup.get("signatureDataType") as PacketSection).bytes +} + + +if( soup.containsKey("hashMark") ){ + + + this.hashMark = (soup.get("hashMark") as PacketSection).bytes +} + + +if( soup.containsKey("hashData") ){ + + + this.hashData = (soup.get("hashData") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + +if( soup.containsKey("publicKeyLength") ){ + + + this.publicKeyLength = (soup.get("publicKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3743")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3743") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV签名校验失败(Util.hexString2Bytes("3032")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的哈希标识(Util.hexString2Bytes("3035")), +OPV无效的签名标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV无效摘要信息语法仅仅无哈希模式(Util.hexString2Bytes("3734")), +OPV公钥长度错误(Util.hexString2Bytes("3736")), +OPV明文数据块错误(Util.hexString2Bytes("3737")), +OPV哈希算法对象标识错误(Util.hexString2Bytes("3739")), +OPV信息长度错(Util.hexString2Bytes("3830")), +OPV签名长度错(Util.hexString2Bytes("3831")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3032".equals(Util.bytes2HexString(this.error) ) ) { + + return "签名校验失败" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的哈希标识" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的签名标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效摘要信息语法(仅仅无哈希模式)" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥长度错误" + +} + + +if( "3737".equals(Util.bytes2HexString(this.error) ) ) { + + return "明文数据块错误" + +} + + +if( "3739".equals(Util.bytes2HexString(this.error) ) ) { + + return "哈希算法对象标识错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "信息长度错" + +} + + +if( "3831".equals(Util.bytes2HexString(this.error) ) ) { + + return "签名长度错" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3032".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3737".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + +if( "3739".equals(Util.bytes2HexString(this.error) ) ) { + + return 12 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 13 + +} + + +if( "3831".equals(Util.bytes2HexString(this.error) ) ) { + + return 14 + +} + + return null + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3744")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3744") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO7D.kt b/src/main/java/racal/sunyard/main/dto/DTO7D.kt new file mode 100644 index 0000000..21ecdfd --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO7D.kt @@ -0,0 +1,1185 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO7D { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var hashType : ByteArray? = null + private var packSn : ByteArray? = null + private var dataLength : ByteArray? = null + private var msg : ByteArray? = null + private var filterDataLen : ByteArray? = null + private var filterData : ByteArray? = null + + + fun getHashTypeAsBin( ) : ByteArray? { + + return this.hashType + } + + + + fun getHashTypeAsStr( ) : String? { + + if( null == this.hashType ) return null; + return String(hashType!!) + } + + + + fun getHashTypeAsHex( ) : String? { + + if( null == this.hashType ) return null; + return Util.bytes2HexString(hashType) + } + + + + fun setHashType( bytes : ByteArray ) : Data { + + this.hashType = bytes + return this + } + + + enum class HashTypeOptions( val bin : ByteArray ) { + +OPVSHA1(Util.hexString2Bytes("30")), +OPVSHA256(Util.hexString2Bytes("31")), +OPVMD5(Util.hexString2Bytes("32")), + } + + fun getHashTypeCn( ) : String? { + + if( null == hashType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.hashType) ) ) { + + return "SHA1" + +} + + +if( "31".equals(Util.bytes2HexString(this.hashType) ) ) { + + return "SHA256" + +} + + +if( "32".equals(Util.bytes2HexString(this.hashType) ) ) { + + return "MD5" + +} + + return null + } + + + + fun getHashTypeOptionIndex( ) : Int? { + + if( null == hashType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.hashType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.hashType) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.hashType) ) ) { + + return 2 + +} + + return null + } + + + + fun getPackSnAsBin( ) : ByteArray? { + + return this.packSn + } + + + + fun getPackSnAsStr( ) : String? { + + if( null == this.packSn ) return null; + return String(packSn!!) + } + + + + fun getPackSnAsHex( ) : String? { + + if( null == this.packSn ) return null; + return Util.bytes2HexString(packSn) + } + + + + fun setPackSn( bytes : ByteArray ) : Data { + + this.packSn = bytes + return this + } + + + enum class PackSnOptions( val bin : ByteArray ) { + +OPV仅一块(Util.hexString2Bytes("30")), +OPV第一块(Util.hexString2Bytes("31")), +OPV中间块(Util.hexString2Bytes("32")), +OPV最后块(Util.hexString2Bytes("33")), + } + + fun getPackSnCn( ) : String? { + + if( null == packSn ) { return null } + +if( "30".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "仅一块" + +} + + +if( "31".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "第一块" + +} + + +if( "32".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "中间块" + +} + + +if( "33".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "最后块" + +} + + return null + } + + + + fun getPackSnOptionIndex( ) : Int? { + + if( null == packSn ) { return null } + +if( "30".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 2 + +} + + +if( "33".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 3 + +} + + return null + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getMsgAsBin( ) : ByteArray? { + + return this.msg + } + + + + fun getMsgAsStr( ) : String? { + + if( null == this.msg ) return null; + return String(msg!!) + } + + + + fun getMsgAsHex( ) : String? { + + if( null == this.msg ) return null; + return Util.bytes2HexString(msg) + } + + + + fun setMsg( bytes : ByteArray ) : Data { + + this.msg = bytes + return this + } + + + + fun getFilterDataLenAsBin( ) : ByteArray? { + + return this.filterDataLen + } + + + + fun getFilterDataLenAsStr( ) : String? { + + if( null == this.filterDataLen ) return null; + return String(filterDataLen!!) + } + + + + fun getFilterDataLenAsHex( ) : String? { + + if( null == this.filterDataLen ) return null; + return Util.bytes2HexString(filterDataLen) + } + + + + fun setFilterDataLen( bytes : ByteArray ) : Data { + + this.filterDataLen = bytes + return this + } + + + + fun getFilterDataAsBin( ) : ByteArray? { + + return this.filterData + } + + + + fun getFilterDataAsStr( ) : String? { + + if( null == this.filterData ) return null; + return String(filterData!!) + } + + + + fun getFilterDataAsHex( ) : String? { + + if( null == this.filterData ) return null; + return Util.bytes2HexString(filterData) + } + + + + fun setFilterData( bytes : ByteArray ) : Data { + + this.filterData = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != hashType ){ + + + soup.put("hashType", this.hashType!!) + soup.put("hashType\$option", getHashTypeOptionIndex()!!) + } + +if( null != packSn ){ + + + soup.put("packSn", this.packSn!!) + soup.put("packSn\$option", getPackSnOptionIndex()!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != msg ){ + + + soup.put("msg", this.msg!!) + } + +if( null != filterDataLen ){ + + + soup.put("filterDataLen", this.filterDataLen!!) + } + +if( null != filterData ){ + + + soup.put("filterData", this.filterData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("hashType") ){ + + + this.hashType = (soup.get("hashType") as PacketSection).bytes +} + + +if( soup.containsKey("packSn") ){ + + + this.packSn = (soup.get("packSn") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("msg") ){ + + + this.msg = (soup.get("msg") as PacketSection).bytes +} + + +if( soup.containsKey("filterDataLen") ){ + + + this.filterDataLen = (soup.get("filterDataLen") as PacketSection).bytes +} + + +if( soup.containsKey("filterData") ){ + + + this.filterData = (soup.get("filterData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3744")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3744") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var hash : ByteArray? = null + private var filterDataLen : ByteArray? = null + private var filterData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV数据长度错(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + return null + } + + + + fun getHashAsBin( ) : ByteArray? { + + return this.hash + } + + + + fun getHashAsStr( ) : String? { + + if( null == this.hash ) return null; + return String(hash!!) + } + + + + fun getHashAsHex( ) : String? { + + if( null == this.hash ) return null; + return Util.bytes2HexString(hash) + } + + + + fun setHash( bytes : ByteArray ) : Data { + + this.hash = bytes + return this + } + + + + fun getFilterDataLenAsBin( ) : ByteArray? { + + return this.filterDataLen + } + + + + fun getFilterDataLenAsStr( ) : String? { + + if( null == this.filterDataLen ) return null; + return String(filterDataLen!!) + } + + + + fun getFilterDataLenAsHex( ) : String? { + + if( null == this.filterDataLen ) return null; + return Util.bytes2HexString(filterDataLen) + } + + + + fun setFilterDataLen( bytes : ByteArray ) : Data { + + this.filterDataLen = bytes + return this + } + + + + fun getFilterDataAsBin( ) : ByteArray? { + + return this.filterData + } + + + + fun getFilterDataAsStr( ) : String? { + + if( null == this.filterData ) return null; + return String(filterData!!) + } + + + + fun getFilterDataAsHex( ) : String? { + + if( null == this.filterData ) return null; + return Util.bytes2HexString(filterData) + } + + + + fun setFilterData( bytes : ByteArray ) : Data { + + this.filterData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != hash ){ + + + soup.put("hash", this.hash!!) + } + +if( null != filterDataLen ){ + + + soup.put("filterDataLen", this.filterDataLen!!) + } + +if( null != filterData ){ + + + soup.put("filterData", this.filterData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("hash") ){ + + + this.hash = (soup.get("hash") as PacketSection).bytes +} + + +if( soup.containsKey("filterDataLen") ){ + + + this.filterDataLen = (soup.get("filterDataLen") as PacketSection).bytes +} + + +if( soup.containsKey("filterData") ){ + + + this.filterData = (soup.get("filterData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3745")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3745") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO7E.kt b/src/main/java/racal/sunyard/main/dto/DTO7E.kt new file mode 100644 index 0000000..289033f --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO7E.kt @@ -0,0 +1,987 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO7E { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var userCertificateType : ByteArray? = null + private var dNLen : ByteArray? = null + private var dN : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getUserCertificateTypeAsBin( ) : ByteArray? { + + return this.userCertificateType + } + + + + fun getUserCertificateTypeAsStr( ) : String? { + + if( null == this.userCertificateType ) return null; + return String(userCertificateType!!) + } + + + + fun getUserCertificateTypeAsHex( ) : String? { + + if( null == this.userCertificateType ) return null; + return Util.bytes2HexString(userCertificateType) + } + + + + fun setUserCertificateType( bytes : ByteArray ) : Data { + + this.userCertificateType = bytes + return this + } + + + enum class UserCertificateTypeOptions( val bin : ByteArray ) { + +OPV签名证书(Util.hexString2Bytes("30")), +OPV加密证书(Util.hexString2Bytes("31")), + } + + fun getUserCertificateTypeCn( ) : String? { + + if( null == userCertificateType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.userCertificateType) ) ) { + + return "签名证书" + +} + + +if( "31".equals(Util.bytes2HexString(this.userCertificateType) ) ) { + + return "加密证书" + +} + + return null + } + + + + fun getUserCertificateTypeOptionIndex( ) : Int? { + + if( null == userCertificateType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.userCertificateType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.userCertificateType) ) ) { + + return 1 + +} + + return null + } + + + + fun getDNLenAsBin( ) : ByteArray? { + + return this.dNLen + } + + + + fun getDNLenAsStr( ) : String? { + + if( null == this.dNLen ) return null; + return String(dNLen!!) + } + + + + fun getDNLenAsHex( ) : String? { + + if( null == this.dNLen ) return null; + return Util.bytes2HexString(dNLen) + } + + + + fun setDNLen( bytes : ByteArray ) : Data { + + this.dNLen = bytes + return this + } + + + + fun getDNAsBin( ) : ByteArray? { + + return this.dN + } + + + + fun getDNAsStr( ) : String? { + + if( null == this.dN ) return null; + return String(dN!!) + } + + + + fun getDNAsHex( ) : String? { + + if( null == this.dN ) return null; + return Util.bytes2HexString(dN) + } + + + + fun setDN( bytes : ByteArray ) : Data { + + this.dN = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != userCertificateType ){ + + + soup.put("userCertificateType", this.userCertificateType!!) + soup.put("userCertificateType\$option", getUserCertificateTypeOptionIndex()!!) + } + +if( null != dNLen ){ + + + soup.put("DNLen", this.dNLen!!) + } + +if( null != dN ){ + + + soup.put("DN", this.dN!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("userCertificateType") ){ + + + this.userCertificateType = (soup.get("userCertificateType") as PacketSection).bytes +} + + +if( soup.containsKey("DNLen") ){ + + + this.dNLen = (soup.get("DNLen") as PacketSection).bytes +} + + +if( soup.containsKey("DN") ){ + + + this.dN = (soup.get("DN") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3745")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3745") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var publicKeyLen : ByteArray? = null + private var publicKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效的索引值(Util.hexString2Bytes("3231")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的索引值" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + return null + } + + + + fun getPublicKeyLenAsBin( ) : ByteArray? { + + return this.publicKeyLen + } + + + + fun getPublicKeyLenAsStr( ) : String? { + + if( null == this.publicKeyLen ) return null; + return String(publicKeyLen!!) + } + + + + fun getPublicKeyLenAsHex( ) : String? { + + if( null == this.publicKeyLen ) return null; + return Util.bytes2HexString(publicKeyLen) + } + + + + fun setPublicKeyLen( bytes : ByteArray ) : Data { + + this.publicKeyLen = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != publicKeyLen ){ + + + soup.put("publicKeyLen", this.publicKeyLen!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("publicKeyLen") ){ + + + this.publicKeyLen = (soup.get("publicKeyLen") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3746")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3746") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO80.kt b/src/main/java/racal/sunyard/main/dto/DTO80.kt new file mode 100644 index 0000000..92d757c --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO80.kt @@ -0,0 +1,1117 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO80 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var certificateNoLen : ByteArray? = null + private var certificateNo : ByteArray? = null + private var dataLen : ByteArray? = null + private var infoData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getCertificateNoLenAsBin( ) : ByteArray? { + + return this.certificateNoLen + } + + + + fun getCertificateNoLenAsStr( ) : String? { + + if( null == this.certificateNoLen ) return null; + return String(certificateNoLen!!) + } + + + + fun getCertificateNoLenAsHex( ) : String? { + + if( null == this.certificateNoLen ) return null; + return Util.bytes2HexString(certificateNoLen) + } + + + + fun setCertificateNoLen( bytes : ByteArray ) : Data { + + this.certificateNoLen = bytes + return this + } + + + + fun getCertificateNoAsBin( ) : ByteArray? { + + return this.certificateNo + } + + + + fun getCertificateNoAsStr( ) : String? { + + if( null == this.certificateNo ) return null; + return String(certificateNo!!) + } + + + + fun getCertificateNoAsHex( ) : String? { + + if( null == this.certificateNo ) return null; + return Util.bytes2HexString(certificateNo) + } + + + + fun setCertificateNo( bytes : ByteArray ) : Data { + + this.certificateNo = bytes + return this + } + + + + fun getDataLenAsBin( ) : ByteArray? { + + return this.dataLen + } + + + + fun getDataLenAsStr( ) : String? { + + if( null == this.dataLen ) return null; + return String(dataLen!!) + } + + + + fun getDataLenAsHex( ) : String? { + + if( null == this.dataLen ) return null; + return Util.bytes2HexString(dataLen) + } + + + + fun setDataLen( bytes : ByteArray ) : Data { + + this.dataLen = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != certificateNoLen ){ + + + soup.put("certificateNoLen", this.certificateNoLen!!) + } + +if( null != certificateNo ){ + + + soup.put("certificateNo", this.certificateNo!!) + } + +if( null != dataLen ){ + + + soup.put("dataLen", this.dataLen!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("certificateNoLen") ){ + + + this.certificateNoLen = (soup.get("certificateNoLen") as PacketSection).bytes +} + + +if( soup.containsKey("certificateNo") ){ + + + this.certificateNo = (soup.get("certificateNo") as PacketSection).bytes +} + + +if( soup.containsKey("dataLen") ){ + + + this.dataLen = (soup.get("dataLen") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3830")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3830") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var signatureLen : ByteArray? = null + private var signature : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getSignatureLenAsBin( ) : ByteArray? { + + return this.signatureLen + } + + + + fun getSignatureLenAsStr( ) : String? { + + if( null == this.signatureLen ) return null; + return String(signatureLen!!) + } + + + + fun getSignatureLenAsHex( ) : String? { + + if( null == this.signatureLen ) return null; + return Util.bytes2HexString(signatureLen) + } + + + + fun setSignatureLen( bytes : ByteArray ) : Data { + + this.signatureLen = bytes + return this + } + + + + fun getSignatureAsBin( ) : ByteArray? { + + return this.signature + } + + + + fun getSignatureAsStr( ) : String? { + + if( null == this.signature ) return null; + return String(signature!!) + } + + + + fun getSignatureAsHex( ) : String? { + + if( null == this.signature ) return null; + return Util.bytes2HexString(signature) + } + + + + fun setSignature( bytes : ByteArray ) : Data { + + this.signature = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != signatureLen ){ + + + soup.put("signatureLen", this.signatureLen!!) + } + +if( null != signature ){ + + + soup.put("signature", this.signature!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("signatureLen") ){ + + + this.signatureLen = (soup.get("signatureLen") as PacketSection).bytes +} + + +if( soup.containsKey("signature") ){ + + + this.signature = (soup.get("signature") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3831")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3831") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO8003.kt b/src/main/java/racal/sunyard/main/dto/DTO8003.kt new file mode 100644 index 0000000..ca584ee --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO8003.kt @@ -0,0 +1,1120 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO8003 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var signatureDataType : ByteArray? = null + private var dN : ByteArray? = null + private var dataLength : ByteArray? = null + private var data : ByteArray? = null + + + fun getSignatureDataTypeAsBin( ) : ByteArray? { + + return this.signatureDataType + } + + + + fun getSignatureDataTypeAsStr( ) : String? { + + if( null == this.signatureDataType ) return null; + return String(signatureDataType!!) + } + + + + fun getSignatureDataTypeAsHex( ) : String? { + + if( null == this.signatureDataType ) return null; + return Util.bytes2HexString(signatureDataType) + } + + + + fun setSignatureDataType( bytes : ByteArray ) : Data { + + this.signatureDataType = bytes + return this + } + + + enum class SignatureDataTypeOptions( val bin : ByteArray ) { + +OPV索引方式(Util.hexString2Bytes("30")), +OPVDN方式(Util.hexString2Bytes("31")), + } + + fun getSignatureDataTypeCn( ) : String? { + + if( null == signatureDataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return "索引方式" + +} + + +if( "31".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return "DN 方式" + +} + + return null + } + + + + fun getSignatureDataTypeOptionIndex( ) : Int? { + + if( null == signatureDataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return 1 + +} + + return null + } + + + + fun getDNAsBin( ) : ByteArray? { + + return this.dN + } + + + + fun getDNAsStr( ) : String? { + + if( null == this.dN ) return null; + return String(dN!!) + } + + + + fun getDNAsHex( ) : String? { + + if( null == this.dN ) return null; + return Util.bytes2HexString(dN) + } + + + + fun setDN( bytes : ByteArray ) : Data { + + this.dN = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getDataAsBin( ) : ByteArray? { + + return this.data + } + + + + fun getDataAsStr( ) : String? { + + if( null == this.data ) return null; + return String(data!!) + } + + + + fun getDataAsHex( ) : String? { + + if( null == this.data ) return null; + return Util.bytes2HexString(data) + } + + + + fun setData( bytes : ByteArray ) : Data { + + this.data = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != signatureDataType ){ + + + soup.put("signatureDataType", this.signatureDataType!!) + soup.put("signatureDataType\$option", getSignatureDataTypeOptionIndex()!!) + } + +if( null != dN ){ + + + soup.put("DN", this.dN!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != data ){ + + + soup.put("data", this.data!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("signatureDataType") ){ + + + this.signatureDataType = (soup.get("signatureDataType") as PacketSection).bytes +} + + +if( soup.containsKey("DN") ){ + + + this.dN = (soup.get("DN") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + + + this.data = (soup.get("data") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8003")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8003") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var signatureLen : ByteArray? = null + private var signature : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效的私钥类型(Util.hexString2Bytes("3033")), +OPV无效私钥标记(Util.hexString2Bytes("3034")), +OPV无效的哈希标识(Util.hexString2Bytes("3035")), +OPV无效的签名标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV无效摘要信息语法仅仅无哈希模式(Util.hexString2Bytes("3734")), +OPV公钥长度错误(Util.hexString2Bytes("3736")), +OPV私钥长度错误(Util.hexString2Bytes("3738")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的私钥类型" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效私钥标记" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的哈希标识" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的签名标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效摘要信息语法(仅仅无哈希模式)" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥长度错误" + +} + + +if( "3738".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + +if( "3738".equals(Util.bytes2HexString(this.error) ) ) { + + return 12 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 13 + +} + + return null + } + + + + fun getSignatureLenAsBin( ) : ByteArray? { + + return this.signatureLen + } + + + + fun getSignatureLenAsStr( ) : String? { + + if( null == this.signatureLen ) return null; + return String(signatureLen!!) + } + + + + fun getSignatureLenAsHex( ) : String? { + + if( null == this.signatureLen ) return null; + return Util.bytes2HexString(signatureLen) + } + + + + fun setSignatureLen( bytes : ByteArray ) : Data { + + this.signatureLen = bytes + return this + } + + + + fun getSignatureAsBin( ) : ByteArray? { + + return this.signature + } + + + + fun getSignatureAsStr( ) : String? { + + if( null == this.signature ) return null; + return String(signature!!) + } + + + + fun getSignatureAsHex( ) : String? { + + if( null == this.signature ) return null; + return Util.bytes2HexString(signature) + } + + + + fun setSignature( bytes : ByteArray ) : Data { + + this.signature = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != signatureLen ){ + + + soup.put("signatureLen", this.signatureLen!!) + } + +if( null != signature ){ + + + soup.put("signature", this.signature!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("signatureLen") ){ + + + this.signatureLen = (soup.get("signatureLen") as PacketSection).bytes +} + + +if( soup.containsKey("signature") ){ + + + this.signature = (soup.get("signature") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8004")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8004") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO8004.kt b/src/main/java/racal/sunyard/main/dto/DTO8004.kt new file mode 100644 index 0000000..89939df --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO8004.kt @@ -0,0 +1,1273 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO8004 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var signatureDataType : ByteArray? = null + private var dN : ByteArray? = null + private var organizationNumLen : ByteArray? = null + private var organizationNum : ByteArray? = null + private var dataLength : ByteArray? = null + private var data : ByteArray? = null + private var signatureLen : ByteArray? = null + private var signature : ByteArray? = null + private var returnSign : ByteArray? = null + + + fun getSignatureDataTypeAsBin( ) : ByteArray? { + + return this.signatureDataType + } + + + + fun getSignatureDataTypeAsStr( ) : String? { + + if( null == this.signatureDataType ) return null; + return String(signatureDataType!!) + } + + + + fun getSignatureDataTypeAsHex( ) : String? { + + if( null == this.signatureDataType ) return null; + return Util.bytes2HexString(signatureDataType) + } + + + + fun setSignatureDataType( bytes : ByteArray ) : Data { + + this.signatureDataType = bytes + return this + } + + + enum class SignatureDataTypeOptions( val bin : ByteArray ) { + +OPV索引方式(Util.hexString2Bytes("30")), +OPVDN方式(Util.hexString2Bytes("31")), +OPV通过机构号获取(Util.hexString2Bytes("32")), + } + + fun getSignatureDataTypeCn( ) : String? { + + if( null == signatureDataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return "索引方式" + +} + + +if( "31".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return "DN 方式" + +} + + +if( "32".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return "通过机构号获取" + +} + + return null + } + + + + fun getSignatureDataTypeOptionIndex( ) : Int? { + + if( null == signatureDataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.signatureDataType) ) ) { + + return 2 + +} + + return null + } + + + + fun getDNAsBin( ) : ByteArray? { + + return this.dN + } + + + + fun getDNAsStr( ) : String? { + + if( null == this.dN ) return null; + return String(dN!!) + } + + + + fun getDNAsHex( ) : String? { + + if( null == this.dN ) return null; + return Util.bytes2HexString(dN) + } + + + + fun setDN( bytes : ByteArray ) : Data { + + this.dN = bytes + return this + } + + + + fun getOrganizationNumLenAsBin( ) : ByteArray? { + + return this.organizationNumLen + } + + + + fun getOrganizationNumLenAsStr( ) : String? { + + if( null == this.organizationNumLen ) return null; + return String(organizationNumLen!!) + } + + + + fun getOrganizationNumLenAsHex( ) : String? { + + if( null == this.organizationNumLen ) return null; + return Util.bytes2HexString(organizationNumLen) + } + + + + fun setOrganizationNumLen( bytes : ByteArray ) : Data { + + this.organizationNumLen = bytes + return this + } + + + + fun getOrganizationNumAsBin( ) : ByteArray? { + + return this.organizationNum + } + + + + fun getOrganizationNumAsStr( ) : String? { + + if( null == this.organizationNum ) return null; + return String(organizationNum!!) + } + + + + fun getOrganizationNumAsHex( ) : String? { + + if( null == this.organizationNum ) return null; + return Util.bytes2HexString(organizationNum) + } + + + + fun setOrganizationNum( bytes : ByteArray ) : Data { + + this.organizationNum = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getDataAsBin( ) : ByteArray? { + + return this.data + } + + + + fun getDataAsStr( ) : String? { + + if( null == this.data ) return null; + return String(data!!) + } + + + + fun getDataAsHex( ) : String? { + + if( null == this.data ) return null; + return Util.bytes2HexString(data) + } + + + + fun setData( bytes : ByteArray ) : Data { + + this.data = bytes + return this + } + + + + fun getSignatureLenAsBin( ) : ByteArray? { + + return this.signatureLen + } + + + + fun getSignatureLenAsStr( ) : String? { + + if( null == this.signatureLen ) return null; + return String(signatureLen!!) + } + + + + fun getSignatureLenAsHex( ) : String? { + + if( null == this.signatureLen ) return null; + return Util.bytes2HexString(signatureLen) + } + + + + fun setSignatureLen( bytes : ByteArray ) : Data { + + this.signatureLen = bytes + return this + } + + + + fun getSignatureAsBin( ) : ByteArray? { + + return this.signature + } + + + + fun getSignatureAsStr( ) : String? { + + if( null == this.signature ) return null; + return String(signature!!) + } + + + + fun getSignatureAsHex( ) : String? { + + if( null == this.signature ) return null; + return Util.bytes2HexString(signature) + } + + + + fun setSignature( bytes : ByteArray ) : Data { + + this.signature = bytes + return this + } + + + + fun getReturnSignAsBin( ) : ByteArray? { + + return this.returnSign + } + + + + fun getReturnSignAsStr( ) : String? { + + if( null == this.returnSign ) return null; + return String(returnSign!!) + } + + + + fun getReturnSignAsHex( ) : String? { + + if( null == this.returnSign ) return null; + return Util.bytes2HexString(returnSign) + } + + + + fun setReturnSign( bytes : ByteArray ) : Data { + + this.returnSign = bytes + return this + } + + + enum class ReturnSignOptions( val bin : ByteArray ) { + +OPV不返回(Util.hexString2Bytes("0000")), +OPV返回(Util.hexString2Bytes("0001")), + } + + fun getReturnSignCn( ) : String? { + + if( null == returnSign ) { return null } + +if( "0000".equals(Util.bytes2HexString(this.returnSign) ) ) { + + return "不返回" + +} + + +if( "0001".equals(Util.bytes2HexString(this.returnSign) ) ) { + + return "返回" + +} + + return null + } + + + + fun getReturnSignOptionIndex( ) : Int? { + + if( null == returnSign ) { return null } + +if( "0000".equals(Util.bytes2HexString(this.returnSign) ) ) { + + return 0 + +} + + +if( "0001".equals(Util.bytes2HexString(this.returnSign) ) ) { + + return 1 + +} + + return null + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != signatureDataType ){ + + + soup.put("signatureDataType", this.signatureDataType!!) + soup.put("signatureDataType\$option", getSignatureDataTypeOptionIndex()!!) + } + +if( null != dN ){ + + + soup.put("DN", this.dN!!) + } + +if( null != organizationNumLen ){ + + + soup.put("organizationNumLen", this.organizationNumLen!!) + } + +if( null != organizationNum ){ + + + soup.put("organizationNum", this.organizationNum!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != data ){ + + + soup.put("data", this.data!!) + } + +if( null != signatureLen ){ + + + soup.put("signatureLen", this.signatureLen!!) + } + +if( null != signature ){ + + + soup.put("signature", this.signature!!) + } + +if( null != returnSign ){ + + + soup.put("returnSign", this.returnSign!!) + soup.put("returnSign\$option", getReturnSignOptionIndex()!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("signatureDataType") ){ + + + this.signatureDataType = (soup.get("signatureDataType") as PacketSection).bytes +} + + +if( soup.containsKey("DN") ){ + + + this.dN = (soup.get("DN") as PacketSection).bytes +} + + +if( soup.containsKey("organizationNumLen") ){ + + + this.organizationNumLen = (soup.get("organizationNumLen") as PacketSection).bytes +} + + +if( soup.containsKey("organizationNum") ){ + + + this.organizationNum = (soup.get("organizationNum") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + + + this.data = (soup.get("data") as PacketSection).bytes +} + + +if( soup.containsKey("signatureLen") ){ + + + this.signatureLen = (soup.get("signatureLen") as PacketSection).bytes +} + + +if( soup.containsKey("signature") ){ + + + this.signature = (soup.get("signature") as PacketSection).bytes +} + + +if( soup.containsKey("returnSign") ){ + + + this.returnSign = (soup.get("returnSign") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8004")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8004") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var infoLen : ByteArray? = null + private var info : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getInfoLenAsBin( ) : ByteArray? { + + return this.infoLen + } + + + + fun getInfoLenAsStr( ) : String? { + + if( null == this.infoLen ) return null; + return String(infoLen!!) + } + + + + fun getInfoLenAsHex( ) : String? { + + if( null == this.infoLen ) return null; + return Util.bytes2HexString(infoLen) + } + + + + fun setInfoLen( bytes : ByteArray ) : Data { + + this.infoLen = bytes + return this + } + + + + fun getInfoAsBin( ) : ByteArray? { + + return this.info + } + + + + fun getInfoAsStr( ) : String? { + + if( null == this.info ) return null; + return String(info!!) + } + + + + fun getInfoAsHex( ) : String? { + + if( null == this.info ) return null; + return Util.bytes2HexString(info) + } + + + + fun setInfo( bytes : ByteArray ) : Data { + + this.info = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != infoLen ){ + + + soup.put("infoLen", this.infoLen!!) + } + +if( null != info ){ + + + soup.put("info", this.info!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("infoLen") ){ + + + this.infoLen = (soup.get("infoLen") as PacketSection).bytes +} + + +if( soup.containsKey("info") ){ + + + this.info = (soup.get("info") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8005")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8005") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO8005.kt b/src/main/java/racal/sunyard/main/dto/DTO8005.kt new file mode 100644 index 0000000..58e3c2c --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO8005.kt @@ -0,0 +1,978 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO8005 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var dN : ByteArray? = null + private var hashFlag : ByteArray? = null + private var hash : ByteArray? = null + private var dataLen : ByteArray? = null + private var infoData : ByteArray? = null + + + fun getDNAsBin( ) : ByteArray? { + + return this.dN + } + + + + fun getDNAsStr( ) : String? { + + if( null == this.dN ) return null; + return String(dN!!) + } + + + + fun getDNAsHex( ) : String? { + + if( null == this.dN ) return null; + return Util.bytes2HexString(dN) + } + + + + fun setDN( bytes : ByteArray ) : Data { + + this.dN = bytes + return this + } + + + + fun getHashFlagAsBin( ) : ByteArray? { + + return this.hashFlag + } + + + + fun getHashFlagAsStr( ) : String? { + + if( null == this.hashFlag ) return null; + return String(hashFlag!!) + } + + + + fun getHashFlagAsHex( ) : String? { + + if( null == this.hashFlag ) return null; + return Util.bytes2HexString(hashFlag) + } + + + + fun setHashFlag( bytes : ByteArray ) : Data { + + this.hashFlag = bytes + return this + } + + + + fun getHashAsBin( ) : ByteArray? { + + return this.hash + } + + + + fun getHashAsStr( ) : String? { + + if( null == this.hash ) return null; + return String(hash!!) + } + + + + fun getHashAsHex( ) : String? { + + if( null == this.hash ) return null; + return Util.bytes2HexString(hash) + } + + + + fun setHash( bytes : ByteArray ) : Data { + + this.hash = bytes + return this + } + + + + fun getDataLenAsBin( ) : ByteArray? { + + return this.dataLen + } + + + + fun getDataLenAsStr( ) : String? { + + if( null == this.dataLen ) return null; + return String(dataLen!!) + } + + + + fun getDataLenAsHex( ) : String? { + + if( null == this.dataLen ) return null; + return Util.bytes2HexString(dataLen) + } + + + + fun setDataLen( bytes : ByteArray ) : Data { + + this.dataLen = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != dN ){ + + + soup.put("DN", this.dN!!) + } + +if( null != hashFlag ){ + + + soup.put("hashFlag", this.hashFlag!!) + } + +if( null != hash ){ + + + soup.put("hash", this.hash!!) + } + +if( null != dataLen ){ + + + soup.put("dataLen", this.dataLen!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("DN") ){ + + + this.dN = (soup.get("DN") as PacketSection).bytes +} + + +if( soup.containsKey("hashFlag") ){ + + + this.hashFlag = (soup.get("hashFlag") as PacketSection).bytes +} + + +if( soup.containsKey("hash") ){ + + + this.hash = (soup.get("hash") as PacketSection).bytes +} + + +if( soup.containsKey("dataLen") ){ + + + this.dataLen = (soup.get("dataLen") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8005")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8005") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var signatureLen : ByteArray? = null + private var signature : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getSignatureLenAsBin( ) : ByteArray? { + + return this.signatureLen + } + + + + fun getSignatureLenAsStr( ) : String? { + + if( null == this.signatureLen ) return null; + return String(signatureLen!!) + } + + + + fun getSignatureLenAsHex( ) : String? { + + if( null == this.signatureLen ) return null; + return Util.bytes2HexString(signatureLen) + } + + + + fun setSignatureLen( bytes : ByteArray ) : Data { + + this.signatureLen = bytes + return this + } + + + + fun getSignatureAsBin( ) : ByteArray? { + + return this.signature + } + + + + fun getSignatureAsStr( ) : String? { + + if( null == this.signature ) return null; + return String(signature!!) + } + + + + fun getSignatureAsHex( ) : String? { + + if( null == this.signature ) return null; + return Util.bytes2HexString(signature) + } + + + + fun setSignature( bytes : ByteArray ) : Data { + + this.signature = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != signatureLen ){ + + + soup.put("signatureLen", this.signatureLen!!) + } + +if( null != signature ){ + + + soup.put("signature", this.signature!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("signatureLen") ){ + + + this.signatureLen = (soup.get("signatureLen") as PacketSection).bytes +} + + +if( soup.containsKey("signature") ){ + + + this.signature = (soup.get("signature") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8006")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8006") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO8006.kt b/src/main/java/racal/sunyard/main/dto/DTO8006.kt new file mode 100644 index 0000000..9dc8389 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO8006.kt @@ -0,0 +1,1118 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO8006 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var hashFlag : ByteArray? = null + private var hash : ByteArray? = null + private var originLen : ByteArray? = null + private var originData : ByteArray? = null + private var signLen : ByteArray? = null + private var signData : ByteArray? = null + private var flag : ByteArray? = null + + + fun getHashFlagAsBin( ) : ByteArray? { + + return this.hashFlag + } + + + + fun getHashFlagAsStr( ) : String? { + + if( null == this.hashFlag ) return null; + return String(hashFlag!!) + } + + + + fun getHashFlagAsHex( ) : String? { + + if( null == this.hashFlag ) return null; + return Util.bytes2HexString(hashFlag) + } + + + + fun setHashFlag( bytes : ByteArray ) : Data { + + this.hashFlag = bytes + return this + } + + + + fun getHashAsBin( ) : ByteArray? { + + return this.hash + } + + + + fun getHashAsStr( ) : String? { + + if( null == this.hash ) return null; + return String(hash!!) + } + + + + fun getHashAsHex( ) : String? { + + if( null == this.hash ) return null; + return Util.bytes2HexString(hash) + } + + + + fun setHash( bytes : ByteArray ) : Data { + + this.hash = bytes + return this + } + + + + fun getOriginLenAsBin( ) : ByteArray? { + + return this.originLen + } + + + + fun getOriginLenAsStr( ) : String? { + + if( null == this.originLen ) return null; + return String(originLen!!) + } + + + + fun getOriginLenAsHex( ) : String? { + + if( null == this.originLen ) return null; + return Util.bytes2HexString(originLen) + } + + + + fun setOriginLen( bytes : ByteArray ) : Data { + + this.originLen = bytes + return this + } + + + + fun getOriginDataAsBin( ) : ByteArray? { + + return this.originData + } + + + + fun getOriginDataAsStr( ) : String? { + + if( null == this.originData ) return null; + return String(originData!!) + } + + + + fun getOriginDataAsHex( ) : String? { + + if( null == this.originData ) return null; + return Util.bytes2HexString(originData) + } + + + + fun setOriginData( bytes : ByteArray ) : Data { + + this.originData = bytes + return this + } + + + + fun getSignLenAsBin( ) : ByteArray? { + + return this.signLen + } + + + + fun getSignLenAsStr( ) : String? { + + if( null == this.signLen ) return null; + return String(signLen!!) + } + + + + fun getSignLenAsHex( ) : String? { + + if( null == this.signLen ) return null; + return Util.bytes2HexString(signLen) + } + + + + fun setSignLen( bytes : ByteArray ) : Data { + + this.signLen = bytes + return this + } + + + + fun getSignDataAsBin( ) : ByteArray? { + + return this.signData + } + + + + fun getSignDataAsStr( ) : String? { + + if( null == this.signData ) return null; + return String(signData!!) + } + + + + fun getSignDataAsHex( ) : String? { + + if( null == this.signData ) return null; + return Util.bytes2HexString(signData) + } + + + + fun setSignData( bytes : ByteArray ) : Data { + + this.signData = bytes + return this + } + + + + fun getFlagAsBin( ) : ByteArray? { + + return this.flag + } + + + + fun getFlagAsStr( ) : String? { + + if( null == this.flag ) return null; + return String(flag!!) + } + + + + fun getFlagAsHex( ) : String? { + + if( null == this.flag ) return null; + return Util.bytes2HexString(flag) + } + + + + fun setFlag( bytes : ByteArray ) : Data { + + this.flag = bytes + return this + } + + + enum class FlagOptions( val bin : ByteArray ) { + +OPV不返回(Util.hexString2Bytes("0000")), +OPV返回(Util.hexString2Bytes("0001")), + } + + fun getFlagCn( ) : String? { + + if( null == flag ) { return null } + +if( "0000".equals(Util.bytes2HexString(this.flag) ) ) { + + return "不返回" + +} + + +if( "0001".equals(Util.bytes2HexString(this.flag) ) ) { + + return "返回" + +} + + return null + } + + + + fun getFlagOptionIndex( ) : Int? { + + if( null == flag ) { return null } + +if( "0000".equals(Util.bytes2HexString(this.flag) ) ) { + + return 0 + +} + + +if( "0001".equals(Util.bytes2HexString(this.flag) ) ) { + + return 1 + +} + + return null + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != hashFlag ){ + + + soup.put("hashFlag", this.hashFlag!!) + } + +if( null != hash ){ + + + soup.put("hash", this.hash!!) + } + +if( null != originLen ){ + + + soup.put("originLen", this.originLen!!) + } + +if( null != originData ){ + + + soup.put("originData", this.originData!!) + } + +if( null != signLen ){ + + + soup.put("signLen", this.signLen!!) + } + +if( null != signData ){ + + + soup.put("signData", this.signData!!) + } + +if( null != flag ){ + + + soup.put("flag", this.flag!!) + soup.put("flag\$option", getFlagOptionIndex()!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("hashFlag") ){ + + + this.hashFlag = (soup.get("hashFlag") as PacketSection).bytes +} + + +if( soup.containsKey("hash") ){ + + + this.hash = (soup.get("hash") as PacketSection).bytes +} + + +if( soup.containsKey("originLen") ){ + + + this.originLen = (soup.get("originLen") as PacketSection).bytes +} + + +if( soup.containsKey("originData") ){ + + + this.originData = (soup.get("originData") as PacketSection).bytes +} + + +if( soup.containsKey("signLen") ){ + + + this.signLen = (soup.get("signLen") as PacketSection).bytes +} + + +if( soup.containsKey("signData") ){ + + + this.signData = (soup.get("signData") as PacketSection).bytes +} + + +if( soup.containsKey("flag") ){ + + + this.flag = (soup.get("flag") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8006")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8006") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var infoLen : ByteArray? = null + private var info : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getInfoLenAsBin( ) : ByteArray? { + + return this.infoLen + } + + + + fun getInfoLenAsStr( ) : String? { + + if( null == this.infoLen ) return null; + return String(infoLen!!) + } + + + + fun getInfoLenAsHex( ) : String? { + + if( null == this.infoLen ) return null; + return Util.bytes2HexString(infoLen) + } + + + + fun setInfoLen( bytes : ByteArray ) : Data { + + this.infoLen = bytes + return this + } + + + + fun getInfoAsBin( ) : ByteArray? { + + return this.info + } + + + + fun getInfoAsStr( ) : String? { + + if( null == this.info ) return null; + return String(info!!) + } + + + + fun getInfoAsHex( ) : String? { + + if( null == this.info ) return null; + return Util.bytes2HexString(info) + } + + + + fun setInfo( bytes : ByteArray ) : Data { + + this.info = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != infoLen ){ + + + soup.put("infoLen", this.infoLen!!) + } + +if( null != info ){ + + + soup.put("info", this.info!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("infoLen") ){ + + + this.infoLen = (soup.get("infoLen") as PacketSection).bytes +} + + +if( soup.containsKey("info") ){ + + + this.info = (soup.get("info") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8007")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8007") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO8012.kt b/src/main/java/racal/sunyard/main/dto/DTO8012.kt new file mode 100644 index 0000000..225a5b8 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO8012.kt @@ -0,0 +1,1133 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO8012 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var originLen : ByteArray? = null + private var originData : ByteArray? = null + private var signLen : ByteArray? = null + private var signData : ByteArray? = null + private var flag : ByteArray? = null + private var organizationNumLen : ByteArray? = null + private var organizationNum : ByteArray? = null + + + fun getOriginLenAsBin( ) : ByteArray? { + + return this.originLen + } + + + + fun getOriginLenAsStr( ) : String? { + + if( null == this.originLen ) return null; + return String(originLen!!) + } + + + + fun getOriginLenAsHex( ) : String? { + + if( null == this.originLen ) return null; + return Util.bytes2HexString(originLen) + } + + + + fun setOriginLen( bytes : ByteArray ) : Data { + + this.originLen = bytes + return this + } + + + + fun getOriginDataAsBin( ) : ByteArray? { + + return this.originData + } + + + + fun getOriginDataAsStr( ) : String? { + + if( null == this.originData ) return null; + return String(originData!!) + } + + + + fun getOriginDataAsHex( ) : String? { + + if( null == this.originData ) return null; + return Util.bytes2HexString(originData) + } + + + + fun setOriginData( bytes : ByteArray ) : Data { + + this.originData = bytes + return this + } + + + + fun getSignLenAsBin( ) : ByteArray? { + + return this.signLen + } + + + + fun getSignLenAsStr( ) : String? { + + if( null == this.signLen ) return null; + return String(signLen!!) + } + + + + fun getSignLenAsHex( ) : String? { + + if( null == this.signLen ) return null; + return Util.bytes2HexString(signLen) + } + + + + fun setSignLen( bytes : ByteArray ) : Data { + + this.signLen = bytes + return this + } + + + + fun getSignDataAsBin( ) : ByteArray? { + + return this.signData + } + + + + fun getSignDataAsStr( ) : String? { + + if( null == this.signData ) return null; + return String(signData!!) + } + + + + fun getSignDataAsHex( ) : String? { + + if( null == this.signData ) return null; + return Util.bytes2HexString(signData) + } + + + + fun setSignData( bytes : ByteArray ) : Data { + + this.signData = bytes + return this + } + + + + fun getFlagAsBin( ) : ByteArray? { + + return this.flag + } + + + + fun getFlagAsStr( ) : String? { + + if( null == this.flag ) return null; + return String(flag!!) + } + + + + fun getFlagAsHex( ) : String? { + + if( null == this.flag ) return null; + return Util.bytes2HexString(flag) + } + + + + fun setFlag( bytes : ByteArray ) : Data { + + this.flag = bytes + return this + } + + + enum class FlagOptions( val bin : ByteArray ) { + +OPV不上载(Util.hexString2Bytes("0000")), +OPV上载并返回证书内容(Util.hexString2Bytes("0001")), +OPV上传并返回证书内容并更新机构号(Util.hexString2Bytes("0002")), + } + + fun getFlagCn( ) : String? { + + if( null == flag ) { return null } + +if( "0000".equals(Util.bytes2HexString(this.flag) ) ) { + + return "不上载" + +} + + +if( "0001".equals(Util.bytes2HexString(this.flag) ) ) { + + return "上载并返回证书内容" + +} + + +if( "0002".equals(Util.bytes2HexString(this.flag) ) ) { + + return "上传并返回证书内容,并更新机构号" + +} + + return null + } + + + + fun getFlagOptionIndex( ) : Int? { + + if( null == flag ) { return null } + +if( "0000".equals(Util.bytes2HexString(this.flag) ) ) { + + return 0 + +} + + +if( "0001".equals(Util.bytes2HexString(this.flag) ) ) { + + return 1 + +} + + +if( "0002".equals(Util.bytes2HexString(this.flag) ) ) { + + return 2 + +} + + return null + } + + + + fun getOrganizationNumLenAsBin( ) : ByteArray? { + + return this.organizationNumLen + } + + + + fun getOrganizationNumLenAsStr( ) : String? { + + if( null == this.organizationNumLen ) return null; + return String(organizationNumLen!!) + } + + + + fun getOrganizationNumLenAsHex( ) : String? { + + if( null == this.organizationNumLen ) return null; + return Util.bytes2HexString(organizationNumLen) + } + + + + fun setOrganizationNumLen( bytes : ByteArray ) : Data { + + this.organizationNumLen = bytes + return this + } + + + + fun getOrganizationNumAsBin( ) : ByteArray? { + + return this.organizationNum + } + + + + fun getOrganizationNumAsStr( ) : String? { + + if( null == this.organizationNum ) return null; + return String(organizationNum!!) + } + + + + fun getOrganizationNumAsHex( ) : String? { + + if( null == this.organizationNum ) return null; + return Util.bytes2HexString(organizationNum) + } + + + + fun setOrganizationNum( bytes : ByteArray ) : Data { + + this.organizationNum = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != originLen ){ + + + soup.put("originLen", this.originLen!!) + } + +if( null != originData ){ + + + soup.put("originData", this.originData!!) + } + +if( null != signLen ){ + + + soup.put("signLen", this.signLen!!) + } + +if( null != signData ){ + + + soup.put("signData", this.signData!!) + } + +if( null != flag ){ + + + soup.put("flag", this.flag!!) + soup.put("flag\$option", getFlagOptionIndex()!!) + } + +if( null != organizationNumLen ){ + + + soup.put("organizationNumLen", this.organizationNumLen!!) + } + +if( null != organizationNum ){ + + + soup.put("organizationNum", this.organizationNum!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("originLen") ){ + + + this.originLen = (soup.get("originLen") as PacketSection).bytes +} + + +if( soup.containsKey("originData") ){ + + + this.originData = (soup.get("originData") as PacketSection).bytes +} + + +if( soup.containsKey("signLen") ){ + + + this.signLen = (soup.get("signLen") as PacketSection).bytes +} + + +if( soup.containsKey("signData") ){ + + + this.signData = (soup.get("signData") as PacketSection).bytes +} + + +if( soup.containsKey("flag") ){ + + + this.flag = (soup.get("flag") as PacketSection).bytes +} + + +if( soup.containsKey("organizationNumLen") ){ + + + this.organizationNumLen = (soup.get("organizationNumLen") as PacketSection).bytes +} + + +if( soup.containsKey("organizationNum") ){ + + + this.organizationNum = (soup.get("organizationNum") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8012")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8012") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var infoLen : ByteArray? = null + private var info : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getInfoLenAsBin( ) : ByteArray? { + + return this.infoLen + } + + + + fun getInfoLenAsStr( ) : String? { + + if( null == this.infoLen ) return null; + return String(infoLen!!) + } + + + + fun getInfoLenAsHex( ) : String? { + + if( null == this.infoLen ) return null; + return Util.bytes2HexString(infoLen) + } + + + + fun setInfoLen( bytes : ByteArray ) : Data { + + this.infoLen = bytes + return this + } + + + + fun getInfoAsBin( ) : ByteArray? { + + return this.info + } + + + + fun getInfoAsStr( ) : String? { + + if( null == this.info ) return null; + return String(info!!) + } + + + + fun getInfoAsHex( ) : String? { + + if( null == this.info ) return null; + return Util.bytes2HexString(info) + } + + + + fun setInfo( bytes : ByteArray ) : Data { + + this.info = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != infoLen ){ + + + soup.put("infoLen", this.infoLen!!) + } + +if( null != info ){ + + + soup.put("info", this.info!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("infoLen") ){ + + + this.infoLen = (soup.get("infoLen") as PacketSection).bytes +} + + +if( soup.containsKey("info") ){ + + + this.info = (soup.get("info") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8013")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8013") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO8016.kt b/src/main/java/racal/sunyard/main/dto/DTO8016.kt new file mode 100644 index 0000000..b8644c1 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO8016.kt @@ -0,0 +1,888 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO8016 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var certLen : ByteArray? = null + private var cert : ByteArray? = null + + + fun getCertLenAsBin( ) : ByteArray? { + + return this.certLen + } + + + + fun getCertLenAsStr( ) : String? { + + if( null == this.certLen ) return null; + return String(certLen!!) + } + + + + fun getCertLenAsHex( ) : String? { + + if( null == this.certLen ) return null; + return Util.bytes2HexString(certLen) + } + + + + fun setCertLen( bytes : ByteArray ) : Data { + + this.certLen = bytes + return this + } + + + + fun getCertAsBin( ) : ByteArray? { + + return this.cert + } + + + + fun getCertAsStr( ) : String? { + + if( null == this.cert ) return null; + return String(cert!!) + } + + + + fun getCertAsHex( ) : String? { + + if( null == this.cert ) return null; + return Util.bytes2HexString(cert) + } + + + + fun setCert( bytes : ByteArray ) : Data { + + this.cert = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != certLen ){ + + + soup.put("certLen", this.certLen!!) + } + +if( null != cert ){ + + + soup.put("cert", this.cert!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("certLen") ){ + + + this.certLen = (soup.get("certLen") as PacketSection).bytes +} + + +if( soup.containsKey("cert") ){ + + + this.cert = (soup.get("cert") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8016")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8016") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var certInfoLen : ByteArray? = null + private var certInfo : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效的私钥类型(Util.hexString2Bytes("3033")), +OPV无效私钥标记(Util.hexString2Bytes("3034")), +OPV无效的哈希标识(Util.hexString2Bytes("3035")), +OPV无效的签名标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV无效摘要信息语法仅仅无哈希模式(Util.hexString2Bytes("3734")), +OPV公钥长度错误(Util.hexString2Bytes("3736")), +OPV私钥长度错误(Util.hexString2Bytes("3738")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的私钥类型" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效私钥标记" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的哈希标识" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的签名标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效摘要信息语法(仅仅无哈希模式)" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥长度错误" + +} + + +if( "3738".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + +if( "3738".equals(Util.bytes2HexString(this.error) ) ) { + + return 12 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 13 + +} + + return null + } + + + + fun getCertInfoLenAsBin( ) : ByteArray? { + + return this.certInfoLen + } + + + + fun getCertInfoLenAsStr( ) : String? { + + if( null == this.certInfoLen ) return null; + return String(certInfoLen!!) + } + + + + fun getCertInfoLenAsHex( ) : String? { + + if( null == this.certInfoLen ) return null; + return Util.bytes2HexString(certInfoLen) + } + + + + fun setCertInfoLen( bytes : ByteArray ) : Data { + + this.certInfoLen = bytes + return this + } + + + + fun getCertInfoAsBin( ) : ByteArray? { + + return this.certInfo + } + + + + fun getCertInfoAsStr( ) : String? { + + if( null == this.certInfo ) return null; + return String(certInfo!!) + } + + + + fun getCertInfoAsHex( ) : String? { + + if( null == this.certInfo ) return null; + return Util.bytes2HexString(certInfo) + } + + + + fun setCertInfo( bytes : ByteArray ) : Data { + + this.certInfo = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != certInfoLen ){ + + + soup.put("certInfoLen", this.certInfoLen!!) + } + +if( null != certInfo ){ + + + soup.put("certInfo", this.certInfo!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("certInfoLen") ){ + + + this.certInfoLen = (soup.get("certInfoLen") as PacketSection).bytes +} + + +if( soup.containsKey("certInfo") ){ + + + this.certInfo = (soup.get("certInfo") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8017")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8017") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO8017.kt b/src/main/java/racal/sunyard/main/dto/DTO8017.kt new file mode 100644 index 0000000..acd88ba --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO8017.kt @@ -0,0 +1,980 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO8017 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var userId : ByteArray? = null + private var type : ByteArray? = null + + + fun getUserIdAsBin( ) : ByteArray? { + + return this.userId + } + + + + fun getUserIdAsStr( ) : String? { + + if( null == this.userId ) return null; + return String(userId!!) + } + + + + fun getUserIdAsHex( ) : String? { + + if( null == this.userId ) return null; + return Util.bytes2HexString(userId) + } + + + + fun setUserId( bytes : ByteArray ) : Data { + + this.userId = bytes + return this + } + + + + fun getTypeAsBin( ) : ByteArray? { + + return this.type + } + + + + fun getTypeAsStr( ) : String? { + + if( null == this.type ) return null; + return String(type!!) + } + + + + fun getTypeAsHex( ) : String? { + + if( null == this.type ) return null; + return Util.bytes2HexString(type) + } + + + + fun setType( bytes : ByteArray ) : Data { + + this.type = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != userId ){ + + + soup.put("userId", this.userId!!) + } + +if( null != type ){ + + + soup.put("type", this.type!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("userId") ){ + + + this.userId = (soup.get("userId") as PacketSection).bytes +} + + +if( soup.containsKey("type") ){ + + + this.type = (soup.get("type") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8017")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8017") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var certLen : ByteArray? = null + private var cert : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效的私钥类型(Util.hexString2Bytes("3033")), +OPV无效私钥标记(Util.hexString2Bytes("3034")), +OPV无效的哈希标识(Util.hexString2Bytes("3035")), +OPV无效的签名标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV无效摘要信息语法仅仅无哈希模式(Util.hexString2Bytes("3734")), +OPV公钥长度错误(Util.hexString2Bytes("3736")), +OPV私钥长度错误(Util.hexString2Bytes("3738")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的私钥类型" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效私钥标记" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的哈希标识" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的签名标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效摘要信息语法(仅仅无哈希模式)" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥长度错误" + +} + + +if( "3738".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + +if( "3738".equals(Util.bytes2HexString(this.error) ) ) { + + return 12 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 13 + +} + + return null + } + + + + fun getCertLenAsBin( ) : ByteArray? { + + return this.certLen + } + + + + fun getCertLenAsStr( ) : String? { + + if( null == this.certLen ) return null; + return String(certLen!!) + } + + + + fun getCertLenAsHex( ) : String? { + + if( null == this.certLen ) return null; + return Util.bytes2HexString(certLen) + } + + + + fun setCertLen( bytes : ByteArray ) : Data { + + this.certLen = bytes + return this + } + + + + fun getCertAsBin( ) : ByteArray? { + + return this.cert + } + + + + fun getCertAsStr( ) : String? { + + if( null == this.cert ) return null; + return String(cert!!) + } + + + + fun getCertAsHex( ) : String? { + + if( null == this.cert ) return null; + return Util.bytes2HexString(cert) + } + + + + fun setCert( bytes : ByteArray ) : Data { + + this.cert = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != certLen ){ + + + soup.put("certLen", this.certLen!!) + } + +if( null != cert ){ + + + soup.put("cert", this.cert!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("certLen") ){ + + + this.certLen = (soup.get("certLen") as PacketSection).bytes +} + + +if( soup.containsKey("cert") ){ + + + this.cert = (soup.get("cert") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8018")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8018") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO8018.kt b/src/main/java/racal/sunyard/main/dto/DTO8018.kt new file mode 100644 index 0000000..ee47150 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO8018.kt @@ -0,0 +1,888 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO8018 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var dN : ByteArray? = null + private var dataLen : ByteArray? = null + private var infoData : ByteArray? = null + + + fun getDNAsBin( ) : ByteArray? { + + return this.dN + } + + + + fun getDNAsStr( ) : String? { + + if( null == this.dN ) return null; + return String(dN!!) + } + + + + fun getDNAsHex( ) : String? { + + if( null == this.dN ) return null; + return Util.bytes2HexString(dN) + } + + + + fun setDN( bytes : ByteArray ) : Data { + + this.dN = bytes + return this + } + + + + fun getDataLenAsBin( ) : ByteArray? { + + return this.dataLen + } + + + + fun getDataLenAsStr( ) : String? { + + if( null == this.dataLen ) return null; + return String(dataLen!!) + } + + + + fun getDataLenAsHex( ) : String? { + + if( null == this.dataLen ) return null; + return Util.bytes2HexString(dataLen) + } + + + + fun setDataLen( bytes : ByteArray ) : Data { + + this.dataLen = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != dN ){ + + + soup.put("DN", this.dN!!) + } + +if( null != dataLen ){ + + + soup.put("dataLen", this.dataLen!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("DN") ){ + + + this.dN = (soup.get("DN") as PacketSection).bytes +} + + +if( soup.containsKey("dataLen") ){ + + + this.dataLen = (soup.get("dataLen") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8018")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8018") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var signatureLen : ByteArray? = null + private var signature : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getSignatureLenAsBin( ) : ByteArray? { + + return this.signatureLen + } + + + + fun getSignatureLenAsStr( ) : String? { + + if( null == this.signatureLen ) return null; + return String(signatureLen!!) + } + + + + fun getSignatureLenAsHex( ) : String? { + + if( null == this.signatureLen ) return null; + return Util.bytes2HexString(signatureLen) + } + + + + fun setSignatureLen( bytes : ByteArray ) : Data { + + this.signatureLen = bytes + return this + } + + + + fun getSignatureAsBin( ) : ByteArray? { + + return this.signature + } + + + + fun getSignatureAsStr( ) : String? { + + if( null == this.signature ) return null; + return String(signature!!) + } + + + + fun getSignatureAsHex( ) : String? { + + if( null == this.signature ) return null; + return Util.bytes2HexString(signature) + } + + + + fun setSignature( bytes : ByteArray ) : Data { + + this.signature = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != signatureLen ){ + + + soup.put("signatureLen", this.signatureLen!!) + } + +if( null != signature ){ + + + soup.put("signature", this.signature!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("signatureLen") ){ + + + this.signatureLen = (soup.get("signatureLen") as PacketSection).bytes +} + + +if( soup.containsKey("signature") ){ + + + this.signature = (soup.get("signature") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8006")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8006") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO8019.kt b/src/main/java/racal/sunyard/main/dto/DTO8019.kt new file mode 100644 index 0000000..b74bfc3 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO8019.kt @@ -0,0 +1,983 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO8019 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var dN : ByteArray? = null + private var dataLen : ByteArray? = null + private var infoData : ByteArray? = null + private var flag : ByteArray? = null + + + fun getDNAsBin( ) : ByteArray? { + + return this.dN + } + + + + fun getDNAsStr( ) : String? { + + if( null == this.dN ) return null; + return String(dN!!) + } + + + + fun getDNAsHex( ) : String? { + + if( null == this.dN ) return null; + return Util.bytes2HexString(dN) + } + + + + fun setDN( bytes : ByteArray ) : Data { + + this.dN = bytes + return this + } + + + + fun getDataLenAsBin( ) : ByteArray? { + + return this.dataLen + } + + + + fun getDataLenAsStr( ) : String? { + + if( null == this.dataLen ) return null; + return String(dataLen!!) + } + + + + fun getDataLenAsHex( ) : String? { + + if( null == this.dataLen ) return null; + return Util.bytes2HexString(dataLen) + } + + + + fun setDataLen( bytes : ByteArray ) : Data { + + this.dataLen = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getFlagAsBin( ) : ByteArray? { + + return this.flag + } + + + + fun getFlagAsStr( ) : String? { + + if( null == this.flag ) return null; + return String(flag!!) + } + + + + fun getFlagAsHex( ) : String? { + + if( null == this.flag ) return null; + return Util.bytes2HexString(flag) + } + + + + fun setFlag( bytes : ByteArray ) : Data { + + this.flag = bytes + return this + } + + + enum class FlagOptions( val bin : ByteArray ) { + +OPV不返回(Util.hexString2Bytes("0000")), +OPV返回(Util.hexString2Bytes("0001")), + } + + fun getFlagCn( ) : String? { + + if( null == flag ) { return null } + +if( "0000".equals(Util.bytes2HexString(this.flag) ) ) { + + return "不返回" + +} + + +if( "0001".equals(Util.bytes2HexString(this.flag) ) ) { + + return "返回" + +} + + return null + } + + + + fun getFlagOptionIndex( ) : Int? { + + if( null == flag ) { return null } + +if( "0000".equals(Util.bytes2HexString(this.flag) ) ) { + + return 0 + +} + + +if( "0001".equals(Util.bytes2HexString(this.flag) ) ) { + + return 1 + +} + + return null + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != dN ){ + + + soup.put("DN", this.dN!!) + } + +if( null != dataLen ){ + + + soup.put("dataLen", this.dataLen!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + +if( null != flag ){ + + + soup.put("flag", this.flag!!) + soup.put("flag\$option", getFlagOptionIndex()!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("DN") ){ + + + this.dN = (soup.get("DN") as PacketSection).bytes +} + + +if( soup.containsKey("dataLen") ){ + + + this.dataLen = (soup.get("dataLen") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + +if( soup.containsKey("flag") ){ + + + this.flag = (soup.get("flag") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8019")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8019") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var infoLen : ByteArray? = null + private var info : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getInfoLenAsBin( ) : ByteArray? { + + return this.infoLen + } + + + + fun getInfoLenAsStr( ) : String? { + + if( null == this.infoLen ) return null; + return String(infoLen!!) + } + + + + fun getInfoLenAsHex( ) : String? { + + if( null == this.infoLen ) return null; + return Util.bytes2HexString(infoLen) + } + + + + fun setInfoLen( bytes : ByteArray ) : Data { + + this.infoLen = bytes + return this + } + + + + fun getInfoAsBin( ) : ByteArray? { + + return this.info + } + + + + fun getInfoAsStr( ) : String? { + + if( null == this.info ) return null; + return String(info!!) + } + + + + fun getInfoAsHex( ) : String? { + + if( null == this.info ) return null; + return Util.bytes2HexString(info) + } + + + + fun setInfo( bytes : ByteArray ) : Data { + + this.info = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != infoLen ){ + + + soup.put("infoLen", this.infoLen!!) + } + +if( null != info ){ + + + soup.put("info", this.info!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("infoLen") ){ + + + this.infoLen = (soup.get("infoLen") as PacketSection).bytes +} + + +if( soup.containsKey("info") ){ + + + this.info = (soup.get("info") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8007")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8007") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO8024.kt b/src/main/java/racal/sunyard/main/dto/DTO8024.kt new file mode 100644 index 0000000..dc729a4 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO8024.kt @@ -0,0 +1,978 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO8024 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var keyTag : ByteArray? = null + private var hashFlag : ByteArray? = null + private var hash : ByteArray? = null + private var dataLen : ByteArray? = null + private var infoData : ByteArray? = null + + + fun getKeyTagAsBin( ) : ByteArray? { + + return this.keyTag + } + + + + fun getKeyTagAsStr( ) : String? { + + if( null == this.keyTag ) return null; + return String(keyTag!!) + } + + + + fun getKeyTagAsHex( ) : String? { + + if( null == this.keyTag ) return null; + return Util.bytes2HexString(keyTag) + } + + + + fun setKeyTag( bytes : ByteArray ) : Data { + + this.keyTag = bytes + return this + } + + + + fun getHashFlagAsBin( ) : ByteArray? { + + return this.hashFlag + } + + + + fun getHashFlagAsStr( ) : String? { + + if( null == this.hashFlag ) return null; + return String(hashFlag!!) + } + + + + fun getHashFlagAsHex( ) : String? { + + if( null == this.hashFlag ) return null; + return Util.bytes2HexString(hashFlag) + } + + + + fun setHashFlag( bytes : ByteArray ) : Data { + + this.hashFlag = bytes + return this + } + + + + fun getHashAsBin( ) : ByteArray? { + + return this.hash + } + + + + fun getHashAsStr( ) : String? { + + if( null == this.hash ) return null; + return String(hash!!) + } + + + + fun getHashAsHex( ) : String? { + + if( null == this.hash ) return null; + return Util.bytes2HexString(hash) + } + + + + fun setHash( bytes : ByteArray ) : Data { + + this.hash = bytes + return this + } + + + + fun getDataLenAsBin( ) : ByteArray? { + + return this.dataLen + } + + + + fun getDataLenAsStr( ) : String? { + + if( null == this.dataLen ) return null; + return String(dataLen!!) + } + + + + fun getDataLenAsHex( ) : String? { + + if( null == this.dataLen ) return null; + return Util.bytes2HexString(dataLen) + } + + + + fun setDataLen( bytes : ByteArray ) : Data { + + this.dataLen = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != keyTag ){ + + + soup.put("keyTag", this.keyTag!!) + } + +if( null != hashFlag ){ + + + soup.put("hashFlag", this.hashFlag!!) + } + +if( null != hash ){ + + + soup.put("hash", this.hash!!) + } + +if( null != dataLen ){ + + + soup.put("dataLen", this.dataLen!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("keyTag") ){ + + + this.keyTag = (soup.get("keyTag") as PacketSection).bytes +} + + +if( soup.containsKey("hashFlag") ){ + + + this.hashFlag = (soup.get("hashFlag") as PacketSection).bytes +} + + +if( soup.containsKey("hash") ){ + + + this.hash = (soup.get("hash") as PacketSection).bytes +} + + +if( soup.containsKey("dataLen") ){ + + + this.dataLen = (soup.get("dataLen") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8024")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8024") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var signatureLen : ByteArray? = null + private var signature : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getSignatureLenAsBin( ) : ByteArray? { + + return this.signatureLen + } + + + + fun getSignatureLenAsStr( ) : String? { + + if( null == this.signatureLen ) return null; + return String(signatureLen!!) + } + + + + fun getSignatureLenAsHex( ) : String? { + + if( null == this.signatureLen ) return null; + return Util.bytes2HexString(signatureLen) + } + + + + fun setSignatureLen( bytes : ByteArray ) : Data { + + this.signatureLen = bytes + return this + } + + + + fun getSignatureAsBin( ) : ByteArray? { + + return this.signature + } + + + + fun getSignatureAsStr( ) : String? { + + if( null == this.signature ) return null; + return String(signature!!) + } + + + + fun getSignatureAsHex( ) : String? { + + if( null == this.signature ) return null; + return Util.bytes2HexString(signature) + } + + + + fun setSignature( bytes : ByteArray ) : Data { + + this.signature = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != signatureLen ){ + + + soup.put("signatureLen", this.signatureLen!!) + } + +if( null != signature ){ + + + soup.put("signature", this.signature!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("signatureLen") ){ + + + this.signatureLen = (soup.get("signatureLen") as PacketSection).bytes +} + + +if( soup.containsKey("signature") ){ + + + this.signature = (soup.get("signature") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8025")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8025") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO8025.kt b/src/main/java/racal/sunyard/main/dto/DTO8025.kt new file mode 100644 index 0000000..94d96f2 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO8025.kt @@ -0,0 +1,1118 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO8025 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var hashFlag : ByteArray? = null + private var hash : ByteArray? = null + private var originLen : ByteArray? = null + private var originData : ByteArray? = null + private var signLen : ByteArray? = null + private var signData : ByteArray? = null + private var flag : ByteArray? = null + + + fun getHashFlagAsBin( ) : ByteArray? { + + return this.hashFlag + } + + + + fun getHashFlagAsStr( ) : String? { + + if( null == this.hashFlag ) return null; + return String(hashFlag!!) + } + + + + fun getHashFlagAsHex( ) : String? { + + if( null == this.hashFlag ) return null; + return Util.bytes2HexString(hashFlag) + } + + + + fun setHashFlag( bytes : ByteArray ) : Data { + + this.hashFlag = bytes + return this + } + + + + fun getHashAsBin( ) : ByteArray? { + + return this.hash + } + + + + fun getHashAsStr( ) : String? { + + if( null == this.hash ) return null; + return String(hash!!) + } + + + + fun getHashAsHex( ) : String? { + + if( null == this.hash ) return null; + return Util.bytes2HexString(hash) + } + + + + fun setHash( bytes : ByteArray ) : Data { + + this.hash = bytes + return this + } + + + + fun getOriginLenAsBin( ) : ByteArray? { + + return this.originLen + } + + + + fun getOriginLenAsStr( ) : String? { + + if( null == this.originLen ) return null; + return String(originLen!!) + } + + + + fun getOriginLenAsHex( ) : String? { + + if( null == this.originLen ) return null; + return Util.bytes2HexString(originLen) + } + + + + fun setOriginLen( bytes : ByteArray ) : Data { + + this.originLen = bytes + return this + } + + + + fun getOriginDataAsBin( ) : ByteArray? { + + return this.originData + } + + + + fun getOriginDataAsStr( ) : String? { + + if( null == this.originData ) return null; + return String(originData!!) + } + + + + fun getOriginDataAsHex( ) : String? { + + if( null == this.originData ) return null; + return Util.bytes2HexString(originData) + } + + + + fun setOriginData( bytes : ByteArray ) : Data { + + this.originData = bytes + return this + } + + + + fun getSignLenAsBin( ) : ByteArray? { + + return this.signLen + } + + + + fun getSignLenAsStr( ) : String? { + + if( null == this.signLen ) return null; + return String(signLen!!) + } + + + + fun getSignLenAsHex( ) : String? { + + if( null == this.signLen ) return null; + return Util.bytes2HexString(signLen) + } + + + + fun setSignLen( bytes : ByteArray ) : Data { + + this.signLen = bytes + return this + } + + + + fun getSignDataAsBin( ) : ByteArray? { + + return this.signData + } + + + + fun getSignDataAsStr( ) : String? { + + if( null == this.signData ) return null; + return String(signData!!) + } + + + + fun getSignDataAsHex( ) : String? { + + if( null == this.signData ) return null; + return Util.bytes2HexString(signData) + } + + + + fun setSignData( bytes : ByteArray ) : Data { + + this.signData = bytes + return this + } + + + + fun getFlagAsBin( ) : ByteArray? { + + return this.flag + } + + + + fun getFlagAsStr( ) : String? { + + if( null == this.flag ) return null; + return String(flag!!) + } + + + + fun getFlagAsHex( ) : String? { + + if( null == this.flag ) return null; + return Util.bytes2HexString(flag) + } + + + + fun setFlag( bytes : ByteArray ) : Data { + + this.flag = bytes + return this + } + + + enum class FlagOptions( val bin : ByteArray ) { + +OPV不返回(Util.hexString2Bytes("0000")), +OPV返回(Util.hexString2Bytes("0001")), + } + + fun getFlagCn( ) : String? { + + if( null == flag ) { return null } + +if( "0000".equals(Util.bytes2HexString(this.flag) ) ) { + + return "不返回" + +} + + +if( "0001".equals(Util.bytes2HexString(this.flag) ) ) { + + return "返回" + +} + + return null + } + + + + fun getFlagOptionIndex( ) : Int? { + + if( null == flag ) { return null } + +if( "0000".equals(Util.bytes2HexString(this.flag) ) ) { + + return 0 + +} + + +if( "0001".equals(Util.bytes2HexString(this.flag) ) ) { + + return 1 + +} + + return null + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != hashFlag ){ + + + soup.put("hashFlag", this.hashFlag!!) + } + +if( null != hash ){ + + + soup.put("hash", this.hash!!) + } + +if( null != originLen ){ + + + soup.put("originLen", this.originLen!!) + } + +if( null != originData ){ + + + soup.put("originData", this.originData!!) + } + +if( null != signLen ){ + + + soup.put("signLen", this.signLen!!) + } + +if( null != signData ){ + + + soup.put("signData", this.signData!!) + } + +if( null != flag ){ + + + soup.put("flag", this.flag!!) + soup.put("flag\$option", getFlagOptionIndex()!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("hashFlag") ){ + + + this.hashFlag = (soup.get("hashFlag") as PacketSection).bytes +} + + +if( soup.containsKey("hash") ){ + + + this.hash = (soup.get("hash") as PacketSection).bytes +} + + +if( soup.containsKey("originLen") ){ + + + this.originLen = (soup.get("originLen") as PacketSection).bytes +} + + +if( soup.containsKey("originData") ){ + + + this.originData = (soup.get("originData") as PacketSection).bytes +} + + +if( soup.containsKey("signLen") ){ + + + this.signLen = (soup.get("signLen") as PacketSection).bytes +} + + +if( soup.containsKey("signData") ){ + + + this.signData = (soup.get("signData") as PacketSection).bytes +} + + +if( soup.containsKey("flag") ){ + + + this.flag = (soup.get("flag") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8025")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8025") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var infoLen : ByteArray? = null + private var info : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getInfoLenAsBin( ) : ByteArray? { + + return this.infoLen + } + + + + fun getInfoLenAsStr( ) : String? { + + if( null == this.infoLen ) return null; + return String(infoLen!!) + } + + + + fun getInfoLenAsHex( ) : String? { + + if( null == this.infoLen ) return null; + return Util.bytes2HexString(infoLen) + } + + + + fun setInfoLen( bytes : ByteArray ) : Data { + + this.infoLen = bytes + return this + } + + + + fun getInfoAsBin( ) : ByteArray? { + + return this.info + } + + + + fun getInfoAsStr( ) : String? { + + if( null == this.info ) return null; + return String(info!!) + } + + + + fun getInfoAsHex( ) : String? { + + if( null == this.info ) return null; + return Util.bytes2HexString(info) + } + + + + fun setInfo( bytes : ByteArray ) : Data { + + this.info = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != infoLen ){ + + + soup.put("infoLen", this.infoLen!!) + } + +if( null != info ){ + + + soup.put("info", this.info!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("infoLen") ){ + + + this.infoLen = (soup.get("infoLen") as PacketSection).bytes +} + + +if( soup.containsKey("info") ){ + + + this.info = (soup.get("info") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8026")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8026") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO8026.kt b/src/main/java/racal/sunyard/main/dto/DTO8026.kt new file mode 100644 index 0000000..cd08633 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO8026.kt @@ -0,0 +1,965 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO8026 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var certificateNoLen : ByteArray? = null + private var certificateNo : ByteArray? = null + private var dataSign : ByteArray? = null + private var hash : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getCertificateNoLenAsBin( ) : ByteArray? { + + return this.certificateNoLen + } + + + + fun getCertificateNoLenAsStr( ) : String? { + + if( null == this.certificateNoLen ) return null; + return String(certificateNoLen!!) + } + + + + fun getCertificateNoLenAsHex( ) : String? { + + if( null == this.certificateNoLen ) return null; + return Util.bytes2HexString(certificateNoLen) + } + + + + fun setCertificateNoLen( bytes : ByteArray ) : Data { + + this.certificateNoLen = bytes + return this + } + + + + fun getCertificateNoAsBin( ) : ByteArray? { + + return this.certificateNo + } + + + + fun getCertificateNoAsStr( ) : String? { + + if( null == this.certificateNo ) return null; + return String(certificateNo!!) + } + + + + fun getCertificateNoAsHex( ) : String? { + + if( null == this.certificateNo ) return null; + return Util.bytes2HexString(certificateNo) + } + + + + fun setCertificateNo( bytes : ByteArray ) : Data { + + this.certificateNo = bytes + return this + } + + + + fun getDataSignAsBin( ) : ByteArray? { + + return this.dataSign + } + + + + fun getDataSignAsStr( ) : String? { + + if( null == this.dataSign ) return null; + return String(dataSign!!) + } + + + + fun getDataSignAsHex( ) : String? { + + if( null == this.dataSign ) return null; + return Util.bytes2HexString(dataSign) + } + + + + fun setDataSign( bytes : ByteArray ) : Data { + + this.dataSign = bytes + return this + } + + + + fun getHashAsBin( ) : ByteArray? { + + return this.hash + } + + + + fun getHashAsStr( ) : String? { + + if( null == this.hash ) return null; + return String(hash!!) + } + + + + fun getHashAsHex( ) : String? { + + if( null == this.hash ) return null; + return Util.bytes2HexString(hash) + } + + + + fun setHash( bytes : ByteArray ) : Data { + + this.hash = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != certificateNoLen ){ + + + soup.put("certificateNoLen", this.certificateNoLen!!) + } + +if( null != certificateNo ){ + + + soup.put("certificateNo", this.certificateNo!!) + } + +if( null != dataSign ){ + + + soup.put("dataSign", this.dataSign!!) + } + +if( null != hash ){ + + + soup.put("hash", this.hash!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("certificateNoLen") ){ + + + this.certificateNoLen = (soup.get("certificateNoLen") as PacketSection).bytes +} + + +if( soup.containsKey("certificateNo") ){ + + + this.certificateNo = (soup.get("certificateNo") as PacketSection).bytes +} + + +if( soup.containsKey("dataSign") ){ + + + this.dataSign = (soup.get("dataSign") as PacketSection).bytes +} + + +if( soup.containsKey("hash") ){ + + + this.hash = (soup.get("hash") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8026")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8026") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var signatureLen : ByteArray? = null + private var signature : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + return null + } + + + + fun getSignatureLenAsBin( ) : ByteArray? { + + return this.signatureLen + } + + + + fun getSignatureLenAsStr( ) : String? { + + if( null == this.signatureLen ) return null; + return String(signatureLen!!) + } + + + + fun getSignatureLenAsHex( ) : String? { + + if( null == this.signatureLen ) return null; + return Util.bytes2HexString(signatureLen) + } + + + + fun setSignatureLen( bytes : ByteArray ) : Data { + + this.signatureLen = bytes + return this + } + + + + fun getSignatureAsBin( ) : ByteArray? { + + return this.signature + } + + + + fun getSignatureAsStr( ) : String? { + + if( null == this.signature ) return null; + return String(signature!!) + } + + + + fun getSignatureAsHex( ) : String? { + + if( null == this.signature ) return null; + return Util.bytes2HexString(signature) + } + + + + fun setSignature( bytes : ByteArray ) : Data { + + this.signature = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != signatureLen ){ + + + soup.put("signatureLen", this.signatureLen!!) + } + +if( null != signature ){ + + + soup.put("signature", this.signature!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("signatureLen") ){ + + + this.signatureLen = (soup.get("signatureLen") as PacketSection).bytes +} + + +if( soup.containsKey("signature") ){ + + + this.signature = (soup.get("signature") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("8027")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("8027") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO81.kt b/src/main/java/racal/sunyard/main/dto/DTO81.kt new file mode 100644 index 0000000..ab288ac --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO81.kt @@ -0,0 +1,1102 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO81 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var certificateNoLen : ByteArray? = null + private var certificateNo : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var signatureLen : ByteArray? = null + private var signature : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getCertificateNoLenAsBin( ) : ByteArray? { + + return this.certificateNoLen + } + + + + fun getCertificateNoLenAsStr( ) : String? { + + if( null == this.certificateNoLen ) return null; + return String(certificateNoLen!!) + } + + + + fun getCertificateNoLenAsHex( ) : String? { + + if( null == this.certificateNoLen ) return null; + return Util.bytes2HexString(certificateNoLen) + } + + + + fun setCertificateNoLen( bytes : ByteArray ) : Data { + + this.certificateNoLen = bytes + return this + } + + + + fun getCertificateNoAsBin( ) : ByteArray? { + + return this.certificateNo + } + + + + fun getCertificateNoAsStr( ) : String? { + + if( null == this.certificateNo ) return null; + return String(certificateNo!!) + } + + + + fun getCertificateNoAsHex( ) : String? { + + if( null == this.certificateNo ) return null; + return Util.bytes2HexString(certificateNo) + } + + + + fun setCertificateNo( bytes : ByteArray ) : Data { + + this.certificateNo = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getSignatureLenAsBin( ) : ByteArray? { + + return this.signatureLen + } + + + + fun getSignatureLenAsStr( ) : String? { + + if( null == this.signatureLen ) return null; + return String(signatureLen!!) + } + + + + fun getSignatureLenAsHex( ) : String? { + + if( null == this.signatureLen ) return null; + return Util.bytes2HexString(signatureLen) + } + + + + fun setSignatureLen( bytes : ByteArray ) : Data { + + this.signatureLen = bytes + return this + } + + + + fun getSignatureAsBin( ) : ByteArray? { + + return this.signature + } + + + + fun getSignatureAsStr( ) : String? { + + if( null == this.signature ) return null; + return String(signature!!) + } + + + + fun getSignatureAsHex( ) : String? { + + if( null == this.signature ) return null; + return Util.bytes2HexString(signature) + } + + + + fun setSignature( bytes : ByteArray ) : Data { + + this.signature = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != certificateNoLen ){ + + + soup.put("certificateNoLen", this.certificateNoLen!!) + } + +if( null != certificateNo ){ + + + soup.put("certificateNo", this.certificateNo!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + +if( null != signatureLen ){ + + + soup.put("signatureLen", this.signatureLen!!) + } + +if( null != signature ){ + + + soup.put("signature", this.signature!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("certificateNoLen") ){ + + + this.certificateNoLen = (soup.get("certificateNoLen") as PacketSection).bytes +} + + +if( soup.containsKey("certificateNo") ){ + + + this.certificateNo = (soup.get("certificateNo") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + +if( soup.containsKey("signatureLen") ){ + + + this.signatureLen = (soup.get("signatureLen") as PacketSection).bytes +} + + +if( soup.containsKey("signature") ){ + + + this.signature = (soup.get("signature") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3831")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3831") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的签名标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV信息长度错(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的签名标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "信息长度错" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3832")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3832") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO82.kt b/src/main/java/racal/sunyard/main/dto/DTO82.kt new file mode 100644 index 0000000..5b60a9f --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO82.kt @@ -0,0 +1,1133 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO82 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var key_Length : ByteArray? = null + private var key : ByteArray? = null + private var hashType : ByteArray? = null + private var contextInfo_Len : ByteArray? = null + private var contextInfo : ByteArray? = null + private var infoData_Len : ByteArray? = null + private var infoData : ByteArray? = null + + + fun getKey_LengthAsBin( ) : ByteArray? { + + return this.key_Length + } + + + + fun getKey_LengthAsStr( ) : String? { + + if( null == this.key_Length ) return null; + return String(key_Length!!) + } + + + + fun getKey_LengthAsHex( ) : String? { + + if( null == this.key_Length ) return null; + return Util.bytes2HexString(key_Length) + } + + + + fun setKey_Length( bytes : ByteArray ) : Data { + + this.key_Length = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getHashTypeAsBin( ) : ByteArray? { + + return this.hashType + } + + + + fun getHashTypeAsStr( ) : String? { + + if( null == this.hashType ) return null; + return String(hashType!!) + } + + + + fun getHashTypeAsHex( ) : String? { + + if( null == this.hashType ) return null; + return Util.bytes2HexString(hashType) + } + + + + fun setHashType( bytes : ByteArray ) : Data { + + this.hashType = bytes + return this + } + + + enum class HashTypeOptions( val bin : ByteArray ) { + +OPVSHA1(Util.hexString2Bytes("31")), +OPVSHA256(Util.hexString2Bytes("32")), +OPVSHA384(Util.hexString2Bytes("33")), +OPVSHA512(Util.hexString2Bytes("34")), +OPVSM3(Util.hexString2Bytes("35")), + } + + fun getHashTypeCn( ) : String? { + + if( null == hashType ) { return null } + +if( "31".equals(Util.bytes2HexString(this.hashType) ) ) { + + return "SHA1" + +} + + +if( "32".equals(Util.bytes2HexString(this.hashType) ) ) { + + return "SHA256" + +} + + +if( "33".equals(Util.bytes2HexString(this.hashType) ) ) { + + return "SHA384" + +} + + +if( "34".equals(Util.bytes2HexString(this.hashType) ) ) { + + return "SHA512" + +} + + +if( "35".equals(Util.bytes2HexString(this.hashType) ) ) { + + return "SM3" + +} + + return null + } + + + + fun getHashTypeOptionIndex( ) : Int? { + + if( null == hashType ) { return null } + +if( "31".equals(Util.bytes2HexString(this.hashType) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.hashType) ) ) { + + return 1 + +} + + +if( "33".equals(Util.bytes2HexString(this.hashType) ) ) { + + return 2 + +} + + +if( "34".equals(Util.bytes2HexString(this.hashType) ) ) { + + return 3 + +} + + +if( "35".equals(Util.bytes2HexString(this.hashType) ) ) { + + return 4 + +} + + return null + } + + + + fun getContextInfo_LenAsBin( ) : ByteArray? { + + return this.contextInfo_Len + } + + + + fun getContextInfo_LenAsStr( ) : String? { + + if( null == this.contextInfo_Len ) return null; + return String(contextInfo_Len!!) + } + + + + fun getContextInfo_LenAsHex( ) : String? { + + if( null == this.contextInfo_Len ) return null; + return Util.bytes2HexString(contextInfo_Len) + } + + + + fun setContextInfo_Len( bytes : ByteArray ) : Data { + + this.contextInfo_Len = bytes + return this + } + + + + fun getContextInfoAsBin( ) : ByteArray? { + + return this.contextInfo + } + + + + fun getContextInfoAsStr( ) : String? { + + if( null == this.contextInfo ) return null; + return String(contextInfo!!) + } + + + + fun getContextInfoAsHex( ) : String? { + + if( null == this.contextInfo ) return null; + return Util.bytes2HexString(contextInfo) + } + + + + fun setContextInfo( bytes : ByteArray ) : Data { + + this.contextInfo = bytes + return this + } + + + + fun getInfoData_LenAsBin( ) : ByteArray? { + + return this.infoData_Len + } + + + + fun getInfoData_LenAsStr( ) : String? { + + if( null == this.infoData_Len ) return null; + return String(infoData_Len!!) + } + + + + fun getInfoData_LenAsHex( ) : String? { + + if( null == this.infoData_Len ) return null; + return Util.bytes2HexString(infoData_Len) + } + + + + fun setInfoData_Len( bytes : ByteArray ) : Data { + + this.infoData_Len = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != key_Length ){ + + + soup.put("key_Length", this.key_Length!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != hashType ){ + + + soup.put("hashType", this.hashType!!) + soup.put("hashType\$option", getHashTypeOptionIndex()!!) + } + +if( null != contextInfo_Len ){ + + + soup.put("contextInfo_Len", this.contextInfo_Len!!) + } + +if( null != contextInfo ){ + + + soup.put("contextInfo", this.contextInfo!!) + } + +if( null != infoData_Len ){ + + + soup.put("infoData_Len", this.infoData_Len!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("key_Length") ){ + + + this.key_Length = (soup.get("key_Length") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("hashType") ){ + + + this.hashType = (soup.get("hashType") as PacketSection).bytes +} + + +if( soup.containsKey("contextInfo_Len") ){ + + + this.contextInfo_Len = (soup.get("contextInfo_Len") as PacketSection).bytes +} + + +if( soup.containsKey("contextInfo") ){ + + + this.contextInfo = (soup.get("contextInfo") as PacketSection).bytes +} + + +if( soup.containsKey("infoData_Len") ){ + + + this.infoData_Len = (soup.get("infoData_Len") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3832")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3832") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var contextInfo_Length : ByteArray? = null + private var contextInfo : ByteArray? = null + private var hMAC_LEN : ByteArray? = null + private var hAMC : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV数据长度错(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + return null + } + + + + fun getContextInfo_LengthAsBin( ) : ByteArray? { + + return this.contextInfo_Length + } + + + + fun getContextInfo_LengthAsStr( ) : String? { + + if( null == this.contextInfo_Length ) return null; + return String(contextInfo_Length!!) + } + + + + fun getContextInfo_LengthAsHex( ) : String? { + + if( null == this.contextInfo_Length ) return null; + return Util.bytes2HexString(contextInfo_Length) + } + + + + fun setContextInfo_Length( bytes : ByteArray ) : Data { + + this.contextInfo_Length = bytes + return this + } + + + + fun getContextInfoAsBin( ) : ByteArray? { + + return this.contextInfo + } + + + + fun getContextInfoAsStr( ) : String? { + + if( null == this.contextInfo ) return null; + return String(contextInfo!!) + } + + + + fun getContextInfoAsHex( ) : String? { + + if( null == this.contextInfo ) return null; + return Util.bytes2HexString(contextInfo) + } + + + + fun setContextInfo( bytes : ByteArray ) : Data { + + this.contextInfo = bytes + return this + } + + + + fun getHMAC_LENAsBin( ) : ByteArray? { + + return this.hMAC_LEN + } + + + + fun getHMAC_LENAsStr( ) : String? { + + if( null == this.hMAC_LEN ) return null; + return String(hMAC_LEN!!) + } + + + + fun getHMAC_LENAsHex( ) : String? { + + if( null == this.hMAC_LEN ) return null; + return Util.bytes2HexString(hMAC_LEN) + } + + + + fun setHMAC_LEN( bytes : ByteArray ) : Data { + + this.hMAC_LEN = bytes + return this + } + + + + fun getHAMCAsBin( ) : ByteArray? { + + return this.hAMC + } + + + + fun getHAMCAsStr( ) : String? { + + if( null == this.hAMC ) return null; + return String(hAMC!!) + } + + + + fun getHAMCAsHex( ) : String? { + + if( null == this.hAMC ) return null; + return Util.bytes2HexString(hAMC) + } + + + + fun setHAMC( bytes : ByteArray ) : Data { + + this.hAMC = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != contextInfo_Length ){ + + + soup.put("contextInfo_Length", this.contextInfo_Length!!) + } + +if( null != contextInfo ){ + + + soup.put("contextInfo", this.contextInfo!!) + } + +if( null != hMAC_LEN ){ + + + soup.put("HMAC_LEN", this.hMAC_LEN!!) + } + +if( null != hAMC ){ + + + soup.put("HAMC", this.hAMC!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("contextInfo_Length") ){ + + + this.contextInfo_Length = (soup.get("contextInfo_Length") as PacketSection).bytes +} + + +if( soup.containsKey("contextInfo") ){ + + + this.contextInfo = (soup.get("contextInfo") as PacketSection).bytes +} + + +if( soup.containsKey("HMAC_LEN") ){ + + + this.hMAC_LEN = (soup.get("HMAC_LEN") as PacketSection).bytes +} + + +if( soup.containsKey("HAMC") ){ + + + this.hAMC = (soup.get("HAMC") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3833")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3833") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO83.kt b/src/main/java/racal/sunyard/main/dto/DTO83.kt new file mode 100644 index 0000000..e4c9688 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO83.kt @@ -0,0 +1,1293 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO83 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var cardType : ByteArray? = null + private var algorithmType : ByteArray? = null + private var pattern : ByteArray? = null + private var keyType : ByteArray? = null + private var key : ByteArray? = null + private var cardDispersionFactor : ByteArray? = null + private var aTC : ByteArray? = null + private var aRQC : ByteArray? = null + private var messageLength : ByteArray? = null + private var message : ByteArray? = null + private var aRC : ByteArray? = null + + + fun getCardTypeAsBin( ) : ByteArray? { + + return this.cardType + } + + + + fun getCardTypeAsStr( ) : String? { + + if( null == this.cardType ) return null; + return String(cardType!!) + } + + + + fun getCardTypeAsHex( ) : String? { + + if( null == this.cardType ) return null; + return Util.bytes2HexString(cardType) + } + + + + fun setCardType( bytes : ByteArray ) : Data { + + this.cardType = bytes + return this + } + + + enum class CardTypeOptions( val bin : ByteArray ) { + +OPVVisa(Util.hexString2Bytes("30")), +OPVMaster(Util.hexString2Bytes("31")), +OPVPBOC(Util.hexString2Bytes("32")), + } + + fun getCardTypeCn( ) : String? { + + if( null == cardType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.cardType) ) ) { + + return "Visa" + +} + + +if( "31".equals(Util.bytes2HexString(this.cardType) ) ) { + + return "Master" + +} + + +if( "32".equals(Util.bytes2HexString(this.cardType) ) ) { + + return "PBOC" + +} + + return null + } + + + + fun getCardTypeOptionIndex( ) : Int? { + + if( null == cardType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.cardType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.cardType) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.cardType) ) ) { + + return 2 + +} + + return null + } + + + + fun getAlgorithmTypeAsBin( ) : ByteArray? { + + return this.algorithmType + } + + + + fun getAlgorithmTypeAsStr( ) : String? { + + if( null == this.algorithmType ) return null; + return String(algorithmType!!) + } + + + + fun getAlgorithmTypeAsHex( ) : String? { + + if( null == this.algorithmType ) return null; + return Util.bytes2HexString(algorithmType) + } + + + + fun setAlgorithmType( bytes : ByteArray ) : Data { + + this.algorithmType = bytes + return this + } + + + enum class AlgorithmTypeOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("30")), +OPVSM4(Util.hexString2Bytes("31")), + } + + fun getAlgorithmTypeCn( ) : String? { + + if( null == algorithmType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.algorithmType) ) ) { + + return "3DES" + +} + + +if( "31".equals(Util.bytes2HexString(this.algorithmType) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getAlgorithmTypeOptionIndex( ) : Int? { + + if( null == algorithmType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.algorithmType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.algorithmType) ) ) { + + return 1 + +} + + return null + } + + + + fun getPatternAsBin( ) : ByteArray? { + + return this.pattern + } + + + + fun getPatternAsStr( ) : String? { + + if( null == this.pattern ) return null; + return String(pattern!!) + } + + + + fun getPatternAsHex( ) : String? { + + if( null == this.pattern ) return null; + return Util.bytes2HexString(pattern) + } + + + + fun setPattern( bytes : ByteArray ) : Data { + + this.pattern = bytes + return this + } + + + enum class PatternOptions( val bin : ByteArray ) { + +OPV只验证ARQC(Util.hexString2Bytes("30")), +OPV验证ARQC验证成功后生成ARPC(Util.hexString2Bytes("31")), +OPV只产生ARPC(Util.hexString2Bytes("32")), + } + + fun getPatternCn( ) : String? { + + if( null == pattern ) { return null } + +if( "30".equals(Util.bytes2HexString(this.pattern) ) ) { + + return "只验证ARQC" + +} + + +if( "31".equals(Util.bytes2HexString(this.pattern) ) ) { + + return "验证ARQC,验证成功后生成 ARPC" + +} + + +if( "32".equals(Util.bytes2HexString(this.pattern) ) ) { + + return "只产生ARPC" + +} + + return null + } + + + + fun getPatternOptionIndex( ) : Int? { + + if( null == pattern ) { return null } + +if( "30".equals(Util.bytes2HexString(this.pattern) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.pattern) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.pattern) ) ) { + + return 2 + +} + + return null + } + + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getCardDispersionFactorAsBin( ) : ByteArray? { + + return this.cardDispersionFactor + } + + + + fun getCardDispersionFactorAsStr( ) : String? { + + if( null == this.cardDispersionFactor ) return null; + return String(cardDispersionFactor!!) + } + + + + fun getCardDispersionFactorAsHex( ) : String? { + + if( null == this.cardDispersionFactor ) return null; + return Util.bytes2HexString(cardDispersionFactor) + } + + + + fun setCardDispersionFactor( bytes : ByteArray ) : Data { + + this.cardDispersionFactor = bytes + return this + } + + + + fun getATCAsBin( ) : ByteArray? { + + return this.aTC + } + + + + fun getATCAsStr( ) : String? { + + if( null == this.aTC ) return null; + return String(aTC!!) + } + + + + fun getATCAsHex( ) : String? { + + if( null == this.aTC ) return null; + return Util.bytes2HexString(aTC) + } + + + + fun setATC( bytes : ByteArray ) : Data { + + this.aTC = bytes + return this + } + + + + fun getARQCAsBin( ) : ByteArray? { + + return this.aRQC + } + + + + fun getARQCAsStr( ) : String? { + + if( null == this.aRQC ) return null; + return String(aRQC!!) + } + + + + fun getARQCAsHex( ) : String? { + + if( null == this.aRQC ) return null; + return Util.bytes2HexString(aRQC) + } + + + + fun setARQC( bytes : ByteArray ) : Data { + + this.aRQC = bytes + return this + } + + + + fun getMessageLengthAsBin( ) : ByteArray? { + + return this.messageLength + } + + + + fun getMessageLengthAsStr( ) : String? { + + if( null == this.messageLength ) return null; + return String(messageLength!!) + } + + + + fun getMessageLengthAsHex( ) : String? { + + if( null == this.messageLength ) return null; + return Util.bytes2HexString(messageLength) + } + + + + fun setMessageLength( bytes : ByteArray ) : Data { + + this.messageLength = bytes + return this + } + + + + fun getMessageAsBin( ) : ByteArray? { + + return this.message + } + + + + fun getMessageAsStr( ) : String? { + + if( null == this.message ) return null; + return String(message!!) + } + + + + fun getMessageAsHex( ) : String? { + + if( null == this.message ) return null; + return Util.bytes2HexString(message) + } + + + + fun setMessage( bytes : ByteArray ) : Data { + + this.message = bytes + return this + } + + + + fun getARCAsBin( ) : ByteArray? { + + return this.aRC + } + + + + fun getARCAsStr( ) : String? { + + if( null == this.aRC ) return null; + return String(aRC!!) + } + + + + fun getARCAsHex( ) : String? { + + if( null == this.aRC ) return null; + return Util.bytes2HexString(aRC) + } + + + + fun setARC( bytes : ByteArray ) : Data { + + this.aRC = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != cardType ){ + + + soup.put("cardType", this.cardType!!) + soup.put("cardType\$option", getCardTypeOptionIndex()!!) + } + +if( null != algorithmType ){ + + + soup.put("AlgorithmType", this.algorithmType!!) + soup.put("AlgorithmType\$option", getAlgorithmTypeOptionIndex()!!) + } + +if( null != pattern ){ + + + soup.put("pattern", this.pattern!!) + soup.put("pattern\$option", getPatternOptionIndex()!!) + } + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != cardDispersionFactor ){ + + + soup.put("cardDispersionFactor", this.cardDispersionFactor!!) + } + +if( null != aTC ){ + + + soup.put("ATC", this.aTC!!) + } + +if( null != aRQC ){ + + + soup.put("ARQC", this.aRQC!!) + } + +if( null != messageLength ){ + + + soup.put("messageLength", this.messageLength!!) + } + +if( null != message ){ + + + soup.put("message", this.message!!) + } + +if( null != aRC ){ + + + soup.put("ARC", this.aRC!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("cardType") ){ + + + this.cardType = (soup.get("cardType") as PacketSection).bytes +} + + +if( soup.containsKey("AlgorithmType") ){ + + + this.algorithmType = (soup.get("AlgorithmType") as PacketSection).bytes +} + + +if( soup.containsKey("pattern") ){ + + + this.pattern = (soup.get("pattern") as PacketSection).bytes +} + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("cardDispersionFactor") ){ + + + this.cardDispersionFactor = (soup.get("cardDispersionFactor") as PacketSection).bytes +} + + +if( soup.containsKey("ATC") ){ + + + this.aTC = (soup.get("ATC") as PacketSection).bytes +} + + +if( soup.containsKey("ARQC") ){ + + + this.aRQC = (soup.get("ARQC") as PacketSection).bytes +} + + +if( soup.containsKey("messageLength") ){ + + + this.messageLength = (soup.get("messageLength") as PacketSection).bytes +} + + +if( soup.containsKey("message") ){ + + + this.message = (soup.get("message") as PacketSection).bytes +} + + +if( soup.containsKey("ARC") ){ + + + this.aRC = (soup.get("ARC") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3833")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3833") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var aPRC : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVARQC校验失败(Util.hexString2Bytes("3037")), +OPVLMK运算错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV数据长度错(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "ARQC校验失败" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK运算错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + return null + } + + + + fun getAPRCAsBin( ) : ByteArray? { + + return this.aPRC + } + + + + fun getAPRCAsStr( ) : String? { + + if( null == this.aPRC ) return null; + return String(aPRC!!) + } + + + + fun getAPRCAsHex( ) : String? { + + if( null == this.aPRC ) return null; + return Util.bytes2HexString(aPRC) + } + + + + fun setAPRC( bytes : ByteArray ) : Data { + + this.aPRC = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != aPRC ){ + + + soup.put("APRC", this.aPRC!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("APRC") ){ + + + this.aPRC = (soup.get("APRC") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3834")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3834") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO93.kt b/src/main/java/racal/sunyard/main/dto/DTO93.kt new file mode 100644 index 0000000..0c81a3e --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO93.kt @@ -0,0 +1,1053 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO93 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var privateKeyLength : ByteArray? = null + private var privateKey : ByteArray? = null + private var publicKeyLength : ByteArray? = null + private var publicKey : ByteArray? = null + private var dataLength : ByteArray? = null + private var data : ByteArray? = null + + + fun getPrivateKeyLengthAsBin( ) : ByteArray? { + + return this.privateKeyLength + } + + + + fun getPrivateKeyLengthAsStr( ) : String? { + + if( null == this.privateKeyLength ) return null; + return String(privateKeyLength!!) + } + + + + fun getPrivateKeyLengthAsHex( ) : String? { + + if( null == this.privateKeyLength ) return null; + return Util.bytes2HexString(privateKeyLength) + } + + + + fun setPrivateKeyLength( bytes : ByteArray ) : Data { + + this.privateKeyLength = bytes + return this + } + + + + fun getPrivateKeyAsBin( ) : ByteArray? { + + return this.privateKey + } + + + + fun getPrivateKeyAsStr( ) : String? { + + if( null == this.privateKey ) return null; + return String(privateKey!!) + } + + + + fun getPrivateKeyAsHex( ) : String? { + + if( null == this.privateKey ) return null; + return Util.bytes2HexString(privateKey) + } + + + + fun setPrivateKey( bytes : ByteArray ) : Data { + + this.privateKey = bytes + return this + } + + + + fun getPublicKeyLengthAsBin( ) : ByteArray? { + + return this.publicKeyLength + } + + + + fun getPublicKeyLengthAsStr( ) : String? { + + if( null == this.publicKeyLength ) return null; + return String(publicKeyLength!!) + } + + + + fun getPublicKeyLengthAsHex( ) : String? { + + if( null == this.publicKeyLength ) return null; + return Util.bytes2HexString(publicKeyLength) + } + + + + fun setPublicKeyLength( bytes : ByteArray ) : Data { + + this.publicKeyLength = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getDataAsBin( ) : ByteArray? { + + return this.data + } + + + + fun getDataAsStr( ) : String? { + + if( null == this.data ) return null; + return String(data!!) + } + + + + fun getDataAsHex( ) : String? { + + if( null == this.data ) return null; + return Util.bytes2HexString(data) + } + + + + fun setData( bytes : ByteArray ) : Data { + + this.data = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != privateKeyLength ){ + + + soup.put("privateKeyLength", this.privateKeyLength!!) + } + +if( null != privateKey ){ + + + soup.put("privateKey", this.privateKey!!) + } + +if( null != publicKeyLength ){ + + + soup.put("publicKeyLength", this.publicKeyLength!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != data ){ + + + soup.put("data", this.data!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("privateKeyLength") ){ + + + this.privateKeyLength = (soup.get("privateKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("privateKey") ){ + + + this.privateKey = (soup.get("privateKey") as PacketSection).bytes +} + + +if( soup.containsKey("publicKeyLength") ){ + + + this.publicKeyLength = (soup.get("publicKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + + + this.data = (soup.get("data") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3933")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3933") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var dev : ByteArray? = null + private var signLength : ByteArray? = null + private var sign : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的签名标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV信息长度错(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的签名标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "信息长度错" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getDevAsBin( ) : ByteArray? { + + return this.dev + } + + + + fun getDevAsStr( ) : String? { + + if( null == this.dev ) return null; + return String(dev!!) + } + + + + fun getDevAsHex( ) : String? { + + if( null == this.dev ) return null; + return Util.bytes2HexString(dev) + } + + + + fun setDev( bytes : ByteArray ) : Data { + + this.dev = bytes + return this + } + + + + fun getSignLengthAsBin( ) : ByteArray? { + + return this.signLength + } + + + + fun getSignLengthAsStr( ) : String? { + + if( null == this.signLength ) return null; + return String(signLength!!) + } + + + + fun getSignLengthAsHex( ) : String? { + + if( null == this.signLength ) return null; + return Util.bytes2HexString(signLength) + } + + + + fun setSignLength( bytes : ByteArray ) : Data { + + this.signLength = bytes + return this + } + + + + fun getSignAsBin( ) : ByteArray? { + + return this.sign + } + + + + fun getSignAsStr( ) : String? { + + if( null == this.sign ) return null; + return String(sign!!) + } + + + + fun getSignAsHex( ) : String? { + + if( null == this.sign ) return null; + return Util.bytes2HexString(sign) + } + + + + fun setSign( bytes : ByteArray ) : Data { + + this.sign = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != dev ){ + + + soup.put("dev", this.dev!!) + } + +if( null != signLength ){ + + + soup.put("signLength", this.signLength!!) + } + +if( null != sign ){ + + + soup.put("sign", this.sign!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("dev") ){ + + + this.dev = (soup.get("dev") as PacketSection).bytes +} + + +if( soup.containsKey("signLength") ){ + + + this.signLength = (soup.get("signLength") as PacketSection).bytes +} + + +if( soup.containsKey("sign") ){ + + + this.sign = (soup.get("sign") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3934")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3934") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO94.kt b/src/main/java/racal/sunyard/main/dto/DTO94.kt new file mode 100644 index 0000000..b0dc8bd --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO94.kt @@ -0,0 +1,1098 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO94 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var pkLen : ByteArray? = null + private var pk : ByteArray? = null + private var infoLen : ByteArray? = null + private var info : ByteArray? = null + private var sln : ByteArray? = null + + + fun getPkLenAsBin( ) : ByteArray? { + + return this.pkLen + } + + + + fun getPkLenAsStr( ) : String? { + + if( null == this.pkLen ) return null; + return String(pkLen!!) + } + + + + fun getPkLenAsHex( ) : String? { + + if( null == this.pkLen ) return null; + return Util.bytes2HexString(pkLen) + } + + + + fun setPkLen( bytes : ByteArray ) : Data { + + this.pkLen = bytes + return this + } + + + + fun getPkAsBin( ) : ByteArray? { + + return this.pk + } + + + + fun getPkAsStr( ) : String? { + + if( null == this.pk ) return null; + return String(pk!!) + } + + + + fun getPkAsHex( ) : String? { + + if( null == this.pk ) return null; + return Util.bytes2HexString(pk) + } + + + + fun setPk( bytes : ByteArray ) : Data { + + this.pk = bytes + return this + } + + + + fun getInfoLenAsBin( ) : ByteArray? { + + return this.infoLen + } + + + + fun getInfoLenAsStr( ) : String? { + + if( null == this.infoLen ) return null; + return String(infoLen!!) + } + + + + fun getInfoLenAsHex( ) : String? { + + if( null == this.infoLen ) return null; + return Util.bytes2HexString(infoLen) + } + + + + fun setInfoLen( bytes : ByteArray ) : Data { + + this.infoLen = bytes + return this + } + + + + fun getInfoAsBin( ) : ByteArray? { + + return this.info + } + + + + fun getInfoAsStr( ) : String? { + + if( null == this.info ) return null; + return String(info!!) + } + + + + fun getInfoAsHex( ) : String? { + + if( null == this.info ) return null; + return Util.bytes2HexString(info) + } + + + + fun setInfo( bytes : ByteArray ) : Data { + + this.info = bytes + return this + } + + + + fun getSlnAsBin( ) : ByteArray? { + + return this.sln + } + + + + fun getSlnAsStr( ) : String? { + + if( null == this.sln ) return null; + return String(sln!!) + } + + + + fun getSlnAsHex( ) : String? { + + if( null == this.sln ) return null; + return Util.bytes2HexString(sln) + } + + + + fun setSln( bytes : ByteArray ) : Data { + + this.sln = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != pkLen ){ + + + soup.put("pkLen", this.pkLen!!) + } + +if( null != pk ){ + + + soup.put("pk", this.pk!!) + } + +if( null != infoLen ){ + + + soup.put("infoLen", this.infoLen!!) + } + +if( null != info ){ + + + soup.put("info", this.info!!) + } + +if( null != sln ){ + + + soup.put("sln", this.sln!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("pkLen") ){ + + + this.pkLen = (soup.get("pkLen") as PacketSection).bytes +} + + +if( soup.containsKey("pk") ){ + + + this.pk = (soup.get("pk") as PacketSection).bytes +} + + +if( soup.containsKey("infoLen") ){ + + + this.infoLen = (soup.get("infoLen") as PacketSection).bytes +} + + +if( soup.containsKey("info") ){ + + + this.info = (soup.get("info") as PacketSection).bytes +} + + +if( soup.containsKey("sln") ){ + + + this.sln = (soup.get("sln") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3934")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3934") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var keyLength : ByteArray? = null + private var key : ByteArray? = null + private var takLmkHead : ByteArray? = null + private var takLmk : ByteArray? = null + private var keyCheck : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的签名标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV信息长度错(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的签名标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "信息长度错" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getKeyLengthAsBin( ) : ByteArray? { + + return this.keyLength + } + + + + fun getKeyLengthAsStr( ) : String? { + + if( null == this.keyLength ) return null; + return String(keyLength!!) + } + + + + fun getKeyLengthAsHex( ) : String? { + + if( null == this.keyLength ) return null; + return Util.bytes2HexString(keyLength) + } + + + + fun setKeyLength( bytes : ByteArray ) : Data { + + this.keyLength = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getTakLmkHeadAsBin( ) : ByteArray? { + + return this.takLmkHead + } + + + + fun getTakLmkHeadAsStr( ) : String? { + + if( null == this.takLmkHead ) return null; + return String(takLmkHead!!) + } + + + + fun getTakLmkHeadAsHex( ) : String? { + + if( null == this.takLmkHead ) return null; + return Util.bytes2HexString(takLmkHead) + } + + + + fun setTakLmkHead( bytes : ByteArray ) : Data { + + this.takLmkHead = bytes + return this + } + + + + fun getTakLmkAsBin( ) : ByteArray? { + + return this.takLmk + } + + + + fun getTakLmkAsStr( ) : String? { + + if( null == this.takLmk ) return null; + return String(takLmk!!) + } + + + + fun getTakLmkAsHex( ) : String? { + + if( null == this.takLmk ) return null; + return Util.bytes2HexString(takLmk) + } + + + + fun setTakLmk( bytes : ByteArray ) : Data { + + this.takLmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != keyLength ){ + + + soup.put("keyLength", this.keyLength!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != takLmkHead ){ + + + soup.put("takLmkHead", this.takLmkHead!!) + } + +if( null != takLmk ){ + + + soup.put("takLmk", this.takLmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("keyLength") ){ + + + this.keyLength = (soup.get("keyLength") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("takLmkHead") ){ + + + this.takLmkHead = (soup.get("takLmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("takLmk") ){ + + + this.takLmk = (soup.get("takLmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3935")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3935") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO95.kt b/src/main/java/racal/sunyard/main/dto/DTO95.kt new file mode 100644 index 0000000..a7d344e --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO95.kt @@ -0,0 +1,1190 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO95 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var privateKeyLength : ByteArray? = null + private var privateKey : ByteArray? = null + private var keyLength : ByteArray? = null + private var key : ByteArray? = null + private var sln : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getPrivateKeyLengthAsBin( ) : ByteArray? { + + return this.privateKeyLength + } + + + + fun getPrivateKeyLengthAsStr( ) : String? { + + if( null == this.privateKeyLength ) return null; + return String(privateKeyLength!!) + } + + + + fun getPrivateKeyLengthAsHex( ) : String? { + + if( null == this.privateKeyLength ) return null; + return Util.bytes2HexString(privateKeyLength) + } + + + + fun setPrivateKeyLength( bytes : ByteArray ) : Data { + + this.privateKeyLength = bytes + return this + } + + + + fun getPrivateKeyAsBin( ) : ByteArray? { + + return this.privateKey + } + + + + fun getPrivateKeyAsStr( ) : String? { + + if( null == this.privateKey ) return null; + return String(privateKey!!) + } + + + + fun getPrivateKeyAsHex( ) : String? { + + if( null == this.privateKey ) return null; + return Util.bytes2HexString(privateKey) + } + + + + fun setPrivateKey( bytes : ByteArray ) : Data { + + this.privateKey = bytes + return this + } + + + + fun getKeyLengthAsBin( ) : ByteArray? { + + return this.keyLength + } + + + + fun getKeyLengthAsStr( ) : String? { + + if( null == this.keyLength ) return null; + return String(keyLength!!) + } + + + + fun getKeyLengthAsHex( ) : String? { + + if( null == this.keyLength ) return null; + return Util.bytes2HexString(keyLength) + } + + + + fun setKeyLength( bytes : ByteArray ) : Data { + + this.keyLength = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getSlnAsBin( ) : ByteArray? { + + return this.sln + } + + + + fun getSlnAsStr( ) : String? { + + if( null == this.sln ) return null; + return String(sln!!) + } + + + + fun getSlnAsHex( ) : String? { + + if( null == this.sln ) return null; + return Util.bytes2HexString(sln) + } + + + + fun setSln( bytes : ByteArray ) : Data { + + this.sln = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != privateKeyLength ){ + + + soup.put("privateKeyLength", this.privateKeyLength!!) + } + +if( null != privateKey ){ + + + soup.put("privateKey", this.privateKey!!) + } + +if( null != keyLength ){ + + + soup.put("keyLength", this.keyLength!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != sln ){ + + + soup.put("sln", this.sln!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("privateKeyLength") ){ + + + this.privateKeyLength = (soup.get("privateKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("privateKey") ){ + + + this.privateKey = (soup.get("privateKey") as PacketSection).bytes +} + + +if( soup.containsKey("keyLength") ){ + + + this.keyLength = (soup.get("keyLength") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("sln") ){ + + + this.sln = (soup.get("sln") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3935")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3935") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var lmkHead : ByteArray? = null + private var lmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var infoLen : ByteArray? = null + private var info : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getLmkHeadAsBin( ) : ByteArray? { + + return this.lmkHead + } + + + + fun getLmkHeadAsStr( ) : String? { + + if( null == this.lmkHead ) return null; + return String(lmkHead!!) + } + + + + fun getLmkHeadAsHex( ) : String? { + + if( null == this.lmkHead ) return null; + return Util.bytes2HexString(lmkHead) + } + + + + fun setLmkHead( bytes : ByteArray ) : Data { + + this.lmkHead = bytes + return this + } + + + + fun getLmkAsBin( ) : ByteArray? { + + return this.lmk + } + + + + fun getLmkAsStr( ) : String? { + + if( null == this.lmk ) return null; + return String(lmk!!) + } + + + + fun getLmkAsHex( ) : String? { + + if( null == this.lmk ) return null; + return Util.bytes2HexString(lmk) + } + + + + fun setLmk( bytes : ByteArray ) : Data { + + this.lmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getInfoLenAsBin( ) : ByteArray? { + + return this.infoLen + } + + + + fun getInfoLenAsStr( ) : String? { + + if( null == this.infoLen ) return null; + return String(infoLen!!) + } + + + + fun getInfoLenAsHex( ) : String? { + + if( null == this.infoLen ) return null; + return Util.bytes2HexString(infoLen) + } + + + + fun setInfoLen( bytes : ByteArray ) : Data { + + this.infoLen = bytes + return this + } + + + + fun getInfoAsBin( ) : ByteArray? { + + return this.info + } + + + + fun getInfoAsStr( ) : String? { + + if( null == this.info ) return null; + return String(info!!) + } + + + + fun getInfoAsHex( ) : String? { + + if( null == this.info ) return null; + return Util.bytes2HexString(info) + } + + + + fun setInfo( bytes : ByteArray ) : Data { + + this.info = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != lmkHead ){ + + + soup.put("lmkHead", this.lmkHead!!) + } + +if( null != lmk ){ + + + soup.put("lmk", this.lmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + +if( null != infoLen ){ + + + soup.put("infoLen", this.infoLen!!) + } + +if( null != info ){ + + + soup.put("info", this.info!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("lmkHead") ){ + + + this.lmkHead = (soup.get("lmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("lmk") ){ + + + this.lmk = (soup.get("lmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + +if( soup.containsKey("infoLen") ){ + + + this.infoLen = (soup.get("infoLen") as PacketSection).bytes +} + + +if( soup.containsKey("info") ){ + + + this.info = (soup.get("info") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3936")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3936") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTO96.kt b/src/main/java/racal/sunyard/main/dto/DTO96.kt new file mode 100644 index 0000000..d7caa01 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTO96.kt @@ -0,0 +1,1008 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTO96 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var keyA : ByteArray? = null + private var keyB : ByteArray? = null + private var sln : ByteArray? = null + private var alg : ByteArray? = null + + + fun getKeyAAsBin( ) : ByteArray? { + + return this.keyA + } + + + + fun getKeyAAsStr( ) : String? { + + if( null == this.keyA ) return null; + return String(keyA!!) + } + + + + fun getKeyAAsHex( ) : String? { + + if( null == this.keyA ) return null; + return Util.bytes2HexString(keyA) + } + + + + fun setKeyA( bytes : ByteArray ) : Data { + + this.keyA = bytes + return this + } + + + + fun getKeyBAsBin( ) : ByteArray? { + + return this.keyB + } + + + + fun getKeyBAsStr( ) : String? { + + if( null == this.keyB ) return null; + return String(keyB!!) + } + + + + fun getKeyBAsHex( ) : String? { + + if( null == this.keyB ) return null; + return Util.bytes2HexString(keyB) + } + + + + fun setKeyB( bytes : ByteArray ) : Data { + + this.keyB = bytes + return this + } + + + + fun getSlnAsBin( ) : ByteArray? { + + return this.sln + } + + + + fun getSlnAsStr( ) : String? { + + if( null == this.sln ) return null; + return String(sln!!) + } + + + + fun getSlnAsHex( ) : String? { + + if( null == this.sln ) return null; + return Util.bytes2HexString(sln) + } + + + + fun setSln( bytes : ByteArray ) : Data { + + this.sln = bytes + return this + } + + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != keyA ){ + + + soup.put("keyA", this.keyA!!) + } + +if( null != keyB ){ + + + soup.put("keyB", this.keyB!!) + } + +if( null != sln ){ + + + soup.put("sln", this.sln!!) + } + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("keyA") ){ + + + this.keyA = (soup.get("keyA") as PacketSection).bytes +} + + +if( soup.containsKey("keyB") ){ + + + this.keyB = (soup.get("keyB") as PacketSection).bytes +} + + +if( soup.containsKey("sln") ){ + + + this.sln = (soup.get("sln") as PacketSection).bytes +} + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3936")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3936") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var keyC : ByteArray? = null + private var keyCheck : ByteArray? = null + private var infoLen : ByteArray? = null + private var info : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getKeyCAsBin( ) : ByteArray? { + + return this.keyC + } + + + + fun getKeyCAsStr( ) : String? { + + if( null == this.keyC ) return null; + return String(keyC!!) + } + + + + fun getKeyCAsHex( ) : String? { + + if( null == this.keyC ) return null; + return Util.bytes2HexString(keyC) + } + + + + fun setKeyC( bytes : ByteArray ) : Data { + + this.keyC = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getInfoLenAsBin( ) : ByteArray? { + + return this.infoLen + } + + + + fun getInfoLenAsStr( ) : String? { + + if( null == this.infoLen ) return null; + return String(infoLen!!) + } + + + + fun getInfoLenAsHex( ) : String? { + + if( null == this.infoLen ) return null; + return Util.bytes2HexString(infoLen) + } + + + + fun setInfoLen( bytes : ByteArray ) : Data { + + this.infoLen = bytes + return this + } + + + + fun getInfoAsBin( ) : ByteArray? { + + return this.info + } + + + + fun getInfoAsStr( ) : String? { + + if( null == this.info ) return null; + return String(info!!) + } + + + + fun getInfoAsHex( ) : String? { + + if( null == this.info ) return null; + return Util.bytes2HexString(info) + } + + + + fun setInfo( bytes : ByteArray ) : Data { + + this.info = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != keyC ){ + + + soup.put("keyC", this.keyC!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + +if( null != infoLen ){ + + + soup.put("infoLen", this.infoLen!!) + } + +if( null != info ){ + + + soup.put("info", this.info!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("keyC") ){ + + + this.keyC = (soup.get("keyC") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + +if( soup.containsKey("infoLen") ){ + + + this.infoLen = (soup.get("infoLen") as PacketSection).bytes +} + + +if( soup.containsKey("info") ){ + + + this.info = (soup.get("info") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("3937")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("3937") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOA0.kt b/src/main/java/racal/sunyard/main/dto/DTOA0.kt new file mode 100644 index 0000000..3e50af8 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOA0.kt @@ -0,0 +1,1334 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOA0 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var mode : ByteArray? = null + private var keyType : ByteArray? = null + private var solution : ByteArray? = null + private var zmk : ByteArray? = null + private var keySolution : ByteArray? = null + private var businessKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getModeAsBin( ) : ByteArray? { + + return this.mode + } + + + + fun getModeAsStr( ) : String? { + + if( null == this.mode ) return null; + return String(mode!!) + } + + + + fun getModeAsHex( ) : String? { + + if( null == this.mode ) return null; + return Util.bytes2HexString(mode) + } + + + + fun setMode( bytes : ByteArray ) : Data { + + this.mode = bytes + return this + } + + + enum class ModeOptions( val bin : ByteArray ) { + +OPV产生密钥(Util.hexString2Bytes("30")), +OPV产生密钥并在ZMK下加密(Util.hexString2Bytes("31")), + } + + fun getModeCn( ) : String? { + + if( null == mode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.mode) ) ) { + + return "产生密钥" + +} + + +if( "31".equals(Util.bytes2HexString(this.mode) ) ) { + + return "产生密钥并在 ZMK 下加密" + +} + + return null + } + + + + fun getModeOptionIndex( ) : Int? { + + if( null == mode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.mode) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.mode) ) ) { + + return 1 + +} + + return null + } + + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getSolutionAsBin( ) : ByteArray? { + + return this.solution + } + + + + fun getSolutionAsStr( ) : String? { + + if( null == this.solution ) return null; + return String(solution!!) + } + + + + fun getSolutionAsHex( ) : String? { + + if( null == this.solution ) return null; + return Util.bytes2HexString(solution) + } + + + + fun setSolution( bytes : ByteArray ) : Data { + + this.solution = bytes + return this + } + + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getKeySolutionAsBin( ) : ByteArray? { + + return this.keySolution + } + + + + fun getKeySolutionAsStr( ) : String? { + + if( null == this.keySolution ) return null; + return String(keySolution!!) + } + + + + fun getKeySolutionAsHex( ) : String? { + + if( null == this.keySolution ) return null; + return Util.bytes2HexString(keySolution) + } + + + + fun setKeySolution( bytes : ByteArray ) : Data { + + this.keySolution = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != mode ){ + + + soup.put("mode", this.mode!!) + soup.put("mode\$option", getModeOptionIndex()!!) + } + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + +if( null != solution ){ + + + soup.put("solution", this.solution!!) + } + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != keySolution ){ + + + soup.put("keySolution", this.keySolution!!) + } + soup.put("businessKey", Util.hexString2Bytes("4E")) + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("mode") ){ + + + this.mode = (soup.get("mode") as PacketSection).bytes +} + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("solution") ){ + + + this.solution = (soup.get("solution") as PacketSection).bytes +} + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("keySolution") ){ + + + this.keySolution = (soup.get("keySolution") as PacketSection).bytes +} + + this.businessKey = Util.hexString2Bytes("4E") + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4130")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4130") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var lmkHead : ByteArray? = null + private var lmk : ByteArray? = null + private var zmkHead : ByteArray? = null + private var zmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + return null + } + + + + fun getLmkHeadAsBin( ) : ByteArray? { + + return this.lmkHead + } + + + + fun getLmkHeadAsStr( ) : String? { + + if( null == this.lmkHead ) return null; + return String(lmkHead!!) + } + + + + fun getLmkHeadAsHex( ) : String? { + + if( null == this.lmkHead ) return null; + return Util.bytes2HexString(lmkHead) + } + + + + fun setLmkHead( bytes : ByteArray ) : Data { + + this.lmkHead = bytes + return this + } + + + + fun getLmkAsBin( ) : ByteArray? { + + return this.lmk + } + + + + fun getLmkAsStr( ) : String? { + + if( null == this.lmk ) return null; + return String(lmk!!) + } + + + + fun getLmkAsHex( ) : String? { + + if( null == this.lmk ) return null; + return Util.bytes2HexString(lmk) + } + + + + fun setLmk( bytes : ByteArray ) : Data { + + this.lmk = bytes + return this + } + + + + fun getZmkHeadAsBin( ) : ByteArray? { + + return this.zmkHead + } + + + + fun getZmkHeadAsStr( ) : String? { + + if( null == this.zmkHead ) return null; + return String(zmkHead!!) + } + + + + fun getZmkHeadAsHex( ) : String? { + + if( null == this.zmkHead ) return null; + return Util.bytes2HexString(zmkHead) + } + + + + fun setZmkHead( bytes : ByteArray ) : Data { + + this.zmkHead = bytes + return this + } + + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != lmkHead ){ + + + soup.put("lmkHead", this.lmkHead!!) + } + +if( null != lmk ){ + + + soup.put("lmk", this.lmk!!) + } + +if( null != zmkHead ){ + + + soup.put("zmkHead", this.zmkHead!!) + } + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("lmkHead") ){ + + + this.lmkHead = (soup.get("lmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("lmk") ){ + + + this.lmk = (soup.get("lmk") as PacketSection).bytes +} + + +if( soup.containsKey("zmkHead") ){ + + + this.zmkHead = (soup.get("zmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4131")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4131") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOA2.kt b/src/main/java/racal/sunyard/main/dto/DTOA2.kt new file mode 100644 index 0000000..f025f1c --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOA2.kt @@ -0,0 +1,1117 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOA2 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var keyType : ByteArray? = null + private var solution : ByteArray? = null + private var flag : ByteArray? = null + private var print : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getSolutionAsBin( ) : ByteArray? { + + return this.solution + } + + + + fun getSolutionAsStr( ) : String? { + + if( null == this.solution ) return null; + return String(solution!!) + } + + + + fun getSolutionAsHex( ) : String? { + + if( null == this.solution ) return null; + return Util.bytes2HexString(solution) + } + + + + fun setSolution( bytes : ByteArray ) : Data { + + this.solution = bytes + return this + } + + + + fun getFlagAsBin( ) : ByteArray? { + + return this.flag + } + + + + fun getFlagAsStr( ) : String? { + + if( null == this.flag ) return null; + return String(flag!!) + } + + + + fun getFlagAsHex( ) : String? { + + if( null == this.flag ) return null; + return Util.bytes2HexString(flag) + } + + + + fun setFlag( bytes : ByteArray ) : Data { + + this.flag = bytes + return this + } + + + + fun getPrintAsBin( ) : ByteArray? { + + return this.print + } + + + + fun getPrintAsStr( ) : String? { + + if( null == this.print ) return null; + return String(print!!) + } + + + + fun getPrintAsHex( ) : String? { + + if( null == this.print ) return null; + return Util.bytes2HexString(print) + } + + + + fun setPrint( bytes : ByteArray ) : Data { + + this.print = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + +if( null != solution ){ + + + soup.put("solution", this.solution!!) + } + +if( null != flag ){ + + + soup.put("flag", this.flag!!) + } + +if( null != print ){ + + + soup.put("print", this.print!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("solution") ){ + + + this.solution = (soup.get("solution") as PacketSection).bytes +} + + +if( soup.containsKey("flag") ){ + + + this.flag = (soup.get("flag") as PacketSection).bytes +} + + +if( soup.containsKey("print") ){ + + + this.print = (soup.get("print") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4132")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4132") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var keyHead : ByteArray? = null + private var key : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV密钥奇偶校验错(Util.hexString2Bytes("3031")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV无效的密钥类型(Util.hexString2Bytes("3238")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥类型" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getKeyHeadAsBin( ) : ByteArray? { + + return this.keyHead + } + + + + fun getKeyHeadAsStr( ) : String? { + + if( null == this.keyHead ) return null; + return String(keyHead!!) + } + + + + fun getKeyHeadAsHex( ) : String? { + + if( null == this.keyHead ) return null; + return Util.bytes2HexString(keyHead) + } + + + + fun setKeyHead( bytes : ByteArray ) : Data { + + this.keyHead = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != keyHead ){ + + + soup.put("keyHead", this.keyHead!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("keyHead") ){ + + + this.keyHead = (soup.get("keyHead") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4133")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4133") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOA4.kt b/src/main/java/racal/sunyard/main/dto/DTOA4.kt new file mode 100644 index 0000000..d042c11 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOA4.kt @@ -0,0 +1,1192 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOA4 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var num : ByteArray? = null + private var keyType : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keys : ByteArray? = null + private var businessKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getNumAsBin( ) : ByteArray? { + + return this.num + } + + + + fun getNumAsStr( ) : String? { + + if( null == this.num ) return null; + return String(num!!) + } + + + + fun getNumAsHex( ) : String? { + + if( null == this.num ) return null; + return Util.bytes2HexString(num) + } + + + + fun setNum( bytes : ByteArray ) : Data { + + this.num = bytes + return this + } + + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeysAsBin( ) : ByteArray? { + + return this.keys + } + + + + fun getKeysAsStr( ) : String? { + + if( null == this.keys ) return null; + return String(keys!!) + } + + + + fun getKeysAsHex( ) : String? { + + if( null == this.keys ) return null; + return Util.bytes2HexString(keys) + } + + + + fun setKeys( bytes : ByteArray ) : Data { + + this.keys = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != num ){ + + + soup.put("num", this.num!!) + } + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keys ){ + + + soup.put("keys", this.keys!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("num") ){ + + + this.num = (soup.get("num") as PacketSection).bytes +} + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keys") ){ + + + this.keys = (soup.get("keys") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4134")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4134") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var keyHead : ByteArray? = null + private var key : ByteArray? = null + private var kcv : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效的成份号(Util.hexString2Bytes("3033")), +OPV成份奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的成份号" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "成份奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getKeyHeadAsBin( ) : ByteArray? { + + return this.keyHead + } + + + + fun getKeyHeadAsStr( ) : String? { + + if( null == this.keyHead ) return null; + return String(keyHead!!) + } + + + + fun getKeyHeadAsHex( ) : String? { + + if( null == this.keyHead ) return null; + return Util.bytes2HexString(keyHead) + } + + + + fun setKeyHead( bytes : ByteArray ) : Data { + + this.keyHead = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getKcvAsBin( ) : ByteArray? { + + return this.kcv + } + + + + fun getKcvAsStr( ) : String? { + + if( null == this.kcv ) return null; + return String(kcv!!) + } + + + + fun getKcvAsHex( ) : String? { + + if( null == this.kcv ) return null; + return Util.bytes2HexString(kcv) + } + + + + fun setKcv( bytes : ByteArray ) : Data { + + this.kcv = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != keyHead ){ + + + soup.put("keyHead", this.keyHead!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != kcv ){ + + + soup.put("kcv", this.kcv!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("keyHead") ){ + + + this.keyHead = (soup.get("keyHead") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("kcv") ){ + + + this.kcv = (soup.get("kcv") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4135")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4135") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOA6.kt b/src/main/java/racal/sunyard/main/dto/DTOA6.kt new file mode 100644 index 0000000..db470d3 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOA6.kt @@ -0,0 +1,1207 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOA6 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var keyType : ByteArray? = null + private var zmk : ByteArray? = null + private var key : ByteArray? = null + private var keySolution : ByteArray? = null + private var businessKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getKeySolutionAsBin( ) : ByteArray? { + + return this.keySolution + } + + + + fun getKeySolutionAsStr( ) : String? { + + if( null == this.keySolution ) return null; + return String(keySolution!!) + } + + + + fun getKeySolutionAsHex( ) : String? { + + if( null == this.keySolution ) return null; + return Util.bytes2HexString(keySolution) + } + + + + fun setKeySolution( bytes : ByteArray ) : Data { + + this.keySolution = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != keySolution ){ + + + soup.put("keySolution", this.keySolution!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("keySolution") ){ + + + this.keySolution = (soup.get("keySolution") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4136")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4136") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var lmkHead : ByteArray? = null + private var lmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV密钥奇偶校验错(Util.hexString2Bytes("3031")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV无效的密钥类型(Util.hexString2Bytes("3238")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥类型" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getLmkHeadAsBin( ) : ByteArray? { + + return this.lmkHead + } + + + + fun getLmkHeadAsStr( ) : String? { + + if( null == this.lmkHead ) return null; + return String(lmkHead!!) + } + + + + fun getLmkHeadAsHex( ) : String? { + + if( null == this.lmkHead ) return null; + return Util.bytes2HexString(lmkHead) + } + + + + fun setLmkHead( bytes : ByteArray ) : Data { + + this.lmkHead = bytes + return this + } + + + + fun getLmkAsBin( ) : ByteArray? { + + return this.lmk + } + + + + fun getLmkAsStr( ) : String? { + + if( null == this.lmk ) return null; + return String(lmk!!) + } + + + + fun getLmkAsHex( ) : String? { + + if( null == this.lmk ) return null; + return Util.bytes2HexString(lmk) + } + + + + fun setLmk( bytes : ByteArray ) : Data { + + this.lmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != lmkHead ){ + + + soup.put("lmkHead", this.lmkHead!!) + } + +if( null != lmk ){ + + + soup.put("lmk", this.lmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("lmkHead") ){ + + + this.lmkHead = (soup.get("lmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("lmk") ){ + + + this.lmk = (soup.get("lmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4137")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4137") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOA8.kt b/src/main/java/racal/sunyard/main/dto/DTOA8.kt new file mode 100644 index 0000000..44f6723 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOA8.kt @@ -0,0 +1,1192 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOA8 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var keyType : ByteArray? = null + private var zmk : ByteArray? = null + private var key : ByteArray? = null + private var keySolution : ByteArray? = null + private var businessKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getKeySolutionAsBin( ) : ByteArray? { + + return this.keySolution + } + + + + fun getKeySolutionAsStr( ) : String? { + + if( null == this.keySolution ) return null; + return String(keySolution!!) + } + + + + fun getKeySolutionAsHex( ) : String? { + + if( null == this.keySolution ) return null; + return Util.bytes2HexString(keySolution) + } + + + + fun setKeySolution( bytes : ByteArray ) : Data { + + this.keySolution = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != keySolution ){ + + + soup.put("keySolution", this.keySolution!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("keySolution") ){ + + + this.keySolution = (soup.get("keySolution") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4138")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4138") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var zmkHead : ByteArray? = null + private var zmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPV密钥校验错(Util.hexString2Bytes("3131")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getZmkHeadAsBin( ) : ByteArray? { + + return this.zmkHead + } + + + + fun getZmkHeadAsStr( ) : String? { + + if( null == this.zmkHead ) return null; + return String(zmkHead!!) + } + + + + fun getZmkHeadAsHex( ) : String? { + + if( null == this.zmkHead ) return null; + return Util.bytes2HexString(zmkHead) + } + + + + fun setZmkHead( bytes : ByteArray ) : Data { + + this.zmkHead = bytes + return this + } + + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != zmkHead ){ + + + soup.put("zmkHead", this.zmkHead!!) + } + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("zmkHead") ){ + + + this.zmkHead = (soup.get("zmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4139")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4139") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOAA.kt b/src/main/java/racal/sunyard/main/dto/DTOAA.kt new file mode 100644 index 0000000..deb7cc8 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOAA.kt @@ -0,0 +1,1072 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOAA { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var keyType : ByteArray? = null + private var keySolution : ByteArray? = null + private var keyClearPattern : ByteArray? = null + private var businessKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getKeySolutionAsBin( ) : ByteArray? { + + return this.keySolution + } + + + + fun getKeySolutionAsStr( ) : String? { + + if( null == this.keySolution ) return null; + return String(keySolution!!) + } + + + + fun getKeySolutionAsHex( ) : String? { + + if( null == this.keySolution ) return null; + return Util.bytes2HexString(keySolution) + } + + + + fun setKeySolution( bytes : ByteArray ) : Data { + + this.keySolution = bytes + return this + } + + + + fun getKeyClearPatternAsBin( ) : ByteArray? { + + return this.keyClearPattern + } + + + + fun getKeyClearPatternAsStr( ) : String? { + + if( null == this.keyClearPattern ) return null; + return String(keyClearPattern!!) + } + + + + fun getKeyClearPatternAsHex( ) : String? { + + if( null == this.keyClearPattern ) return null; + return Util.bytes2HexString(keyClearPattern) + } + + + + fun setKeyClearPattern( bytes : ByteArray ) : Data { + + this.keyClearPattern = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + +if( null != keySolution ){ + + + soup.put("keySolution", this.keySolution!!) + } + +if( null != keyClearPattern ){ + + + soup.put("keyClearPattern", this.keyClearPattern!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("keySolution") ){ + + + this.keySolution = (soup.get("keySolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyClearPattern") ){ + + + this.keyClearPattern = (soup.get("keyClearPattern") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4141")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4141") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var lmkHead : ByteArray? = null + private var lmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + return null + } + + + + fun getLmkHeadAsBin( ) : ByteArray? { + + return this.lmkHead + } + + + + fun getLmkHeadAsStr( ) : String? { + + if( null == this.lmkHead ) return null; + return String(lmkHead!!) + } + + + + fun getLmkHeadAsHex( ) : String? { + + if( null == this.lmkHead ) return null; + return Util.bytes2HexString(lmkHead) + } + + + + fun setLmkHead( bytes : ByteArray ) : Data { + + this.lmkHead = bytes + return this + } + + + + fun getLmkAsBin( ) : ByteArray? { + + return this.lmk + } + + + + fun getLmkAsStr( ) : String? { + + if( null == this.lmk ) return null; + return String(lmk!!) + } + + + + fun getLmkAsHex( ) : String? { + + if( null == this.lmk ) return null; + return Util.bytes2HexString(lmk) + } + + + + fun setLmk( bytes : ByteArray ) : Data { + + this.lmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != lmkHead ){ + + + soup.put("lmkHead", this.lmkHead!!) + } + +if( null != lmk ){ + + + soup.put("lmk", this.lmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("lmkHead") ){ + + + this.lmkHead = (soup.get("lmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("lmk") ){ + + + this.lmk = (soup.get("lmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4142")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4142") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOAB.kt b/src/main/java/racal/sunyard/main/dto/DTOAB.kt new file mode 100644 index 0000000..744ec8e --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOAB.kt @@ -0,0 +1,1167 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOAB { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var keyType : ByteArray? = null + private var key : ByteArray? = null + private var keyCheck : ByteArray? = null + private var checkAlg : ByteArray? = null + private var businessKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getCheckAlgAsBin( ) : ByteArray? { + + return this.checkAlg + } + + + + fun getCheckAlgAsStr( ) : String? { + + if( null == this.checkAlg ) return null; + return String(checkAlg!!) + } + + + + fun getCheckAlgAsHex( ) : String? { + + if( null == this.checkAlg ) return null; + return Util.bytes2HexString(checkAlg) + } + + + + fun setCheckAlg( bytes : ByteArray ) : Data { + + this.checkAlg = bytes + return this + } + + + enum class CheckAlgOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("30")), +OPVSM4(Util.hexString2Bytes("31")), + } + + fun getCheckAlgCn( ) : String? { + + if( null == checkAlg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.checkAlg) ) ) { + + return "3DES" + +} + + +if( "31".equals(Util.bytes2HexString(this.checkAlg) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getCheckAlgOptionIndex( ) : Int? { + + if( null == checkAlg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.checkAlg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.checkAlg) ) ) { + + return 1 + +} + + return null + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + +if( null != checkAlg ){ + + + soup.put("checkAlg", this.checkAlg!!) + soup.put("checkAlg\$option", getCheckAlgOptionIndex()!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + +if( soup.containsKey("checkAlg") ){ + + + this.checkAlg = (soup.get("checkAlg") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4142")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4142") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var key1 : ByteArray? = null + private var key2 : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + return null + } + + + + fun getKey1AsBin( ) : ByteArray? { + + return this.key1 + } + + + + fun getKey1AsStr( ) : String? { + + if( null == this.key1 ) return null; + return String(key1!!) + } + + + + fun getKey1AsHex( ) : String? { + + if( null == this.key1 ) return null; + return Util.bytes2HexString(key1) + } + + + + fun setKey1( bytes : ByteArray ) : Data { + + this.key1 = bytes + return this + } + + + + fun getKey2AsBin( ) : ByteArray? { + + return this.key2 + } + + + + fun getKey2AsStr( ) : String? { + + if( null == this.key2 ) return null; + return String(key2!!) + } + + + + fun getKey2AsHex( ) : String? { + + if( null == this.key2 ) return null; + return Util.bytes2HexString(key2) + } + + + + fun setKey2( bytes : ByteArray ) : Data { + + this.key2 = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != key1 ){ + + + soup.put("key1", this.key1!!) + } + +if( null != key2 ){ + + + soup.put("key2", this.key2!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("key1") ){ + + + this.key1 = (soup.get("key1") as PacketSection).bytes +} + + +if( soup.containsKey("key2") ){ + + + this.key2 = (soup.get("key2") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4143")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4143") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOAE.kt b/src/main/java/racal/sunyard/main/dto/DTOAE.kt new file mode 100644 index 0000000..5116a91 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOAE.kt @@ -0,0 +1,1192 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOAE { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var tmkNow : ByteArray? = null + private var tmkStorage : ByteArray? = null + private var separator : ByteArray? = null + private var tmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getTmkNowAsBin( ) : ByteArray? { + + return this.tmkNow + } + + + + fun getTmkNowAsStr( ) : String? { + + if( null == this.tmkNow ) return null; + return String(tmkNow!!) + } + + + + fun getTmkNowAsHex( ) : String? { + + if( null == this.tmkNow ) return null; + return Util.bytes2HexString(tmkNow) + } + + + + fun setTmkNow( bytes : ByteArray ) : Data { + + this.tmkNow = bytes + return this + } + + + + fun getTmkStorageAsBin( ) : ByteArray? { + + return this.tmkStorage + } + + + + fun getTmkStorageAsStr( ) : String? { + + if( null == this.tmkStorage ) return null; + return String(tmkStorage!!) + } + + + + fun getTmkStorageAsHex( ) : String? { + + if( null == this.tmkStorage ) return null; + return Util.bytes2HexString(tmkStorage) + } + + + + fun setTmkStorage( bytes : ByteArray ) : Data { + + this.tmkStorage = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getTmkSolutionAsBin( ) : ByteArray? { + + return this.tmkSolution + } + + + + fun getTmkSolutionAsStr( ) : String? { + + if( null == this.tmkSolution ) return null; + return String(tmkSolution!!) + } + + + + fun getTmkSolutionAsHex( ) : String? { + + if( null == this.tmkSolution ) return null; + return Util.bytes2HexString(tmkSolution) + } + + + + fun setTmkSolution( bytes : ByteArray ) : Data { + + this.tmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != tmkNow ){ + + + soup.put("tmkNow", this.tmkNow!!) + } + +if( null != tmkStorage ){ + + + soup.put("tmkStorage", this.tmkStorage!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != tmkSolution ){ + + + soup.put("tmkSolution", this.tmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("tmkNow") ){ + + + this.tmkNow = (soup.get("tmkNow") as PacketSection).bytes +} + + +if( soup.containsKey("tmkStorage") ){ + + + this.tmkStorage = (soup.get("tmkStorage") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("tmkSolution") ){ + + + this.tmkSolution = (soup.get("tmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4145")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4145") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tmkHead : ByteArray? = null + private var tmkKey : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV当前TMKTPK或PVK奇偶校验错(Util.hexString2Bytes("3130")), +OPV存储TMKTPK或PVK奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "当前 TMK、 TPK 或 PVK 奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "存储 TMK、 TPK 或 PVK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + return null + } + + + + fun getTmkHeadAsBin( ) : ByteArray? { + + return this.tmkHead + } + + + + fun getTmkHeadAsStr( ) : String? { + + if( null == this.tmkHead ) return null; + return String(tmkHead!!) + } + + + + fun getTmkHeadAsHex( ) : String? { + + if( null == this.tmkHead ) return null; + return Util.bytes2HexString(tmkHead) + } + + + + fun setTmkHead( bytes : ByteArray ) : Data { + + this.tmkHead = bytes + return this + } + + + + fun getTmkKeyAsBin( ) : ByteArray? { + + return this.tmkKey + } + + + + fun getTmkKeyAsStr( ) : String? { + + if( null == this.tmkKey ) return null; + return String(tmkKey!!) + } + + + + fun getTmkKeyAsHex( ) : String? { + + if( null == this.tmkKey ) return null; + return Util.bytes2HexString(tmkKey) + } + + + + fun setTmkKey( bytes : ByteArray ) : Data { + + this.tmkKey = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != tmkHead ){ + + + soup.put("tmkHead", this.tmkHead!!) + } + +if( null != tmkKey ){ + + + soup.put("tmkKey", this.tmkKey!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("tmkHead") ){ + + + this.tmkHead = (soup.get("tmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("tmkKey") ){ + + + this.tmkKey = (soup.get("tmkKey") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4146")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4146") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOAG.kt b/src/main/java/racal/sunyard/main/dto/DTOAG.kt new file mode 100644 index 0000000..e144be9 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOAG.kt @@ -0,0 +1,1267 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOAG { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var tmk : ByteArray? = null + private var tak : ByteArray? = null + private var businessKey : ByteArray? = null + private var separator : ByteArray? = null + private var tmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getTmkAsBin( ) : ByteArray? { + + return this.tmk + } + + + + fun getTmkAsStr( ) : String? { + + if( null == this.tmk ) return null; + return String(tmk!!) + } + + + + fun getTmkAsHex( ) : String? { + + if( null == this.tmk ) return null; + return Util.bytes2HexString(tmk) + } + + + + fun setTmk( bytes : ByteArray ) : Data { + + this.tmk = bytes + return this + } + + + + fun getTakAsBin( ) : ByteArray? { + + return this.tak + } + + + + fun getTakAsStr( ) : String? { + + if( null == this.tak ) return null; + return String(tak!!) + } + + + + fun getTakAsHex( ) : String? { + + if( null == this.tak ) return null; + return Util.bytes2HexString(tak) + } + + + + fun setTak( bytes : ByteArray ) : Data { + + this.tak = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getTmkSolutionAsBin( ) : ByteArray? { + + return this.tmkSolution + } + + + + fun getTmkSolutionAsStr( ) : String? { + + if( null == this.tmkSolution ) return null; + return String(tmkSolution!!) + } + + + + fun getTmkSolutionAsHex( ) : String? { + + if( null == this.tmkSolution ) return null; + return Util.bytes2HexString(tmkSolution) + } + + + + fun setTmkSolution( bytes : ByteArray ) : Data { + + this.tmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != tmk ){ + + + soup.put("tmk", this.tmk!!) + } + +if( null != tak ){ + + + soup.put("tak", this.tak!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != tmkSolution ){ + + + soup.put("tmkSolution", this.tmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("tmk") ){ + + + this.tmk = (soup.get("tmk") as PacketSection).bytes +} + + +if( soup.containsKey("tak") ){ + + + this.tak = (soup.get("tak") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("tmkSolution") ){ + + + this.tmkSolution = (soup.get("tmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4147")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4147") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tmkTakHead : ByteArray? = null + private var tmkTak : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPVTMKTPK或PVK奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "TMK、TPK 或 PVK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + return null + } + + + + fun getTmkTakHeadAsBin( ) : ByteArray? { + + return this.tmkTakHead + } + + + + fun getTmkTakHeadAsStr( ) : String? { + + if( null == this.tmkTakHead ) return null; + return String(tmkTakHead!!) + } + + + + fun getTmkTakHeadAsHex( ) : String? { + + if( null == this.tmkTakHead ) return null; + return Util.bytes2HexString(tmkTakHead) + } + + + + fun setTmkTakHead( bytes : ByteArray ) : Data { + + this.tmkTakHead = bytes + return this + } + + + + fun getTmkTakAsBin( ) : ByteArray? { + + return this.tmkTak + } + + + + fun getTmkTakAsStr( ) : String? { + + if( null == this.tmkTak ) return null; + return String(tmkTak!!) + } + + + + fun getTmkTakAsHex( ) : String? { + + if( null == this.tmkTak ) return null; + return Util.bytes2HexString(tmkTak) + } + + + + fun setTmkTak( bytes : ByteArray ) : Data { + + this.tmkTak = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != tmkTakHead ){ + + + soup.put("tmkTakHead", this.tmkTakHead!!) + } + +if( null != tmkTak ){ + + + soup.put("tmkTak", this.tmkTak!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("tmkTakHead") ){ + + + this.tmkTakHead = (soup.get("tmkTakHead") as PacketSection).bytes +} + + +if( soup.containsKey("tmkTak") ){ + + + this.tmkTak = (soup.get("tmkTak") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4148")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4148") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOB0.kt b/src/main/java/racal/sunyard/main/dto/DTOB0.kt new file mode 100644 index 0000000..3ac8aac --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOB0.kt @@ -0,0 +1,1012 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOB0 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var keyType : ByteArray? = null + private var key : ByteArray? = null + private var keySolution : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getKeySolutionAsBin( ) : ByteArray? { + + return this.keySolution + } + + + + fun getKeySolutionAsStr( ) : String? { + + if( null == this.keySolution ) return null; + return String(keySolution!!) + } + + + + fun getKeySolutionAsHex( ) : String? { + + if( null == this.keySolution ) return null; + return Util.bytes2HexString(keySolution) + } + + + + fun setKeySolution( bytes : ByteArray ) : Data { + + this.keySolution = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != keySolution ){ + + + soup.put("keySolution", this.keySolution!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("keySolution") ){ + + + this.keySolution = (soup.get("keySolution") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4230")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4230") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var lmkHead : ByteArray? = null + private var lmk : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + return null + } + + + + fun getLmkHeadAsBin( ) : ByteArray? { + + return this.lmkHead + } + + + + fun getLmkHeadAsStr( ) : String? { + + if( null == this.lmkHead ) return null; + return String(lmkHead!!) + } + + + + fun getLmkHeadAsHex( ) : String? { + + if( null == this.lmkHead ) return null; + return Util.bytes2HexString(lmkHead) + } + + + + fun setLmkHead( bytes : ByteArray ) : Data { + + this.lmkHead = bytes + return this + } + + + + fun getLmkAsBin( ) : ByteArray? { + + return this.lmk + } + + + + fun getLmkAsStr( ) : String? { + + if( null == this.lmk ) return null; + return String(lmk!!) + } + + + + fun getLmkAsHex( ) : String? { + + if( null == this.lmk ) return null; + return Util.bytes2HexString(lmk) + } + + + + fun setLmk( bytes : ByteArray ) : Data { + + this.lmk = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != lmkHead ){ + + + soup.put("lmkHead", this.lmkHead!!) + } + +if( null != lmk ){ + + + soup.put("lmk", this.lmk!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("lmkHead") ){ + + + this.lmkHead = (soup.get("lmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("lmk") ){ + + + this.lmk = (soup.get("lmk") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4231")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4231") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOBA.kt b/src/main/java/racal/sunyard/main/dto/DTOBA.kt new file mode 100644 index 0000000..a91222e --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOBA.kt @@ -0,0 +1,972 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOBA { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var alg : ByteArray? = null + private var pin : ByteArray? = null + private var account : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("30")), +OPVSM4(Util.hexString2Bytes("31")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "3DES" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + return null + } + + + + fun getPinAsBin( ) : ByteArray? { + + return this.pin + } + + + + fun getPinAsStr( ) : String? { + + if( null == this.pin ) return null; + return String(pin!!) + } + + + + fun getPinAsHex( ) : String? { + + if( null == this.pin ) return null; + return Util.bytes2HexString(pin) + } + + + + fun setPin( bytes : ByteArray ) : Data { + + this.pin = bytes + return this + } + + + + fun getAccountAsBin( ) : ByteArray? { + + return this.account + } + + + + fun getAccountAsStr( ) : String? { + + if( null == this.account ) return null; + return String(account!!) + } + + + + fun getAccountAsHex( ) : String? { + + if( null == this.account ) return null; + return Util.bytes2HexString(account) + } + + + + fun setAccount( bytes : ByteArray ) : Data { + + this.account = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != pin ){ + + + soup.put("pin", this.pin!!) + } + +if( null != account ){ + + + soup.put("account", this.account!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("pin") ){ + + + this.pin = (soup.get("pin") as PacketSection).bytes +} + + +if( soup.containsKey("account") ){ + + + this.account = (soup.get("account") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4241")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4241") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var pinBlock : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + return null + } + + + + fun getPinBlockAsBin( ) : ByteArray? { + + return this.pinBlock + } + + + + fun getPinBlockAsStr( ) : String? { + + if( null == this.pinBlock ) return null; + return String(pinBlock!!) + } + + + + fun getPinBlockAsHex( ) : String? { + + if( null == this.pinBlock ) return null; + return Util.bytes2HexString(pinBlock) + } + + + + fun setPinBlock( bytes : ByteArray ) : Data { + + this.pinBlock = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != pinBlock ){ + + + soup.put("pinBlock", this.pinBlock!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("pinBlock") ){ + + + this.pinBlock = (soup.get("pinBlock") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4242")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4242") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOBY.kt b/src/main/java/racal/sunyard/main/dto/DTOBY.kt new file mode 100644 index 0000000..0548737 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOBY.kt @@ -0,0 +1,1222 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOBY { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var zmki : ByteArray? = null + private var zmk : ByteArray? = null + private var separator : ByteArray? = null + private var zmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getZmkiAsBin( ) : ByteArray? { + + return this.zmki + } + + + + fun getZmkiAsStr( ) : String? { + + if( null == this.zmki ) return null; + return String(zmki!!) + } + + + + fun getZmkiAsHex( ) : String? { + + if( null == this.zmki ) return null; + return Util.bytes2HexString(zmki) + } + + + + fun setZmki( bytes : ByteArray ) : Data { + + this.zmki = bytes + return this + } + + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getZmkSolutionAsBin( ) : ByteArray? { + + return this.zmkSolution + } + + + + fun getZmkSolutionAsStr( ) : String? { + + if( null == this.zmkSolution ) return null; + return String(zmkSolution!!) + } + + + + fun getZmkSolutionAsHex( ) : String? { + + if( null == this.zmkSolution ) return null; + return Util.bytes2HexString(zmkSolution) + } + + + + fun setZmkSolution( bytes : ByteArray ) : Data { + + this.zmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != zmki ){ + + + soup.put("zmki", this.zmki!!) + } + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != zmkSolution ){ + + + soup.put("zmkSolution", this.zmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("zmki") ){ + + + this.zmki = (soup.get("zmki") as PacketSection).bytes +} + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("zmkSolution") ){ + + + this.zmkSolution = (soup.get("zmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4259")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4259") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var zmkHead : ByteArray? = null + private var zmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV密钥奇偶校验错仅仅是报告错误并不影响结果(Util.hexString2Bytes("3031")), +OPV第一个成份奇偶校验错(Util.hexString2Bytes("3130")), +OPV第二或第三个成份奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错,仅仅是报告错误,并不影响结果" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "第一个成份奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "第二或第三个成份奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + return null + } + + + + fun getZmkHeadAsBin( ) : ByteArray? { + + return this.zmkHead + } + + + + fun getZmkHeadAsStr( ) : String? { + + if( null == this.zmkHead ) return null; + return String(zmkHead!!) + } + + + + fun getZmkHeadAsHex( ) : String? { + + if( null == this.zmkHead ) return null; + return Util.bytes2HexString(zmkHead) + } + + + + fun setZmkHead( bytes : ByteArray ) : Data { + + this.zmkHead = bytes + return this + } + + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != zmkHead ){ + + + soup.put("zmkHead", this.zmkHead!!) + } + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("zmkHead") ){ + + + this.zmkHead = (soup.get("zmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("425A")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("425A") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOCA.kt b/src/main/java/racal/sunyard/main/dto/DTOCA.kt new file mode 100644 index 0000000..b5f7d54 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOCA.kt @@ -0,0 +1,1609 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOCA { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var sourceZpk : ByteArray? = null + private var purposeZpk : ByteArray? = null + private var algorithmKey : ByteArray? = null + private var sca : ByteArray? = null + private var dca : ByteArray? = null + private var businessKey : ByteArray? = null + private var maxLength : ByteArray? = null + private var sourcePinBlock : ByteArray? = null + private var sourcePinBlockFormat : ByteArray? = null + private var purposePinBlockFormat : ByteArray? = null + private var account : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getSourceZpkAsBin( ) : ByteArray? { + + return this.sourceZpk + } + + + + fun getSourceZpkAsStr( ) : String? { + + if( null == this.sourceZpk ) return null; + return String(sourceZpk!!) + } + + + + fun getSourceZpkAsHex( ) : String? { + + if( null == this.sourceZpk ) return null; + return Util.bytes2HexString(sourceZpk) + } + + + + fun setSourceZpk( bytes : ByteArray ) : Data { + + this.sourceZpk = bytes + return this + } + + + + fun getPurposeZpkAsBin( ) : ByteArray? { + + return this.purposeZpk + } + + + + fun getPurposeZpkAsStr( ) : String? { + + if( null == this.purposeZpk ) return null; + return String(purposeZpk!!) + } + + + + fun getPurposeZpkAsHex( ) : String? { + + if( null == this.purposeZpk ) return null; + return Util.bytes2HexString(purposeZpk) + } + + + + fun setPurposeZpk( bytes : ByteArray ) : Data { + + this.purposeZpk = bytes + return this + } + + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + + fun getScaAsBin( ) : ByteArray? { + + return this.sca + } + + + + fun getScaAsStr( ) : String? { + + if( null == this.sca ) return null; + return String(sca!!) + } + + + + fun getScaAsHex( ) : String? { + + if( null == this.sca ) return null; + return Util.bytes2HexString(sca) + } + + + + fun setSca( bytes : ByteArray ) : Data { + + this.sca = bytes + return this + } + + + enum class ScaOptions( val bin : ByteArray ) { + +OPV3DES默认(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getScaCn( ) : String? { + + if( null == sca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.sca) ) ) { + + return "3DES(默认)" + +} + + +if( "32".equals(Util.bytes2HexString(this.sca) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getScaOptionIndex( ) : Int? { + + if( null == sca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.sca) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.sca) ) ) { + + return 1 + +} + + return null + } + + + + fun getDcaAsBin( ) : ByteArray? { + + return this.dca + } + + + + fun getDcaAsStr( ) : String? { + + if( null == this.dca ) return null; + return String(dca!!) + } + + + + fun getDcaAsHex( ) : String? { + + if( null == this.dca ) return null; + return Util.bytes2HexString(dca) + } + + + + fun setDca( bytes : ByteArray ) : Data { + + this.dca = bytes + return this + } + + + enum class DcaOptions( val bin : ByteArray ) { + +OPV3DES默认(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getDcaCn( ) : String? { + + if( null == dca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.dca) ) ) { + + return "3DES(默认)" + +} + + +if( "32".equals(Util.bytes2HexString(this.dca) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getDcaOptionIndex( ) : Int? { + + if( null == dca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.dca) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.dca) ) ) { + + return 1 + +} + + return null + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getMaxLengthAsBin( ) : ByteArray? { + + return this.maxLength + } + + + + fun getMaxLengthAsStr( ) : String? { + + if( null == this.maxLength ) return null; + return String(maxLength!!) + } + + + + fun getMaxLengthAsHex( ) : String? { + + if( null == this.maxLength ) return null; + return Util.bytes2HexString(maxLength) + } + + + + fun setMaxLength( bytes : ByteArray ) : Data { + + this.maxLength = bytes + return this + } + + + + fun getSourcePinBlockAsBin( ) : ByteArray? { + + return this.sourcePinBlock + } + + + + fun getSourcePinBlockAsStr( ) : String? { + + if( null == this.sourcePinBlock ) return null; + return String(sourcePinBlock!!) + } + + + + fun getSourcePinBlockAsHex( ) : String? { + + if( null == this.sourcePinBlock ) return null; + return Util.bytes2HexString(sourcePinBlock) + } + + + + fun setSourcePinBlock( bytes : ByteArray ) : Data { + + this.sourcePinBlock = bytes + return this + } + + + + fun getSourcePinBlockFormatAsBin( ) : ByteArray? { + + return this.sourcePinBlockFormat + } + + + + fun getSourcePinBlockFormatAsStr( ) : String? { + + if( null == this.sourcePinBlockFormat ) return null; + return String(sourcePinBlockFormat!!) + } + + + + fun getSourcePinBlockFormatAsHex( ) : String? { + + if( null == this.sourcePinBlockFormat ) return null; + return Util.bytes2HexString(sourcePinBlockFormat) + } + + + + fun setSourcePinBlockFormat( bytes : ByteArray ) : Data { + + this.sourcePinBlockFormat = bytes + return this + } + + + + fun getPurposePinBlockFormatAsBin( ) : ByteArray? { + + return this.purposePinBlockFormat + } + + + + fun getPurposePinBlockFormatAsStr( ) : String? { + + if( null == this.purposePinBlockFormat ) return null; + return String(purposePinBlockFormat!!) + } + + + + fun getPurposePinBlockFormatAsHex( ) : String? { + + if( null == this.purposePinBlockFormat ) return null; + return Util.bytes2HexString(purposePinBlockFormat) + } + + + + fun setPurposePinBlockFormat( bytes : ByteArray ) : Data { + + this.purposePinBlockFormat = bytes + return this + } + + + + fun getAccountAsBin( ) : ByteArray? { + + return this.account + } + + + + fun getAccountAsStr( ) : String? { + + if( null == this.account ) return null; + return String(account!!) + } + + + + fun getAccountAsHex( ) : String? { + + if( null == this.account ) return null; + return Util.bytes2HexString(account) + } + + + + fun setAccount( bytes : ByteArray ) : Data { + + this.account = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != sourceZpk ){ + + + soup.put("sourceZpk", this.sourceZpk!!) + } + +if( null != purposeZpk ){ + + + soup.put("purposeZpk", this.purposeZpk!!) + } + +if( null != algorithmKey ){ + + + soup.put("algorithmKey", this.algorithmKey!!) + } + +if( null != sca ){ + + + soup.put("sca", this.sca!!) + soup.put("sca\$option", getScaOptionIndex()!!) + } + +if( null != dca ){ + + + soup.put("dca", this.dca!!) + soup.put("dca\$option", getDcaOptionIndex()!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + soup.put("maxLength", Util.hexString2Bytes("3132")) + +if( null != maxLength ){ + + + soup.put("maxLength", this.maxLength!!) + } + +if( null != sourcePinBlock ){ + + + soup.put("sourcePinBlock", this.sourcePinBlock!!) + } + +if( null != sourcePinBlockFormat ){ + + + soup.put("sourcePinBlockFormat", this.sourcePinBlockFormat!!) + } + +if( null != purposePinBlockFormat ){ + + + soup.put("purposePinBlockFormat", this.purposePinBlockFormat!!) + } + +if( null != account ){ + + + soup.put("account", this.account!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("sourceZpk") ){ + + + this.sourceZpk = (soup.get("sourceZpk") as PacketSection).bytes +} + + +if( soup.containsKey("purposeZpk") ){ + + + this.purposeZpk = (soup.get("purposeZpk") as PacketSection).bytes +} + + +if( soup.containsKey("algorithmKey") ){ + + + this.algorithmKey = (soup.get("algorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("sca") ){ + + + this.sca = (soup.get("sca") as PacketSection).bytes +} + + +if( soup.containsKey("dca") ){ + + + this.dca = (soup.get("dca") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + this.maxLength = Util.hexString2Bytes("3132") + +if( soup.containsKey("maxLength") ){ + + + this.maxLength = (soup.get("maxLength") as PacketSection).bytes +} + + +if( soup.containsKey("sourcePinBlock") ){ + + + this.sourcePinBlock = (soup.get("sourcePinBlock") as PacketSection).bytes +} + + +if( soup.containsKey("sourcePinBlockFormat") ){ + + + this.sourcePinBlockFormat = (soup.get("sourcePinBlockFormat") as PacketSection).bytes +} + + +if( soup.containsKey("purposePinBlockFormat") ){ + + + this.purposePinBlockFormat = (soup.get("purposePinBlockFormat") as PacketSection).bytes +} + + +if( soup.containsKey("account") ){ + + + this.account = (soup.get("account") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4341")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4341") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var pinLen : ByteArray? = null + private var purposePinBlock : ByteArray? = null + private var purposePinBlockFormat : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV源ZPK奇偶校验错(Util.hexString2Bytes("3130")), +OPV目的ZPK奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVPIN块错误(Util.hexString2Bytes("3230")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV帐号无效(Util.hexString2Bytes("3232")), +OPV无效PIN块格式代码(Util.hexString2Bytes("3233")), +OPVPIN小于4位或大于12位(Util.hexString2Bytes("3234")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "源 ZPK 奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "目的 ZPK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3230".equals(Util.bytes2HexString(this.error) ) ) { + + return "PIN块错误" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return "帐号无效" + +} + + +if( "3233".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效 PIN 块格式代码" + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return "PIN 小于 4 位或大于 12 位。" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3230".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3233".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 12 + +} + + return null + } + + + + fun getPinLenAsBin( ) : ByteArray? { + + return this.pinLen + } + + + + fun getPinLenAsStr( ) : String? { + + if( null == this.pinLen ) return null; + return String(pinLen!!) + } + + + + fun getPinLenAsHex( ) : String? { + + if( null == this.pinLen ) return null; + return Util.bytes2HexString(pinLen) + } + + + + fun setPinLen( bytes : ByteArray ) : Data { + + this.pinLen = bytes + return this + } + + + + fun getPurposePinBlockAsBin( ) : ByteArray? { + + return this.purposePinBlock + } + + + + fun getPurposePinBlockAsStr( ) : String? { + + if( null == this.purposePinBlock ) return null; + return String(purposePinBlock!!) + } + + + + fun getPurposePinBlockAsHex( ) : String? { + + if( null == this.purposePinBlock ) return null; + return Util.bytes2HexString(purposePinBlock) + } + + + + fun setPurposePinBlock( bytes : ByteArray ) : Data { + + this.purposePinBlock = bytes + return this + } + + + + fun getPurposePinBlockFormatAsBin( ) : ByteArray? { + + return this.purposePinBlockFormat + } + + + + fun getPurposePinBlockFormatAsStr( ) : String? { + + if( null == this.purposePinBlockFormat ) return null; + return String(purposePinBlockFormat!!) + } + + + + fun getPurposePinBlockFormatAsHex( ) : String? { + + if( null == this.purposePinBlockFormat ) return null; + return Util.bytes2HexString(purposePinBlockFormat) + } + + + + fun setPurposePinBlockFormat( bytes : ByteArray ) : Data { + + this.purposePinBlockFormat = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != pinLen ){ + + + soup.put("pinLen", this.pinLen!!) + } + +if( null != purposePinBlock ){ + + + soup.put("purposePinBlock", this.purposePinBlock!!) + } + +if( null != purposePinBlockFormat ){ + + + soup.put("purposePinBlockFormat", this.purposePinBlockFormat!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("pinLen") ){ + + + this.pinLen = (soup.get("pinLen") as PacketSection).bytes +} + + +if( soup.containsKey("purposePinBlock") ){ + + + this.purposePinBlock = (soup.get("purposePinBlock") as PacketSection).bytes +} + + +if( soup.containsKey("purposePinBlockFormat") ){ + + + this.purposePinBlockFormat = (soup.get("purposePinBlockFormat") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4342")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4342") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOCB.kt b/src/main/java/racal/sunyard/main/dto/DTOCB.kt new file mode 100644 index 0000000..44fd19b --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOCB.kt @@ -0,0 +1,1857 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOCB { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var srcKeyType : ByteArray? = null + private var desKeyType : ByteArray? = null + private var srcKey : ByteArray? = null + private var desKey : ByteArray? = null + private var algorithmKey : ByteArray? = null + private var sca : ByteArray? = null + private var dca : ByteArray? = null + private var sPin : ByteArray? = null + private var sPinType : ByteArray? = null + private var dPinType : ByteArray? = null + private var primaryAccount : ByteArray? = null + private var businessKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getSrcKeyTypeAsBin( ) : ByteArray? { + + return this.srcKeyType + } + + + + fun getSrcKeyTypeAsStr( ) : String? { + + if( null == this.srcKeyType ) return null; + return String(srcKeyType!!) + } + + + + fun getSrcKeyTypeAsHex( ) : String? { + + if( null == this.srcKeyType ) return null; + return Util.bytes2HexString(srcKeyType) + } + + + + fun setSrcKeyType( bytes : ByteArray ) : Data { + + this.srcKeyType = bytes + return this + } + + + + fun getDesKeyTypeAsBin( ) : ByteArray? { + + return this.desKeyType + } + + + + fun getDesKeyTypeAsStr( ) : String? { + + if( null == this.desKeyType ) return null; + return String(desKeyType!!) + } + + + + fun getDesKeyTypeAsHex( ) : String? { + + if( null == this.desKeyType ) return null; + return Util.bytes2HexString(desKeyType) + } + + + + fun setDesKeyType( bytes : ByteArray ) : Data { + + this.desKeyType = bytes + return this + } + + + + fun getSrcKeyAsBin( ) : ByteArray? { + + return this.srcKey + } + + + + fun getSrcKeyAsStr( ) : String? { + + if( null == this.srcKey ) return null; + return String(srcKey!!) + } + + + + fun getSrcKeyAsHex( ) : String? { + + if( null == this.srcKey ) return null; + return Util.bytes2HexString(srcKey) + } + + + + fun setSrcKey( bytes : ByteArray ) : Data { + + this.srcKey = bytes + return this + } + + + + fun getDesKeyAsBin( ) : ByteArray? { + + return this.desKey + } + + + + fun getDesKeyAsStr( ) : String? { + + if( null == this.desKey ) return null; + return String(desKey!!) + } + + + + fun getDesKeyAsHex( ) : String? { + + if( null == this.desKey ) return null; + return Util.bytes2HexString(desKey) + } + + + + fun setDesKey( bytes : ByteArray ) : Data { + + this.desKey = bytes + return this + } + + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + + fun getScaAsBin( ) : ByteArray? { + + return this.sca + } + + + + fun getScaAsStr( ) : String? { + + if( null == this.sca ) return null; + return String(sca!!) + } + + + + fun getScaAsHex( ) : String? { + + if( null == this.sca ) return null; + return Util.bytes2HexString(sca) + } + + + + fun setSca( bytes : ByteArray ) : Data { + + this.sca = bytes + return this + } + + + enum class ScaOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getScaCn( ) : String? { + + if( null == sca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.sca) ) ) { + + return "3DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.sca) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getScaOptionIndex( ) : Int? { + + if( null == sca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.sca) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.sca) ) ) { + + return 1 + +} + + return null + } + + + + fun getDcaAsBin( ) : ByteArray? { + + return this.dca + } + + + + fun getDcaAsStr( ) : String? { + + if( null == this.dca ) return null; + return String(dca!!) + } + + + + fun getDcaAsHex( ) : String? { + + if( null == this.dca ) return null; + return Util.bytes2HexString(dca) + } + + + + fun setDca( bytes : ByteArray ) : Data { + + this.dca = bytes + return this + } + + + enum class DcaOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getDcaCn( ) : String? { + + if( null == dca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.dca) ) ) { + + return "3DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.dca) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getDcaOptionIndex( ) : Int? { + + if( null == dca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.dca) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.dca) ) ) { + + return 1 + +} + + return null + } + + + + fun getSPinAsBin( ) : ByteArray? { + + return this.sPin + } + + + + fun getSPinAsStr( ) : String? { + + if( null == this.sPin ) return null; + return String(sPin!!) + } + + + + fun getSPinAsHex( ) : String? { + + if( null == this.sPin ) return null; + return Util.bytes2HexString(sPin) + } + + + + fun setSPin( bytes : ByteArray ) : Data { + + this.sPin = bytes + return this + } + + + + fun getSPinTypeAsBin( ) : ByteArray? { + + return this.sPinType + } + + + + fun getSPinTypeAsStr( ) : String? { + + if( null == this.sPinType ) return null; + return String(sPinType!!) + } + + + + fun getSPinTypeAsHex( ) : String? { + + if( null == this.sPinType ) return null; + return Util.bytes2HexString(sPinType) + } + + + + fun setSPinType( bytes : ByteArray ) : Data { + + this.sPinType = bytes + return this + } + + + enum class SPinTypeOptions( val bin : ByteArray ) { + +OPV带主帐号的ANSI98格式(Util.hexString2Bytes("3031")), +OPVDocutelATM(Util.hexString2Bytes("3032")), +OPVDieboldandIBMATM(Util.hexString2Bytes("3033")), +OPVPlusNetwork(Util.hexString2Bytes("3034")), +OPVISO956411格式1NPPRR(Util.hexString2Bytes("3035")), +OPV不带主帐号的ANSI98格式(Util.hexString2Bytes("3036")), + } + + fun getSPinTypeCn( ) : String? { + + if( null == sPinType ) { return null } + +if( "3031".equals(Util.bytes2HexString(this.sPinType) ) ) { + + return "带主帐号的ANSI9.8格式" + +} + + +if( "3032".equals(Util.bytes2HexString(this.sPinType) ) ) { + + return "Docutel ATM" + +} + + +if( "3033".equals(Util.bytes2HexString(this.sPinType) ) ) { + + return "Diebold and IBM ATM" + +} + + +if( "3034".equals(Util.bytes2HexString(this.sPinType) ) ) { + + return "Plus Network" + +} + + +if( "3035".equals(Util.bytes2HexString(this.sPinType) ) ) { + + return "ISO9564-1-1格式,1NP..PR...R" + +} + + +if( "3036".equals(Util.bytes2HexString(this.sPinType) ) ) { + + return "不带主帐号的ANSI9.8格式" + +} + + return null + } + + + + fun getSPinTypeOptionIndex( ) : Int? { + + if( null == sPinType ) { return null } + +if( "3031".equals(Util.bytes2HexString(this.sPinType) ) ) { + + return 0 + +} + + +if( "3032".equals(Util.bytes2HexString(this.sPinType) ) ) { + + return 1 + +} + + +if( "3033".equals(Util.bytes2HexString(this.sPinType) ) ) { + + return 2 + +} + + +if( "3034".equals(Util.bytes2HexString(this.sPinType) ) ) { + + return 3 + +} + + +if( "3035".equals(Util.bytes2HexString(this.sPinType) ) ) { + + return 4 + +} + + +if( "3036".equals(Util.bytes2HexString(this.sPinType) ) ) { + + return 5 + +} + + return null + } + + + + fun getDPinTypeAsBin( ) : ByteArray? { + + return this.dPinType + } + + + + fun getDPinTypeAsStr( ) : String? { + + if( null == this.dPinType ) return null; + return String(dPinType!!) + } + + + + fun getDPinTypeAsHex( ) : String? { + + if( null == this.dPinType ) return null; + return Util.bytes2HexString(dPinType) + } + + + + fun setDPinType( bytes : ByteArray ) : Data { + + this.dPinType = bytes + return this + } + + + enum class DPinTypeOptions( val bin : ByteArray ) { + +OPV带主帐号的ANSI98格式(Util.hexString2Bytes("3031")), +OPVDocutelATM(Util.hexString2Bytes("3032")), +OPVDieboldandIBMATM(Util.hexString2Bytes("3033")), +OPVPlusNetwork(Util.hexString2Bytes("3034")), +OPVISO95641format1格式1NPPRR(Util.hexString2Bytes("3035")), +OPV不带主帐号的ANSI98格式(Util.hexString2Bytes("3036")), + } + + fun getDPinTypeCn( ) : String? { + + if( null == dPinType ) { return null } + +if( "3031".equals(Util.bytes2HexString(this.dPinType) ) ) { + + return "带主帐号的ANSI9.8格式" + +} + + +if( "3032".equals(Util.bytes2HexString(this.dPinType) ) ) { + + return "Docutel ATM" + +} + + +if( "3033".equals(Util.bytes2HexString(this.dPinType) ) ) { + + return "Diebold and IBM ATM" + +} + + +if( "3034".equals(Util.bytes2HexString(this.dPinType) ) ) { + + return "Plus Network" + +} + + +if( "3035".equals(Util.bytes2HexString(this.dPinType) ) ) { + + return "ISO95641-format 1格式,1NP..PR...R" + +} + + +if( "3036".equals(Util.bytes2HexString(this.dPinType) ) ) { + + return "不带主帐号的ANSI9.8格式" + +} + + return null + } + + + + fun getDPinTypeOptionIndex( ) : Int? { + + if( null == dPinType ) { return null } + +if( "3031".equals(Util.bytes2HexString(this.dPinType) ) ) { + + return 0 + +} + + +if( "3032".equals(Util.bytes2HexString(this.dPinType) ) ) { + + return 1 + +} + + +if( "3033".equals(Util.bytes2HexString(this.dPinType) ) ) { + + return 2 + +} + + +if( "3034".equals(Util.bytes2HexString(this.dPinType) ) ) { + + return 3 + +} + + +if( "3035".equals(Util.bytes2HexString(this.dPinType) ) ) { + + return 4 + +} + + +if( "3036".equals(Util.bytes2HexString(this.dPinType) ) ) { + + return 5 + +} + + return null + } + + + + fun getPrimaryAccountAsBin( ) : ByteArray? { + + return this.primaryAccount + } + + + + fun getPrimaryAccountAsStr( ) : String? { + + if( null == this.primaryAccount ) return null; + return String(primaryAccount!!) + } + + + + fun getPrimaryAccountAsHex( ) : String? { + + if( null == this.primaryAccount ) return null; + return Util.bytes2HexString(primaryAccount) + } + + + + fun setPrimaryAccount( bytes : ByteArray ) : Data { + + this.primaryAccount = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != srcKeyType ){ + + + soup.put("srcKeyType", this.srcKeyType!!) + } + +if( null != desKeyType ){ + + + soup.put("desKeyType", this.desKeyType!!) + } + +if( null != srcKey ){ + + + soup.put("srcKey", this.srcKey!!) + } + +if( null != desKey ){ + + + soup.put("desKey", this.desKey!!) + } + +if( null != algorithmKey ){ + + + soup.put("algorithmKey", this.algorithmKey!!) + } + +if( null != sca ){ + + + soup.put("sca", this.sca!!) + soup.put("sca\$option", getScaOptionIndex()!!) + } + +if( null != dca ){ + + + soup.put("dca", this.dca!!) + soup.put("dca\$option", getDcaOptionIndex()!!) + } + +if( null != sPin ){ + + + soup.put("sPin", this.sPin!!) + } + +if( null != sPinType ){ + + + soup.put("sPinType", this.sPinType!!) + soup.put("sPinType\$option", getSPinTypeOptionIndex()!!) + } + +if( null != dPinType ){ + + + soup.put("dPinType", this.dPinType!!) + soup.put("dPinType\$option", getDPinTypeOptionIndex()!!) + } + +if( null != primaryAccount ){ + + + soup.put("primaryAccount", this.primaryAccount!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("srcKeyType") ){ + + + this.srcKeyType = (soup.get("srcKeyType") as PacketSection).bytes +} + + +if( soup.containsKey("desKeyType") ){ + + + this.desKeyType = (soup.get("desKeyType") as PacketSection).bytes +} + + +if( soup.containsKey("srcKey") ){ + + + this.srcKey = (soup.get("srcKey") as PacketSection).bytes +} + + +if( soup.containsKey("desKey") ){ + + + this.desKey = (soup.get("desKey") as PacketSection).bytes +} + + +if( soup.containsKey("algorithmKey") ){ + + + this.algorithmKey = (soup.get("algorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("sca") ){ + + + this.sca = (soup.get("sca") as PacketSection).bytes +} + + +if( soup.containsKey("dca") ){ + + + this.dca = (soup.get("dca") as PacketSection).bytes +} + + +if( soup.containsKey("sPin") ){ + + + this.sPin = (soup.get("sPin") as PacketSection).bytes +} + + +if( soup.containsKey("sPinType") ){ + + + this.sPinType = (soup.get("sPinType") as PacketSection).bytes +} + + +if( soup.containsKey("dPinType") ){ + + + this.dPinType = (soup.get("dPinType") as PacketSection).bytes +} + + +if( soup.containsKey("primaryAccount") ){ + + + this.primaryAccount = (soup.get("primaryAccount") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4342")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4342") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var pinLen : ByteArray? = null + private var dPin : ByteArray? = null + private var dPinType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV源ZPK奇偶校验错(Util.hexString2Bytes("3130")), +OPV目的ZPK奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV帐号无效(Util.hexString2Bytes("3232")), +OPV无效PIN块格式代码(Util.hexString2Bytes("3233")), +OPVPIN小于4位或大于12位(Util.hexString2Bytes("3234")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "源ZPK奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "目的ZPK奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return "帐号无效" + +} + + +if( "3233".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效PIN块格式代码" + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return "PIN小于4位或大于12位" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3233".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + return null + } + + + + fun getPinLenAsBin( ) : ByteArray? { + + return this.pinLen + } + + + + fun getPinLenAsStr( ) : String? { + + if( null == this.pinLen ) return null; + return String(pinLen!!) + } + + + + fun getPinLenAsHex( ) : String? { + + if( null == this.pinLen ) return null; + return Util.bytes2HexString(pinLen) + } + + + + fun setPinLen( bytes : ByteArray ) : Data { + + this.pinLen = bytes + return this + } + + + + fun getDPinAsBin( ) : ByteArray? { + + return this.dPin + } + + + + fun getDPinAsStr( ) : String? { + + if( null == this.dPin ) return null; + return String(dPin!!) + } + + + + fun getDPinAsHex( ) : String? { + + if( null == this.dPin ) return null; + return Util.bytes2HexString(dPin) + } + + + + fun setDPin( bytes : ByteArray ) : Data { + + this.dPin = bytes + return this + } + + + + fun getDPinTypeAsBin( ) : ByteArray? { + + return this.dPinType + } + + + + fun getDPinTypeAsStr( ) : String? { + + if( null == this.dPinType ) return null; + return String(dPinType!!) + } + + + + fun getDPinTypeAsHex( ) : String? { + + if( null == this.dPinType ) return null; + return Util.bytes2HexString(dPinType) + } + + + + fun setDPinType( bytes : ByteArray ) : Data { + + this.dPinType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != pinLen ){ + + + soup.put("pinLen", this.pinLen!!) + } + +if( null != dPin ){ + + + soup.put("dPin", this.dPin!!) + } + +if( null != dPinType ){ + + + soup.put("dPinType", this.dPinType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("pinLen") ){ + + + this.pinLen = (soup.get("pinLen") as PacketSection).bytes +} + + +if( soup.containsKey("dPin") ){ + + + this.dPin = (soup.get("dPin") as PacketSection).bytes +} + + +if( soup.containsKey("dPinType") ){ + + + this.dPinType = (soup.get("dPinType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4343")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4343") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOCC.kt b/src/main/java/racal/sunyard/main/dto/DTOCC.kt new file mode 100644 index 0000000..20c7253 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOCC.kt @@ -0,0 +1,1594 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOCC { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var sourceZpk : ByteArray? = null + private var purposeZpk : ByteArray? = null + private var algorithmKey : ByteArray? = null + private var sca : ByteArray? = null + private var dca : ByteArray? = null + private var businessKey : ByteArray? = null + private var maxLength : ByteArray? = null + private var sourcePinBlock : ByteArray? = null + private var sourcePinBlockFormat : ByteArray? = null + private var purposePinBlockFormat : ByteArray? = null + private var account : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getSourceZpkAsBin( ) : ByteArray? { + + return this.sourceZpk + } + + + + fun getSourceZpkAsStr( ) : String? { + + if( null == this.sourceZpk ) return null; + return String(sourceZpk!!) + } + + + + fun getSourceZpkAsHex( ) : String? { + + if( null == this.sourceZpk ) return null; + return Util.bytes2HexString(sourceZpk) + } + + + + fun setSourceZpk( bytes : ByteArray ) : Data { + + this.sourceZpk = bytes + return this + } + + + + fun getPurposeZpkAsBin( ) : ByteArray? { + + return this.purposeZpk + } + + + + fun getPurposeZpkAsStr( ) : String? { + + if( null == this.purposeZpk ) return null; + return String(purposeZpk!!) + } + + + + fun getPurposeZpkAsHex( ) : String? { + + if( null == this.purposeZpk ) return null; + return Util.bytes2HexString(purposeZpk) + } + + + + fun setPurposeZpk( bytes : ByteArray ) : Data { + + this.purposeZpk = bytes + return this + } + + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + + fun getScaAsBin( ) : ByteArray? { + + return this.sca + } + + + + fun getScaAsStr( ) : String? { + + if( null == this.sca ) return null; + return String(sca!!) + } + + + + fun getScaAsHex( ) : String? { + + if( null == this.sca ) return null; + return Util.bytes2HexString(sca) + } + + + + fun setSca( bytes : ByteArray ) : Data { + + this.sca = bytes + return this + } + + + enum class ScaOptions( val bin : ByteArray ) { + +OPV3DES默认(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getScaCn( ) : String? { + + if( null == sca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.sca) ) ) { + + return "3DES(默认)" + +} + + +if( "32".equals(Util.bytes2HexString(this.sca) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getScaOptionIndex( ) : Int? { + + if( null == sca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.sca) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.sca) ) ) { + + return 1 + +} + + return null + } + + + + fun getDcaAsBin( ) : ByteArray? { + + return this.dca + } + + + + fun getDcaAsStr( ) : String? { + + if( null == this.dca ) return null; + return String(dca!!) + } + + + + fun getDcaAsHex( ) : String? { + + if( null == this.dca ) return null; + return Util.bytes2HexString(dca) + } + + + + fun setDca( bytes : ByteArray ) : Data { + + this.dca = bytes + return this + } + + + enum class DcaOptions( val bin : ByteArray ) { + +OPV3DES默认(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getDcaCn( ) : String? { + + if( null == dca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.dca) ) ) { + + return "3DES(默认)" + +} + + +if( "32".equals(Util.bytes2HexString(this.dca) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getDcaOptionIndex( ) : Int? { + + if( null == dca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.dca) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.dca) ) ) { + + return 1 + +} + + return null + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getMaxLengthAsBin( ) : ByteArray? { + + return this.maxLength + } + + + + fun getMaxLengthAsStr( ) : String? { + + if( null == this.maxLength ) return null; + return String(maxLength!!) + } + + + + fun getMaxLengthAsHex( ) : String? { + + if( null == this.maxLength ) return null; + return Util.bytes2HexString(maxLength) + } + + + + fun setMaxLength( bytes : ByteArray ) : Data { + + this.maxLength = bytes + return this + } + + + + fun getSourcePinBlockAsBin( ) : ByteArray? { + + return this.sourcePinBlock + } + + + + fun getSourcePinBlockAsStr( ) : String? { + + if( null == this.sourcePinBlock ) return null; + return String(sourcePinBlock!!) + } + + + + fun getSourcePinBlockAsHex( ) : String? { + + if( null == this.sourcePinBlock ) return null; + return Util.bytes2HexString(sourcePinBlock) + } + + + + fun setSourcePinBlock( bytes : ByteArray ) : Data { + + this.sourcePinBlock = bytes + return this + } + + + + fun getSourcePinBlockFormatAsBin( ) : ByteArray? { + + return this.sourcePinBlockFormat + } + + + + fun getSourcePinBlockFormatAsStr( ) : String? { + + if( null == this.sourcePinBlockFormat ) return null; + return String(sourcePinBlockFormat!!) + } + + + + fun getSourcePinBlockFormatAsHex( ) : String? { + + if( null == this.sourcePinBlockFormat ) return null; + return Util.bytes2HexString(sourcePinBlockFormat) + } + + + + fun setSourcePinBlockFormat( bytes : ByteArray ) : Data { + + this.sourcePinBlockFormat = bytes + return this + } + + + + fun getPurposePinBlockFormatAsBin( ) : ByteArray? { + + return this.purposePinBlockFormat + } + + + + fun getPurposePinBlockFormatAsStr( ) : String? { + + if( null == this.purposePinBlockFormat ) return null; + return String(purposePinBlockFormat!!) + } + + + + fun getPurposePinBlockFormatAsHex( ) : String? { + + if( null == this.purposePinBlockFormat ) return null; + return Util.bytes2HexString(purposePinBlockFormat) + } + + + + fun setPurposePinBlockFormat( bytes : ByteArray ) : Data { + + this.purposePinBlockFormat = bytes + return this + } + + + + fun getAccountAsBin( ) : ByteArray? { + + return this.account + } + + + + fun getAccountAsStr( ) : String? { + + if( null == this.account ) return null; + return String(account!!) + } + + + + fun getAccountAsHex( ) : String? { + + if( null == this.account ) return null; + return Util.bytes2HexString(account) + } + + + + fun setAccount( bytes : ByteArray ) : Data { + + this.account = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != sourceZpk ){ + + + soup.put("sourceZpk", this.sourceZpk!!) + } + +if( null != purposeZpk ){ + + + soup.put("purposeZpk", this.purposeZpk!!) + } + +if( null != algorithmKey ){ + + + soup.put("algorithmKey", this.algorithmKey!!) + } + +if( null != sca ){ + + + soup.put("sca", this.sca!!) + soup.put("sca\$option", getScaOptionIndex()!!) + } + +if( null != dca ){ + + + soup.put("dca", this.dca!!) + soup.put("dca\$option", getDcaOptionIndex()!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + soup.put("maxLength", Util.hexString2Bytes("3132")) + +if( null != maxLength ){ + + + soup.put("maxLength", this.maxLength!!) + } + +if( null != sourcePinBlock ){ + + + soup.put("sourcePinBlock", this.sourcePinBlock!!) + } + +if( null != sourcePinBlockFormat ){ + + + soup.put("sourcePinBlockFormat", this.sourcePinBlockFormat!!) + } + +if( null != purposePinBlockFormat ){ + + + soup.put("purposePinBlockFormat", this.purposePinBlockFormat!!) + } + +if( null != account ){ + + + soup.put("account", this.account!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("sourceZpk") ){ + + + this.sourceZpk = (soup.get("sourceZpk") as PacketSection).bytes +} + + +if( soup.containsKey("purposeZpk") ){ + + + this.purposeZpk = (soup.get("purposeZpk") as PacketSection).bytes +} + + +if( soup.containsKey("algorithmKey") ){ + + + this.algorithmKey = (soup.get("algorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("sca") ){ + + + this.sca = (soup.get("sca") as PacketSection).bytes +} + + +if( soup.containsKey("dca") ){ + + + this.dca = (soup.get("dca") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + this.maxLength = Util.hexString2Bytes("3132") + +if( soup.containsKey("maxLength") ){ + + + this.maxLength = (soup.get("maxLength") as PacketSection).bytes +} + + +if( soup.containsKey("sourcePinBlock") ){ + + + this.sourcePinBlock = (soup.get("sourcePinBlock") as PacketSection).bytes +} + + +if( soup.containsKey("sourcePinBlockFormat") ){ + + + this.sourcePinBlockFormat = (soup.get("sourcePinBlockFormat") as PacketSection).bytes +} + + +if( soup.containsKey("purposePinBlockFormat") ){ + + + this.purposePinBlockFormat = (soup.get("purposePinBlockFormat") as PacketSection).bytes +} + + +if( soup.containsKey("account") ){ + + + this.account = (soup.get("account") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4343")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4343") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var pinLen : ByteArray? = null + private var purposePinBlock : ByteArray? = null + private var purposePinBlockFormat : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV源ZPK奇偶校验错(Util.hexString2Bytes("3130")), +OPV目的ZPK奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV帐号无效(Util.hexString2Bytes("3232")), +OPV无效PIN块格式代码(Util.hexString2Bytes("3233")), +OPVPIN小于4位或大于12位(Util.hexString2Bytes("3234")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "源 ZPK 奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "目的 ZPK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return "帐号无效" + +} + + +if( "3233".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效 PIN 块格式代码" + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return "PIN 小于 4 位或大于 12 位。" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3233".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + return null + } + + + + fun getPinLenAsBin( ) : ByteArray? { + + return this.pinLen + } + + + + fun getPinLenAsStr( ) : String? { + + if( null == this.pinLen ) return null; + return String(pinLen!!) + } + + + + fun getPinLenAsHex( ) : String? { + + if( null == this.pinLen ) return null; + return Util.bytes2HexString(pinLen) + } + + + + fun setPinLen( bytes : ByteArray ) : Data { + + this.pinLen = bytes + return this + } + + + + fun getPurposePinBlockAsBin( ) : ByteArray? { + + return this.purposePinBlock + } + + + + fun getPurposePinBlockAsStr( ) : String? { + + if( null == this.purposePinBlock ) return null; + return String(purposePinBlock!!) + } + + + + fun getPurposePinBlockAsHex( ) : String? { + + if( null == this.purposePinBlock ) return null; + return Util.bytes2HexString(purposePinBlock) + } + + + + fun setPurposePinBlock( bytes : ByteArray ) : Data { + + this.purposePinBlock = bytes + return this + } + + + + fun getPurposePinBlockFormatAsBin( ) : ByteArray? { + + return this.purposePinBlockFormat + } + + + + fun getPurposePinBlockFormatAsStr( ) : String? { + + if( null == this.purposePinBlockFormat ) return null; + return String(purposePinBlockFormat!!) + } + + + + fun getPurposePinBlockFormatAsHex( ) : String? { + + if( null == this.purposePinBlockFormat ) return null; + return Util.bytes2HexString(purposePinBlockFormat) + } + + + + fun setPurposePinBlockFormat( bytes : ByteArray ) : Data { + + this.purposePinBlockFormat = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != pinLen ){ + + + soup.put("pinLen", this.pinLen!!) + } + +if( null != purposePinBlock ){ + + + soup.put("purposePinBlock", this.purposePinBlock!!) + } + +if( null != purposePinBlockFormat ){ + + + soup.put("purposePinBlockFormat", this.purposePinBlockFormat!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("pinLen") ){ + + + this.pinLen = (soup.get("pinLen") as PacketSection).bytes +} + + +if( soup.containsKey("purposePinBlock") ){ + + + this.purposePinBlock = (soup.get("purposePinBlock") as PacketSection).bytes +} + + +if( soup.containsKey("purposePinBlockFormat") ){ + + + this.purposePinBlockFormat = (soup.get("purposePinBlockFormat") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4344")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4344") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTODE.kt b/src/main/java/racal/sunyard/main/dto/DTODE.kt new file mode 100644 index 0000000..2ad4830 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTODE.kt @@ -0,0 +1,1100 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTODE { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var pvk : ByteArray? = null + private var pin : ByteArray? = null + private var pinLen : ByteArray? = null + private var account : ByteArray? = null + private var turn : ByteArray? = null + private var pinCheck : ByteArray? = null + + + fun getPvkAsBin( ) : ByteArray? { + + return this.pvk + } + + + + fun getPvkAsStr( ) : String? { + + if( null == this.pvk ) return null; + return String(pvk!!) + } + + + + fun getPvkAsHex( ) : String? { + + if( null == this.pvk ) return null; + return Util.bytes2HexString(pvk) + } + + + + fun setPvk( bytes : ByteArray ) : Data { + + this.pvk = bytes + return this + } + + + + fun getPinAsBin( ) : ByteArray? { + + return this.pin + } + + + + fun getPinAsStr( ) : String? { + + if( null == this.pin ) return null; + return String(pin!!) + } + + + + fun getPinAsHex( ) : String? { + + if( null == this.pin ) return null; + return Util.bytes2HexString(pin) + } + + + + fun setPin( bytes : ByteArray ) : Data { + + this.pin = bytes + return this + } + + + + fun getPinLenAsBin( ) : ByteArray? { + + return this.pinLen + } + + + + fun getPinLenAsStr( ) : String? { + + if( null == this.pinLen ) return null; + return String(pinLen!!) + } + + + + fun getPinLenAsHex( ) : String? { + + if( null == this.pinLen ) return null; + return Util.bytes2HexString(pinLen) + } + + + + fun setPinLen( bytes : ByteArray ) : Data { + + this.pinLen = bytes + return this + } + + + + fun getAccountAsBin( ) : ByteArray? { + + return this.account + } + + + + fun getAccountAsStr( ) : String? { + + if( null == this.account ) return null; + return String(account!!) + } + + + + fun getAccountAsHex( ) : String? { + + if( null == this.account ) return null; + return Util.bytes2HexString(account) + } + + + + fun setAccount( bytes : ByteArray ) : Data { + + this.account = bytes + return this + } + + + + fun getTurnAsBin( ) : ByteArray? { + + return this.turn + } + + + + fun getTurnAsStr( ) : String? { + + if( null == this.turn ) return null; + return String(turn!!) + } + + + + fun getTurnAsHex( ) : String? { + + if( null == this.turn ) return null; + return Util.bytes2HexString(turn) + } + + + + fun setTurn( bytes : ByteArray ) : Data { + + this.turn = bytes + return this + } + + + + fun getPinCheckAsBin( ) : ByteArray? { + + return this.pinCheck + } + + + + fun getPinCheckAsStr( ) : String? { + + if( null == this.pinCheck ) return null; + return String(pinCheck!!) + } + + + + fun getPinCheckAsHex( ) : String? { + + if( null == this.pinCheck ) return null; + return Util.bytes2HexString(pinCheck) + } + + + + fun setPinCheck( bytes : ByteArray ) : Data { + + this.pinCheck = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != pvk ){ + + + soup.put("pvk", this.pvk!!) + } + +if( null != pin ){ + + + soup.put("pin", this.pin!!) + } + +if( null != pinLen ){ + + + soup.put("pinLen", this.pinLen!!) + } + +if( null != account ){ + + + soup.put("account", this.account!!) + } + +if( null != turn ){ + + + soup.put("turn", this.turn!!) + } + +if( null != pinCheck ){ + + + soup.put("pinCheck", this.pinCheck!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("pvk") ){ + + + this.pvk = (soup.get("pvk") as PacketSection).bytes +} + + +if( soup.containsKey("pin") ){ + + + this.pin = (soup.get("pin") as PacketSection).bytes +} + + +if( soup.containsKey("pinLen") ){ + + + this.pinLen = (soup.get("pinLen") as PacketSection).bytes +} + + +if( soup.containsKey("account") ){ + + + this.account = (soup.get("account") as PacketSection).bytes +} + + +if( soup.containsKey("turn") ){ + + + this.turn = (soup.get("turn") as PacketSection).bytes +} + + +if( soup.containsKey("pinCheck") ){ + + + this.pinCheck = (soup.get("pinCheck") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4445")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4445") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var offset : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV源ZPK奇偶校验错(Util.hexString2Bytes("3130")), +OPV目的ZPK奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV加密的PIN错误(Util.hexString2Bytes("3134")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV帐号无效(Util.hexString2Bytes("3232")), +OPV无效PIN块格式代码(Util.hexString2Bytes("3233")), +OPVPIN小于4位或大于12位(Util.hexString2Bytes("3234")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "源ZPK奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "目的ZPK奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3134".equals(Util.bytes2HexString(this.error) ) ) { + + return "加密的 PIN 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return "帐号无效" + +} + + +if( "3233".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效PIN块格式代码" + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return "PIN小于4位或大于12位" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3134".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3233".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 12 + +} + + return null + } + + + + fun getOffsetAsBin( ) : ByteArray? { + + return this.offset + } + + + + fun getOffsetAsStr( ) : String? { + + if( null == this.offset ) return null; + return String(offset!!) + } + + + + fun getOffsetAsHex( ) : String? { + + if( null == this.offset ) return null; + return Util.bytes2HexString(offset) + } + + + + fun setOffset( bytes : ByteArray ) : Data { + + this.offset = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != offset ){ + + + soup.put("offset", this.offset!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("offset") ){ + + + this.offset = (soup.get("offset") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4446")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4446") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOE0.kt b/src/main/java/racal/sunyard/main/dto/DTOE0.kt new file mode 100644 index 0000000..05bd3d3 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOE0.kt @@ -0,0 +1,2213 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOE0 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var packSn : ByteArray? = null + private var alg : ByteArray? = null + private var roundModel : ByteArray? = null + private var keyType : ByteArray? = null + private var key : ByteArray? = null + private var inType : ByteArray? = null + private var outType : ByteArray? = null + private var fullMode : ByteArray? = null + private var fullChar : ByteArray? = null + private var fullType : ByteArray? = null + private var iv : ByteArray? = null + private var msgLen : ByteArray? = null + private var msg : ByteArray? = null + + + fun getPackSnAsBin( ) : ByteArray? { + + return this.packSn + } + + + + fun getPackSnAsStr( ) : String? { + + if( null == this.packSn ) return null; + return String(packSn!!) + } + + + + fun getPackSnAsHex( ) : String? { + + if( null == this.packSn ) return null; + return Util.bytes2HexString(packSn) + } + + + + fun setPackSn( bytes : ByteArray ) : Data { + + this.packSn = bytes + return this + } + + + enum class PackSnOptions( val bin : ByteArray ) { + +OPV仅一块(Util.hexString2Bytes("30")), +OPV第一块(Util.hexString2Bytes("31")), +OPV中间块(Util.hexString2Bytes("32")), +OPV最后块(Util.hexString2Bytes("33")), + } + + fun getPackSnCn( ) : String? { + + if( null == packSn ) { return null } + +if( "30".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "仅一块" + +} + + +if( "31".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "第一块" + +} + + +if( "32".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "中间块" + +} + + +if( "33".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "最后块" + +} + + return null + } + + + + fun getPackSnOptionIndex( ) : Int? { + + if( null == packSn ) { return null } + +if( "30".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 2 + +} + + +if( "33".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 3 + +} + + return null + } + + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPVDES加密(Util.hexString2Bytes("30")), +OPVDES解密(Util.hexString2Bytes("31")), +OPVAES加密(Util.hexString2Bytes("32")), +OPVAES解密(Util.hexString2Bytes("33")), +OPVSSF33加密(Util.hexString2Bytes("34")), +OPVSSF33解密(Util.hexString2Bytes("35")), +OPVSM1加密(Util.hexString2Bytes("36")), +OPVSM1解密(Util.hexString2Bytes("37")), +OPVSM4加密(Util.hexString2Bytes("38")), +OPVSM4解密(Util.hexString2Bytes("39")), +OPVIDEA加密(Util.hexString2Bytes("41")), +OPVIDEA解密(Util.hexString2Bytes("42")), +OPVAES256加密(Util.hexString2Bytes("43")), +OPVAES256解密(Util.hexString2Bytes("44")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "DES加密" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "DES解密" + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return "AES加密" + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return "AES解密" + +} + + +if( "34".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SSF33 加密" + +} + + +if( "35".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SSF33 解密" + +} + + +if( "36".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM1加密" + +} + + +if( "37".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM1解密" + +} + + +if( "38".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4加密" + +} + + +if( "39".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4解密" + +} + + +if( "41".equals(Util.bytes2HexString(this.alg) ) ) { + + return "IDEA 加密" + +} + + +if( "42".equals(Util.bytes2HexString(this.alg) ) ) { + + return "IDEA 解密" + +} + + +if( "43".equals(Util.bytes2HexString(this.alg) ) ) { + + return "AES256 加密" + +} + + +if( "44".equals(Util.bytes2HexString(this.alg) ) ) { + + return "AES256 解密" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return 2 + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return 3 + +} + + +if( "34".equals(Util.bytes2HexString(this.alg) ) ) { + + return 4 + +} + + +if( "35".equals(Util.bytes2HexString(this.alg) ) ) { + + return 5 + +} + + +if( "36".equals(Util.bytes2HexString(this.alg) ) ) { + + return 6 + +} + + +if( "37".equals(Util.bytes2HexString(this.alg) ) ) { + + return 7 + +} + + +if( "38".equals(Util.bytes2HexString(this.alg) ) ) { + + return 8 + +} + + +if( "39".equals(Util.bytes2HexString(this.alg) ) ) { + + return 9 + +} + + +if( "41".equals(Util.bytes2HexString(this.alg) ) ) { + + return 10 + +} + + +if( "42".equals(Util.bytes2HexString(this.alg) ) ) { + + return 11 + +} + + +if( "43".equals(Util.bytes2HexString(this.alg) ) ) { + + return 12 + +} + + +if( "44".equals(Util.bytes2HexString(this.alg) ) ) { + + return 13 + +} + + return null + } + + + + fun getRoundModelAsBin( ) : ByteArray? { + + return this.roundModel + } + + + + fun getRoundModelAsStr( ) : String? { + + if( null == this.roundModel ) return null; + return String(roundModel!!) + } + + + + fun getRoundModelAsHex( ) : String? { + + if( null == this.roundModel ) return null; + return Util.bytes2HexString(roundModel) + } + + + + fun setRoundModel( bytes : ByteArray ) : Data { + + this.roundModel = bytes + return this + } + + + enum class RoundModelOptions( val bin : ByteArray ) { + +OPVECB(Util.hexString2Bytes("31")), +OPVCBC(Util.hexString2Bytes("32")), +OPVCFB(Util.hexString2Bytes("33")), +OPVOFB(Util.hexString2Bytes("34")), + } + + fun getRoundModelCn( ) : String? { + + if( null == roundModel ) { return null } + +if( "31".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "ECB" + +} + + +if( "32".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "CBC" + +} + + +if( "33".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "CFB" + +} + + +if( "34".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "OFB" + +} + + return null + } + + + + fun getRoundModelOptionIndex( ) : Int? { + + if( null == roundModel ) { return null } + +if( "31".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 1 + +} + + +if( "33".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 2 + +} + + +if( "34".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 3 + +} + + return null + } + + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + enum class KeyTypeOptions( val bin : ByteArray ) { + +OPVZEK(Util.hexString2Bytes("30")), +OPVTEK(Util.hexString2Bytes("31")), + } + + fun getKeyTypeCn( ) : String? { + + if( null == keyType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.keyType) ) ) { + + return "ZEK" + +} + + +if( "31".equals(Util.bytes2HexString(this.keyType) ) ) { + + return "TEK" + +} + + return null + } + + + + fun getKeyTypeOptionIndex( ) : Int? { + + if( null == keyType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.keyType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.keyType) ) ) { + + return 1 + +} + + return null + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getInTypeAsBin( ) : ByteArray? { + + return this.inType + } + + + + fun getInTypeAsStr( ) : String? { + + if( null == this.inType ) return null; + return String(inType!!) + } + + + + fun getInTypeAsHex( ) : String? { + + if( null == this.inType ) return null; + return Util.bytes2HexString(inType) + } + + + + fun setInType( bytes : ByteArray ) : Data { + + this.inType = bytes + return this + } + + + enum class InTypeOptions( val bin : ByteArray ) { + +OPV二进制(Util.hexString2Bytes("30")), +OPV扩展十六进制(Util.hexString2Bytes("31")), + } + + fun getInTypeCn( ) : String? { + + if( null == inType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.inType) ) ) { + + return "二进制" + +} + + +if( "31".equals(Util.bytes2HexString(this.inType) ) ) { + + return "扩展十六进制" + +} + + return null + } + + + + fun getInTypeOptionIndex( ) : Int? { + + if( null == inType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.inType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.inType) ) ) { + + return 1 + +} + + return null + } + + + + fun getOutTypeAsBin( ) : ByteArray? { + + return this.outType + } + + + + fun getOutTypeAsStr( ) : String? { + + if( null == this.outType ) return null; + return String(outType!!) + } + + + + fun getOutTypeAsHex( ) : String? { + + if( null == this.outType ) return null; + return Util.bytes2HexString(outType) + } + + + + fun setOutType( bytes : ByteArray ) : Data { + + this.outType = bytes + return this + } + + + enum class OutTypeOptions( val bin : ByteArray ) { + +OPV二进制(Util.hexString2Bytes("30")), +OPV扩展十六进制(Util.hexString2Bytes("31")), + } + + fun getOutTypeCn( ) : String? { + + if( null == outType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.outType) ) ) { + + return "二进制" + +} + + +if( "31".equals(Util.bytes2HexString(this.outType) ) ) { + + return "扩展十六进制" + +} + + return null + } + + + + fun getOutTypeOptionIndex( ) : Int? { + + if( null == outType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.outType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.outType) ) ) { + + return 1 + +} + + return null + } + + + + fun getFullModeAsBin( ) : ByteArray? { + + return this.fullMode + } + + + + fun getFullModeAsStr( ) : String? { + + if( null == this.fullMode ) return null; + return String(fullMode!!) + } + + + + fun getFullModeAsHex( ) : String? { + + if( null == this.fullMode ) return null; + return Util.bytes2HexString(fullMode) + } + + + + fun setFullMode( bytes : ByteArray ) : Data { + + this.fullMode = bytes + return this + } + + + enum class FullModeOptions( val bin : ByteArray ) { + +OPV饥饿模式(Util.hexString2Bytes("30")), +OPV贪婪模式(Util.hexString2Bytes("31")), + } + + fun getFullModeCn( ) : String? { + + if( null == fullMode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return "饥饿模式" + +} + + +if( "31".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return "贪婪模式" + +} + + return null + } + + + + fun getFullModeOptionIndex( ) : Int? { + + if( null == fullMode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return 1 + +} + + return null + } + + + + fun getFullCharAsBin( ) : ByteArray? { + + return this.fullChar + } + + + + fun getFullCharAsStr( ) : String? { + + if( null == this.fullChar ) return null; + return String(fullChar!!) + } + + + + fun getFullCharAsHex( ) : String? { + + if( null == this.fullChar ) return null; + return Util.bytes2HexString(fullChar) + } + + + + fun setFullChar( bytes : ByteArray ) : Data { + + this.fullChar = bytes + return this + } + + + enum class FullCharOptions( val bin : ByteArray ) { + +OPV0000(Util.hexString2Bytes("30303030")), +OPV8000(Util.hexString2Bytes("38303030")), +OPV7FFF(Util.hexString2Bytes("37464646")), + } + + fun getFullCharCn( ) : String? { + + if( null == fullChar ) { return null } + +if( "30303030".equals(Util.bytes2HexString(this.fullChar) ) ) { + + return "0000" + +} + + +if( "38303030".equals(Util.bytes2HexString(this.fullChar) ) ) { + + return "8000" + +} + + +if( "37464646".equals(Util.bytes2HexString(this.fullChar) ) ) { + + return "7FFF" + +} + + return null + } + + + + fun getFullCharOptionIndex( ) : Int? { + + if( null == fullChar ) { return null } + +if( "30303030".equals(Util.bytes2HexString(this.fullChar) ) ) { + + return 0 + +} + + +if( "38303030".equals(Util.bytes2HexString(this.fullChar) ) ) { + + return 1 + +} + + +if( "37464646".equals(Util.bytes2HexString(this.fullChar) ) ) { + + return 2 + +} + + return null + } + + + + fun getFullTypeAsBin( ) : ByteArray? { + + return this.fullType + } + + + + fun getFullTypeAsStr( ) : String? { + + if( null == this.fullType ) return null; + return String(fullType!!) + } + + + + fun getFullTypeAsHex( ) : String? { + + if( null == this.fullType ) return null; + return Util.bytes2HexString(fullType) + } + + + + fun setFullType( bytes : ByteArray ) : Data { + + this.fullType = bytes + return this + } + + + enum class FullTypeOptions( val bin : ByteArray ) { + +OPV不计尾(Util.hexString2Bytes("30")), +OPV计尾(Util.hexString2Bytes("31")), +OPVpkcs(Util.hexString2Bytes("32")), + } + + fun getFullTypeCn( ) : String? { + + if( null == fullType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullType) ) ) { + + return "不计尾" + +} + + +if( "31".equals(Util.bytes2HexString(this.fullType) ) ) { + + return "计尾" + +} + + +if( "32".equals(Util.bytes2HexString(this.fullType) ) ) { + + return "pkcs" + +} + + return null + } + + + + fun getFullTypeOptionIndex( ) : Int? { + + if( null == fullType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.fullType) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.fullType) ) ) { + + return 2 + +} + + return null + } + + + + fun getIvAsBin( ) : ByteArray? { + + return this.iv + } + + + + fun getIvAsStr( ) : String? { + + if( null == this.iv ) return null; + return String(iv!!) + } + + + + fun getIvAsHex( ) : String? { + + if( null == this.iv ) return null; + return Util.bytes2HexString(iv) + } + + + + fun setIv( bytes : ByteArray ) : Data { + + this.iv = bytes + return this + } + + + + fun getMsgLenAsBin( ) : ByteArray? { + + return this.msgLen + } + + + + fun getMsgLenAsStr( ) : String? { + + if( null == this.msgLen ) return null; + return String(msgLen!!) + } + + + + fun getMsgLenAsHex( ) : String? { + + if( null == this.msgLen ) return null; + return Util.bytes2HexString(msgLen) + } + + + + fun setMsgLen( bytes : ByteArray ) : Data { + + this.msgLen = bytes + return this + } + + + + fun getMsgAsBin( ) : ByteArray? { + + return this.msg + } + + + + fun getMsgAsStr( ) : String? { + + if( null == this.msg ) return null; + return String(msg!!) + } + + + + fun getMsgAsHex( ) : String? { + + if( null == this.msg ) return null; + return Util.bytes2HexString(msg) + } + + + + fun setMsg( bytes : ByteArray ) : Data { + + this.msg = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != packSn ){ + + + soup.put("packSn", this.packSn!!) + soup.put("packSn\$option", getPackSnOptionIndex()!!) + } + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != roundModel ){ + + + soup.put("roundModel", this.roundModel!!) + soup.put("roundModel\$option", getRoundModelOptionIndex()!!) + } + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + soup.put("keyType\$option", getKeyTypeOptionIndex()!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != inType ){ + + + soup.put("inType", this.inType!!) + soup.put("inType\$option", getInTypeOptionIndex()!!) + } + +if( null != outType ){ + + + soup.put("outType", this.outType!!) + soup.put("outType\$option", getOutTypeOptionIndex()!!) + } + +if( null != fullMode ){ + + + soup.put("fullMode", this.fullMode!!) + soup.put("fullMode\$option", getFullModeOptionIndex()!!) + } + +if( null != fullChar ){ + + + soup.put("fullChar", this.fullChar!!) + soup.put("fullChar\$option", getFullCharOptionIndex()!!) + } + +if( null != fullType ){ + + + soup.put("fullType", this.fullType!!) + soup.put("fullType\$option", getFullTypeOptionIndex()!!) + } + +if( null != iv ){ + + + soup.put("iv", this.iv!!) + } + +if( null != msgLen ){ + + + soup.put("msgLen", this.msgLen!!) + } + +if( null != msg ){ + + + soup.put("msg", this.msg!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("packSn") ){ + + + this.packSn = (soup.get("packSn") as PacketSection).bytes +} + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("roundModel") ){ + + + this.roundModel = (soup.get("roundModel") as PacketSection).bytes +} + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("inType") ){ + + + this.inType = (soup.get("inType") as PacketSection).bytes +} + + +if( soup.containsKey("outType") ){ + + + this.outType = (soup.get("outType") as PacketSection).bytes +} + + +if( soup.containsKey("fullMode") ){ + + + this.fullMode = (soup.get("fullMode") as PacketSection).bytes +} + + +if( soup.containsKey("fullChar") ){ + + + this.fullChar = (soup.get("fullChar") as PacketSection).bytes +} + + +if( soup.containsKey("fullType") ){ + + + this.fullType = (soup.get("fullType") as PacketSection).bytes +} + + +if( soup.containsKey("iv") ){ + + + this.iv = (soup.get("iv") as PacketSection).bytes +} + + +if( soup.containsKey("msgLen") ){ + + + this.msgLen = (soup.get("msgLen") as PacketSection).bytes +} + + +if( soup.containsKey("msg") ){ + + + this.msg = (soup.get("msg") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4530")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4530") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var outType : ByteArray? = null + private var msgLen : ByteArray? = null + private var msg : ByteArray? = null + private var iv : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV模式标志错(Util.hexString2Bytes("3034")), +OPV未定义的方案ID(Util.hexString2Bytes("3035")), +OPV根密钥奇偶校验错(Util.hexString2Bytes("3130")), +OPV保护密钥奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV离散次数错(Util.hexString2Bytes("3334")), +OPV密钥类型错(Util.hexString2Bytes("3238")), +OPV保护密钥类型错(Util.hexString2Bytes("3530")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "模式标志错" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "未定义的方案 ID" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "根密钥奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "保护密钥奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3334".equals(Util.bytes2HexString(this.error) ) ) { + + return "离散次数错" + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥类型错" + +} + + +if( "3530".equals(Util.bytes2HexString(this.error) ) ) { + + return "保护密钥类型错" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3334".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3530".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + return null + } + + + + fun getOutTypeAsBin( ) : ByteArray? { + + return this.outType + } + + + + fun getOutTypeAsStr( ) : String? { + + if( null == this.outType ) return null; + return String(outType!!) + } + + + + fun getOutTypeAsHex( ) : String? { + + if( null == this.outType ) return null; + return Util.bytes2HexString(outType) + } + + + + fun setOutType( bytes : ByteArray ) : Data { + + this.outType = bytes + return this + } + + + enum class OutTypeOptions( val bin : ByteArray ) { + +OPV二进制(Util.hexString2Bytes("30")), +OPV扩展十六进制(Util.hexString2Bytes("31")), + } + + fun getOutTypeCn( ) : String? { + + if( null == outType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.outType) ) ) { + + return "二进制" + +} + + +if( "31".equals(Util.bytes2HexString(this.outType) ) ) { + + return "扩展十六进制" + +} + + return null + } + + + + fun getOutTypeOptionIndex( ) : Int? { + + if( null == outType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.outType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.outType) ) ) { + + return 1 + +} + + return null + } + + + + fun getMsgLenAsBin( ) : ByteArray? { + + return this.msgLen + } + + + + fun getMsgLenAsStr( ) : String? { + + if( null == this.msgLen ) return null; + return String(msgLen!!) + } + + + + fun getMsgLenAsHex( ) : String? { + + if( null == this.msgLen ) return null; + return Util.bytes2HexString(msgLen) + } + + + + fun setMsgLen( bytes : ByteArray ) : Data { + + this.msgLen = bytes + return this + } + + + + fun getMsgAsBin( ) : ByteArray? { + + return this.msg + } + + + + fun getMsgAsStr( ) : String? { + + if( null == this.msg ) return null; + return String(msg!!) + } + + + + fun getMsgAsHex( ) : String? { + + if( null == this.msg ) return null; + return Util.bytes2HexString(msg) + } + + + + fun setMsg( bytes : ByteArray ) : Data { + + this.msg = bytes + return this + } + + + + fun getIvAsBin( ) : ByteArray? { + + return this.iv + } + + + + fun getIvAsStr( ) : String? { + + if( null == this.iv ) return null; + return String(iv!!) + } + + + + fun getIvAsHex( ) : String? { + + if( null == this.iv ) return null; + return Util.bytes2HexString(iv) + } + + + + fun setIv( bytes : ByteArray ) : Data { + + this.iv = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != outType ){ + + + soup.put("outType", this.outType!!) + soup.put("outType\$option", getOutTypeOptionIndex()!!) + } + +if( null != msgLen ){ + + + soup.put("msgLen", this.msgLen!!) + } + +if( null != msg ){ + + + soup.put("msg", this.msg!!) + } + +if( null != iv ){ + + + soup.put("iv", this.iv!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("outType") ){ + + + this.outType = (soup.get("outType") as PacketSection).bytes +} + + +if( soup.containsKey("msgLen") ){ + + + this.msgLen = (soup.get("msgLen") as PacketSection).bytes +} + + +if( soup.containsKey("msg") ){ + + + this.msg = (soup.get("msg") as PacketSection).bytes +} + + +if( soup.containsKey("iv") ){ + + + this.iv = (soup.get("iv") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4531")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4531") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOE1.kt b/src/main/java/racal/sunyard/main/dto/DTOE1.kt new file mode 100644 index 0000000..9806f98 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOE1.kt @@ -0,0 +1,2213 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOE1 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var packSn : ByteArray? = null + private var alg : ByteArray? = null + private var roundModel : ByteArray? = null + private var keyType : ByteArray? = null + private var key : ByteArray? = null + private var inType : ByteArray? = null + private var outType : ByteArray? = null + private var fullMode : ByteArray? = null + private var fullChar : ByteArray? = null + private var fullType : ByteArray? = null + private var iv : ByteArray? = null + private var msgLen : ByteArray? = null + private var msg : ByteArray? = null + + + fun getPackSnAsBin( ) : ByteArray? { + + return this.packSn + } + + + + fun getPackSnAsStr( ) : String? { + + if( null == this.packSn ) return null; + return String(packSn!!) + } + + + + fun getPackSnAsHex( ) : String? { + + if( null == this.packSn ) return null; + return Util.bytes2HexString(packSn) + } + + + + fun setPackSn( bytes : ByteArray ) : Data { + + this.packSn = bytes + return this + } + + + enum class PackSnOptions( val bin : ByteArray ) { + +OPV仅一块(Util.hexString2Bytes("30")), +OPV第一块(Util.hexString2Bytes("31")), +OPV中间块(Util.hexString2Bytes("32")), +OPV最后块(Util.hexString2Bytes("33")), + } + + fun getPackSnCn( ) : String? { + + if( null == packSn ) { return null } + +if( "30".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "仅一块" + +} + + +if( "31".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "第一块" + +} + + +if( "32".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "中间块" + +} + + +if( "33".equals(Util.bytes2HexString(this.packSn) ) ) { + + return "最后块" + +} + + return null + } + + + + fun getPackSnOptionIndex( ) : Int? { + + if( null == packSn ) { return null } + +if( "30".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 2 + +} + + +if( "33".equals(Util.bytes2HexString(this.packSn) ) ) { + + return 3 + +} + + return null + } + + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPVDES加密(Util.hexString2Bytes("30")), +OPVDES解密(Util.hexString2Bytes("31")), +OPVAES加密(Util.hexString2Bytes("32")), +OPVAES解密(Util.hexString2Bytes("33")), +OPVSSF33加密(Util.hexString2Bytes("34")), +OPVSSF33解密(Util.hexString2Bytes("35")), +OPVSM1加密(Util.hexString2Bytes("36")), +OPVSM1解密(Util.hexString2Bytes("37")), +OPVSM4加密(Util.hexString2Bytes("38")), +OPVSM4解密(Util.hexString2Bytes("39")), +OPVIDEA加密(Util.hexString2Bytes("41")), +OPVIDEA解密(Util.hexString2Bytes("42")), +OPVAES256加密(Util.hexString2Bytes("43")), +OPVAES256解密(Util.hexString2Bytes("44")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "DES加密" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "DES解密" + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return "AES加密" + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return "AES解密" + +} + + +if( "34".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SSF33 加密" + +} + + +if( "35".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SSF33 解密" + +} + + +if( "36".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM1加密" + +} + + +if( "37".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM1解密" + +} + + +if( "38".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4加密" + +} + + +if( "39".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4解密" + +} + + +if( "41".equals(Util.bytes2HexString(this.alg) ) ) { + + return "IDEA 加密" + +} + + +if( "42".equals(Util.bytes2HexString(this.alg) ) ) { + + return "IDEA 解密" + +} + + +if( "43".equals(Util.bytes2HexString(this.alg) ) ) { + + return "AES256 加密" + +} + + +if( "44".equals(Util.bytes2HexString(this.alg) ) ) { + + return "AES256 解密" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return 2 + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return 3 + +} + + +if( "34".equals(Util.bytes2HexString(this.alg) ) ) { + + return 4 + +} + + +if( "35".equals(Util.bytes2HexString(this.alg) ) ) { + + return 5 + +} + + +if( "36".equals(Util.bytes2HexString(this.alg) ) ) { + + return 6 + +} + + +if( "37".equals(Util.bytes2HexString(this.alg) ) ) { + + return 7 + +} + + +if( "38".equals(Util.bytes2HexString(this.alg) ) ) { + + return 8 + +} + + +if( "39".equals(Util.bytes2HexString(this.alg) ) ) { + + return 9 + +} + + +if( "41".equals(Util.bytes2HexString(this.alg) ) ) { + + return 10 + +} + + +if( "42".equals(Util.bytes2HexString(this.alg) ) ) { + + return 11 + +} + + +if( "43".equals(Util.bytes2HexString(this.alg) ) ) { + + return 12 + +} + + +if( "44".equals(Util.bytes2HexString(this.alg) ) ) { + + return 13 + +} + + return null + } + + + + fun getRoundModelAsBin( ) : ByteArray? { + + return this.roundModel + } + + + + fun getRoundModelAsStr( ) : String? { + + if( null == this.roundModel ) return null; + return String(roundModel!!) + } + + + + fun getRoundModelAsHex( ) : String? { + + if( null == this.roundModel ) return null; + return Util.bytes2HexString(roundModel) + } + + + + fun setRoundModel( bytes : ByteArray ) : Data { + + this.roundModel = bytes + return this + } + + + enum class RoundModelOptions( val bin : ByteArray ) { + +OPVECB(Util.hexString2Bytes("31")), +OPVCBC(Util.hexString2Bytes("32")), +OPVCFB(Util.hexString2Bytes("33")), +OPVOFB(Util.hexString2Bytes("34")), + } + + fun getRoundModelCn( ) : String? { + + if( null == roundModel ) { return null } + +if( "31".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "ECB" + +} + + +if( "32".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "CBC" + +} + + +if( "33".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "CFB" + +} + + +if( "34".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "OFB" + +} + + return null + } + + + + fun getRoundModelOptionIndex( ) : Int? { + + if( null == roundModel ) { return null } + +if( "31".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 1 + +} + + +if( "33".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 2 + +} + + +if( "34".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 3 + +} + + return null + } + + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + enum class KeyTypeOptions( val bin : ByteArray ) { + +OPVZEK(Util.hexString2Bytes("30")), +OPVTEK(Util.hexString2Bytes("31")), + } + + fun getKeyTypeCn( ) : String? { + + if( null == keyType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.keyType) ) ) { + + return "ZEK" + +} + + +if( "31".equals(Util.bytes2HexString(this.keyType) ) ) { + + return "TEK" + +} + + return null + } + + + + fun getKeyTypeOptionIndex( ) : Int? { + + if( null == keyType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.keyType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.keyType) ) ) { + + return 1 + +} + + return null + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getInTypeAsBin( ) : ByteArray? { + + return this.inType + } + + + + fun getInTypeAsStr( ) : String? { + + if( null == this.inType ) return null; + return String(inType!!) + } + + + + fun getInTypeAsHex( ) : String? { + + if( null == this.inType ) return null; + return Util.bytes2HexString(inType) + } + + + + fun setInType( bytes : ByteArray ) : Data { + + this.inType = bytes + return this + } + + + enum class InTypeOptions( val bin : ByteArray ) { + +OPV二进制(Util.hexString2Bytes("30")), +OPV扩展十六进制(Util.hexString2Bytes("31")), + } + + fun getInTypeCn( ) : String? { + + if( null == inType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.inType) ) ) { + + return "二进制" + +} + + +if( "31".equals(Util.bytes2HexString(this.inType) ) ) { + + return "扩展十六进制" + +} + + return null + } + + + + fun getInTypeOptionIndex( ) : Int? { + + if( null == inType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.inType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.inType) ) ) { + + return 1 + +} + + return null + } + + + + fun getOutTypeAsBin( ) : ByteArray? { + + return this.outType + } + + + + fun getOutTypeAsStr( ) : String? { + + if( null == this.outType ) return null; + return String(outType!!) + } + + + + fun getOutTypeAsHex( ) : String? { + + if( null == this.outType ) return null; + return Util.bytes2HexString(outType) + } + + + + fun setOutType( bytes : ByteArray ) : Data { + + this.outType = bytes + return this + } + + + enum class OutTypeOptions( val bin : ByteArray ) { + +OPV二进制(Util.hexString2Bytes("30")), +OPV扩展十六进制(Util.hexString2Bytes("31")), + } + + fun getOutTypeCn( ) : String? { + + if( null == outType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.outType) ) ) { + + return "二进制" + +} + + +if( "31".equals(Util.bytes2HexString(this.outType) ) ) { + + return "扩展十六进制" + +} + + return null + } + + + + fun getOutTypeOptionIndex( ) : Int? { + + if( null == outType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.outType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.outType) ) ) { + + return 1 + +} + + return null + } + + + + fun getFullModeAsBin( ) : ByteArray? { + + return this.fullMode + } + + + + fun getFullModeAsStr( ) : String? { + + if( null == this.fullMode ) return null; + return String(fullMode!!) + } + + + + fun getFullModeAsHex( ) : String? { + + if( null == this.fullMode ) return null; + return Util.bytes2HexString(fullMode) + } + + + + fun setFullMode( bytes : ByteArray ) : Data { + + this.fullMode = bytes + return this + } + + + enum class FullModeOptions( val bin : ByteArray ) { + +OPV饥饿模式(Util.hexString2Bytes("30")), +OPV贪婪模式(Util.hexString2Bytes("31")), + } + + fun getFullModeCn( ) : String? { + + if( null == fullMode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return "饥饿模式" + +} + + +if( "31".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return "贪婪模式" + +} + + return null + } + + + + fun getFullModeOptionIndex( ) : Int? { + + if( null == fullMode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return 1 + +} + + return null + } + + + + fun getFullCharAsBin( ) : ByteArray? { + + return this.fullChar + } + + + + fun getFullCharAsStr( ) : String? { + + if( null == this.fullChar ) return null; + return String(fullChar!!) + } + + + + fun getFullCharAsHex( ) : String? { + + if( null == this.fullChar ) return null; + return Util.bytes2HexString(fullChar) + } + + + + fun setFullChar( bytes : ByteArray ) : Data { + + this.fullChar = bytes + return this + } + + + enum class FullCharOptions( val bin : ByteArray ) { + +OPV0000(Util.hexString2Bytes("30303030")), +OPV8000(Util.hexString2Bytes("38303030")), +OPV7FFF(Util.hexString2Bytes("37464646")), + } + + fun getFullCharCn( ) : String? { + + if( null == fullChar ) { return null } + +if( "30303030".equals(Util.bytes2HexString(this.fullChar) ) ) { + + return "0000" + +} + + +if( "38303030".equals(Util.bytes2HexString(this.fullChar) ) ) { + + return "8000" + +} + + +if( "37464646".equals(Util.bytes2HexString(this.fullChar) ) ) { + + return "7FFF" + +} + + return null + } + + + + fun getFullCharOptionIndex( ) : Int? { + + if( null == fullChar ) { return null } + +if( "30303030".equals(Util.bytes2HexString(this.fullChar) ) ) { + + return 0 + +} + + +if( "38303030".equals(Util.bytes2HexString(this.fullChar) ) ) { + + return 1 + +} + + +if( "37464646".equals(Util.bytes2HexString(this.fullChar) ) ) { + + return 2 + +} + + return null + } + + + + fun getFullTypeAsBin( ) : ByteArray? { + + return this.fullType + } + + + + fun getFullTypeAsStr( ) : String? { + + if( null == this.fullType ) return null; + return String(fullType!!) + } + + + + fun getFullTypeAsHex( ) : String? { + + if( null == this.fullType ) return null; + return Util.bytes2HexString(fullType) + } + + + + fun setFullType( bytes : ByteArray ) : Data { + + this.fullType = bytes + return this + } + + + enum class FullTypeOptions( val bin : ByteArray ) { + +OPV不计尾(Util.hexString2Bytes("30")), +OPV计尾(Util.hexString2Bytes("31")), +OPVpkcs(Util.hexString2Bytes("32")), + } + + fun getFullTypeCn( ) : String? { + + if( null == fullType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullType) ) ) { + + return "不计尾" + +} + + +if( "31".equals(Util.bytes2HexString(this.fullType) ) ) { + + return "计尾" + +} + + +if( "32".equals(Util.bytes2HexString(this.fullType) ) ) { + + return "pkcs" + +} + + return null + } + + + + fun getFullTypeOptionIndex( ) : Int? { + + if( null == fullType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.fullType) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.fullType) ) ) { + + return 2 + +} + + return null + } + + + + fun getIvAsBin( ) : ByteArray? { + + return this.iv + } + + + + fun getIvAsStr( ) : String? { + + if( null == this.iv ) return null; + return String(iv!!) + } + + + + fun getIvAsHex( ) : String? { + + if( null == this.iv ) return null; + return Util.bytes2HexString(iv) + } + + + + fun setIv( bytes : ByteArray ) : Data { + + this.iv = bytes + return this + } + + + + fun getMsgLenAsBin( ) : ByteArray? { + + return this.msgLen + } + + + + fun getMsgLenAsStr( ) : String? { + + if( null == this.msgLen ) return null; + return String(msgLen!!) + } + + + + fun getMsgLenAsHex( ) : String? { + + if( null == this.msgLen ) return null; + return Util.bytes2HexString(msgLen) + } + + + + fun setMsgLen( bytes : ByteArray ) : Data { + + this.msgLen = bytes + return this + } + + + + fun getMsgAsBin( ) : ByteArray? { + + return this.msg + } + + + + fun getMsgAsStr( ) : String? { + + if( null == this.msg ) return null; + return String(msg!!) + } + + + + fun getMsgAsHex( ) : String? { + + if( null == this.msg ) return null; + return Util.bytes2HexString(msg) + } + + + + fun setMsg( bytes : ByteArray ) : Data { + + this.msg = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != packSn ){ + + + soup.put("packSn", this.packSn!!) + soup.put("packSn\$option", getPackSnOptionIndex()!!) + } + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != roundModel ){ + + + soup.put("roundModel", this.roundModel!!) + soup.put("roundModel\$option", getRoundModelOptionIndex()!!) + } + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + soup.put("keyType\$option", getKeyTypeOptionIndex()!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != inType ){ + + + soup.put("inType", this.inType!!) + soup.put("inType\$option", getInTypeOptionIndex()!!) + } + +if( null != outType ){ + + + soup.put("outType", this.outType!!) + soup.put("outType\$option", getOutTypeOptionIndex()!!) + } + +if( null != fullMode ){ + + + soup.put("fullMode", this.fullMode!!) + soup.put("fullMode\$option", getFullModeOptionIndex()!!) + } + +if( null != fullChar ){ + + + soup.put("fullChar", this.fullChar!!) + soup.put("fullChar\$option", getFullCharOptionIndex()!!) + } + +if( null != fullType ){ + + + soup.put("fullType", this.fullType!!) + soup.put("fullType\$option", getFullTypeOptionIndex()!!) + } + +if( null != iv ){ + + + soup.put("iv", this.iv!!) + } + +if( null != msgLen ){ + + + soup.put("msgLen", this.msgLen!!) + } + +if( null != msg ){ + + + soup.put("msg", this.msg!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("packSn") ){ + + + this.packSn = (soup.get("packSn") as PacketSection).bytes +} + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("roundModel") ){ + + + this.roundModel = (soup.get("roundModel") as PacketSection).bytes +} + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("inType") ){ + + + this.inType = (soup.get("inType") as PacketSection).bytes +} + + +if( soup.containsKey("outType") ){ + + + this.outType = (soup.get("outType") as PacketSection).bytes +} + + +if( soup.containsKey("fullMode") ){ + + + this.fullMode = (soup.get("fullMode") as PacketSection).bytes +} + + +if( soup.containsKey("fullChar") ){ + + + this.fullChar = (soup.get("fullChar") as PacketSection).bytes +} + + +if( soup.containsKey("fullType") ){ + + + this.fullType = (soup.get("fullType") as PacketSection).bytes +} + + +if( soup.containsKey("iv") ){ + + + this.iv = (soup.get("iv") as PacketSection).bytes +} + + +if( soup.containsKey("msgLen") ){ + + + this.msgLen = (soup.get("msgLen") as PacketSection).bytes +} + + +if( soup.containsKey("msg") ){ + + + this.msg = (soup.get("msg") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4531")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4531") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var outType : ByteArray? = null + private var msgLen : ByteArray? = null + private var msg : ByteArray? = null + private var iv : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV模式标志错(Util.hexString2Bytes("3034")), +OPV未定义的方案ID(Util.hexString2Bytes("3035")), +OPV根密钥奇偶校验错(Util.hexString2Bytes("3130")), +OPV保护密钥奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV离散次数错(Util.hexString2Bytes("3334")), +OPV密钥类型错(Util.hexString2Bytes("3238")), +OPV保护密钥类型错(Util.hexString2Bytes("3530")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "模式标志错" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "未定义的方案 ID" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "根密钥奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "保护密钥奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3334".equals(Util.bytes2HexString(this.error) ) ) { + + return "离散次数错" + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥类型错" + +} + + +if( "3530".equals(Util.bytes2HexString(this.error) ) ) { + + return "保护密钥类型错" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3334".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3530".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + return null + } + + + + fun getOutTypeAsBin( ) : ByteArray? { + + return this.outType + } + + + + fun getOutTypeAsStr( ) : String? { + + if( null == this.outType ) return null; + return String(outType!!) + } + + + + fun getOutTypeAsHex( ) : String? { + + if( null == this.outType ) return null; + return Util.bytes2HexString(outType) + } + + + + fun setOutType( bytes : ByteArray ) : Data { + + this.outType = bytes + return this + } + + + enum class OutTypeOptions( val bin : ByteArray ) { + +OPV二进制(Util.hexString2Bytes("30")), +OPV扩展十六进制(Util.hexString2Bytes("31")), + } + + fun getOutTypeCn( ) : String? { + + if( null == outType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.outType) ) ) { + + return "二进制" + +} + + +if( "31".equals(Util.bytes2HexString(this.outType) ) ) { + + return "扩展十六进制" + +} + + return null + } + + + + fun getOutTypeOptionIndex( ) : Int? { + + if( null == outType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.outType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.outType) ) ) { + + return 1 + +} + + return null + } + + + + fun getMsgLenAsBin( ) : ByteArray? { + + return this.msgLen + } + + + + fun getMsgLenAsStr( ) : String? { + + if( null == this.msgLen ) return null; + return String(msgLen!!) + } + + + + fun getMsgLenAsHex( ) : String? { + + if( null == this.msgLen ) return null; + return Util.bytes2HexString(msgLen) + } + + + + fun setMsgLen( bytes : ByteArray ) : Data { + + this.msgLen = bytes + return this + } + + + + fun getMsgAsBin( ) : ByteArray? { + + return this.msg + } + + + + fun getMsgAsStr( ) : String? { + + if( null == this.msg ) return null; + return String(msg!!) + } + + + + fun getMsgAsHex( ) : String? { + + if( null == this.msg ) return null; + return Util.bytes2HexString(msg) + } + + + + fun setMsg( bytes : ByteArray ) : Data { + + this.msg = bytes + return this + } + + + + fun getIvAsBin( ) : ByteArray? { + + return this.iv + } + + + + fun getIvAsStr( ) : String? { + + if( null == this.iv ) return null; + return String(iv!!) + } + + + + fun getIvAsHex( ) : String? { + + if( null == this.iv ) return null; + return Util.bytes2HexString(iv) + } + + + + fun setIv( bytes : ByteArray ) : Data { + + this.iv = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != outType ){ + + + soup.put("outType", this.outType!!) + soup.put("outType\$option", getOutTypeOptionIndex()!!) + } + +if( null != msgLen ){ + + + soup.put("msgLen", this.msgLen!!) + } + +if( null != msg ){ + + + soup.put("msg", this.msg!!) + } + +if( null != iv ){ + + + soup.put("iv", this.iv!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("outType") ){ + + + this.outType = (soup.get("outType") as PacketSection).bytes +} + + +if( soup.containsKey("msgLen") ){ + + + this.msgLen = (soup.get("msgLen") as PacketSection).bytes +} + + +if( soup.containsKey("msg") ){ + + + this.msg = (soup.get("msg") as PacketSection).bytes +} + + +if( soup.containsKey("iv") ){ + + + this.iv = (soup.get("iv") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4532")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4532") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOE2.kt b/src/main/java/racal/sunyard/main/dto/DTOE2.kt new file mode 100644 index 0000000..c4aaabd --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOE2.kt @@ -0,0 +1,1257 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOE2 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var algorithmId : ByteArray? = null + private var keyLength : ByteArray? = null + private var flag : ByteArray? = null + private var index : ByteArray? = null + private var startTime : ByteArray? = null + private var endTime : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getAlgorithmIdAsBin( ) : ByteArray? { + + return this.algorithmId + } + + + + fun getAlgorithmIdAsStr( ) : String? { + + if( null == this.algorithmId ) return null; + return String(algorithmId!!) + } + + + + fun getAlgorithmIdAsHex( ) : String? { + + if( null == this.algorithmId ) return null; + return Util.bytes2HexString(algorithmId) + } + + + + fun setAlgorithmId( bytes : ByteArray ) : Data { + + this.algorithmId = bytes + return this + } + + + enum class AlgorithmIdOptions( val bin : ByteArray ) { + +OPVRSA(Util.hexString2Bytes("30")), +OPVSM2(Util.hexString2Bytes("31")), + } + + fun getAlgorithmIdCn( ) : String? { + + if( null == algorithmId ) { return null } + +if( "30".equals(Util.bytes2HexString(this.algorithmId) ) ) { + + return "RSA" + +} + + +if( "31".equals(Util.bytes2HexString(this.algorithmId) ) ) { + + return "SM2" + +} + + return null + } + + + + fun getAlgorithmIdOptionIndex( ) : Int? { + + if( null == algorithmId ) { return null } + +if( "30".equals(Util.bytes2HexString(this.algorithmId) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.algorithmId) ) ) { + + return 1 + +} + + return null + } + + + + fun getKeyLengthAsBin( ) : ByteArray? { + + return this.keyLength + } + + + + fun getKeyLengthAsStr( ) : String? { + + if( null == this.keyLength ) return null; + return String(keyLength!!) + } + + + + fun getKeyLengthAsHex( ) : String? { + + if( null == this.keyLength ) return null; + return Util.bytes2HexString(keyLength) + } + + + + fun setKeyLength( bytes : ByteArray ) : Data { + + this.keyLength = bytes + return this + } + + + + fun getFlagAsBin( ) : ByteArray? { + + return this.flag + } + + + + fun getFlagAsStr( ) : String? { + + if( null == this.flag ) return null; + return String(flag!!) + } + + + + fun getFlagAsHex( ) : String? { + + if( null == this.flag ) return null; + return Util.bytes2HexString(flag) + } + + + + fun setFlag( bytes : ByteArray ) : Data { + + this.flag = bytes + return this + } + + + + fun getIndexAsBin( ) : ByteArray? { + + return this.index + } + + + + fun getIndexAsStr( ) : String? { + + if( null == this.index ) return null; + return String(index!!) + } + + + + fun getIndexAsHex( ) : String? { + + if( null == this.index ) return null; + return Util.bytes2HexString(index) + } + + + + fun setIndex( bytes : ByteArray ) : Data { + + this.index = bytes + return this + } + + + + fun getStartTimeAsBin( ) : ByteArray? { + + return this.startTime + } + + + + fun getStartTimeAsStr( ) : String? { + + if( null == this.startTime ) return null; + return String(startTime!!) + } + + + + fun getStartTimeAsHex( ) : String? { + + if( null == this.startTime ) return null; + return Util.bytes2HexString(startTime) + } + + + + fun setStartTime( bytes : ByteArray ) : Data { + + this.startTime = bytes + return this + } + + + + fun getEndTimeAsBin( ) : ByteArray? { + + return this.endTime + } + + + + fun getEndTimeAsStr( ) : String? { + + if( null == this.endTime ) return null; + return String(endTime!!) + } + + + + fun getEndTimeAsHex( ) : String? { + + if( null == this.endTime ) return null; + return Util.bytes2HexString(endTime) + } + + + + fun setEndTime( bytes : ByteArray ) : Data { + + this.endTime = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != algorithmId ){ + + + soup.put("algorithmId", this.algorithmId!!) + soup.put("algorithmId\$option", getAlgorithmIdOptionIndex()!!) + } + +if( null != keyLength ){ + + + soup.put("keyLength", this.keyLength!!) + } + +if( null != flag ){ + + + soup.put("flag", this.flag!!) + } + +if( null != index ){ + + + soup.put("index", this.index!!) + } + +if( null != startTime ){ + + + soup.put("startTime", this.startTime!!) + } + +if( null != endTime ){ + + + soup.put("endTime", this.endTime!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("algorithmId") ){ + + + this.algorithmId = (soup.get("algorithmId") as PacketSection).bytes +} + + +if( soup.containsKey("keyLength") ){ + + + this.keyLength = (soup.get("keyLength") as PacketSection).bytes +} + + +if( soup.containsKey("flag") ){ + + + this.flag = (soup.get("flag") as PacketSection).bytes +} + + +if( soup.containsKey("index") ){ + + + this.index = (soup.get("index") as PacketSection).bytes +} + + +if( soup.containsKey("startTime") ){ + + + this.startTime = (soup.get("startTime") as PacketSection).bytes +} + + +if( soup.containsKey("endTime") ){ + + + this.endTime = (soup.get("endTime") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4532")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4532") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var privateKeyLength : ByteArray? = null + private var privateKey : ByteArray? = null + private var publicKeyLength : ByteArray? = null + private var publicKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效的哈希标识(Util.hexString2Bytes("3035")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的哈希标识" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + return null + } + + + + fun getPrivateKeyLengthAsBin( ) : ByteArray? { + + return this.privateKeyLength + } + + + + fun getPrivateKeyLengthAsStr( ) : String? { + + if( null == this.privateKeyLength ) return null; + return String(privateKeyLength!!) + } + + + + fun getPrivateKeyLengthAsHex( ) : String? { + + if( null == this.privateKeyLength ) return null; + return Util.bytes2HexString(privateKeyLength) + } + + + + fun setPrivateKeyLength( bytes : ByteArray ) : Data { + + this.privateKeyLength = bytes + return this + } + + + + fun getPrivateKeyAsBin( ) : ByteArray? { + + return this.privateKey + } + + + + fun getPrivateKeyAsStr( ) : String? { + + if( null == this.privateKey ) return null; + return String(privateKey!!) + } + + + + fun getPrivateKeyAsHex( ) : String? { + + if( null == this.privateKey ) return null; + return Util.bytes2HexString(privateKey) + } + + + + fun setPrivateKey( bytes : ByteArray ) : Data { + + this.privateKey = bytes + return this + } + + + + fun getPublicKeyLengthAsBin( ) : ByteArray? { + + return this.publicKeyLength + } + + + + fun getPublicKeyLengthAsStr( ) : String? { + + if( null == this.publicKeyLength ) return null; + return String(publicKeyLength!!) + } + + + + fun getPublicKeyLengthAsHex( ) : String? { + + if( null == this.publicKeyLength ) return null; + return Util.bytes2HexString(publicKeyLength) + } + + + + fun setPublicKeyLength( bytes : ByteArray ) : Data { + + this.publicKeyLength = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != privateKeyLength ){ + + + soup.put("privateKeyLength", this.privateKeyLength!!) + } + +if( null != privateKey ){ + + + soup.put("privateKey", this.privateKey!!) + } + +if( null != publicKeyLength ){ + + + soup.put("publicKeyLength", this.publicKeyLength!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("privateKeyLength") ){ + + + this.privateKeyLength = (soup.get("privateKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("privateKey") ){ + + + this.privateKey = (soup.get("privateKey") as PacketSection).bytes +} + + +if( soup.containsKey("publicKeyLength") ){ + + + this.publicKeyLength = (soup.get("publicKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4533")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4533") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOE4.kt b/src/main/java/racal/sunyard/main/dto/DTOE4.kt new file mode 100644 index 0000000..243d6be --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOE4.kt @@ -0,0 +1,1177 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOE4 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var nid : ByteArray? = null + private var flg : ByteArray? = null + private var index : ByteArray? = null + private var startTime : ByteArray? = null + private var endTime : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getNidAsBin( ) : ByteArray? { + + return this.nid + } + + + + fun getNidAsStr( ) : String? { + + if( null == this.nid ) return null; + return String(nid!!) + } + + + + fun getNidAsHex( ) : String? { + + if( null == this.nid ) return null; + return Util.bytes2HexString(nid) + } + + + + fun setNid( bytes : ByteArray ) : Data { + + this.nid = bytes + return this + } + + + + fun getFlgAsBin( ) : ByteArray? { + + return this.flg + } + + + + fun getFlgAsStr( ) : String? { + + if( null == this.flg ) return null; + return String(flg!!) + } + + + + fun getFlgAsHex( ) : String? { + + if( null == this.flg ) return null; + return Util.bytes2HexString(flg) + } + + + + fun setFlg( bytes : ByteArray ) : Data { + + this.flg = bytes + return this + } + + + + fun getIndexAsBin( ) : ByteArray? { + + return this.index + } + + + + fun getIndexAsStr( ) : String? { + + if( null == this.index ) return null; + return String(index!!) + } + + + + fun getIndexAsHex( ) : String? { + + if( null == this.index ) return null; + return Util.bytes2HexString(index) + } + + + + fun setIndex( bytes : ByteArray ) : Data { + + this.index = bytes + return this + } + + + + fun getStartTimeAsBin( ) : ByteArray? { + + return this.startTime + } + + + + fun getStartTimeAsStr( ) : String? { + + if( null == this.startTime ) return null; + return String(startTime!!) + } + + + + fun getStartTimeAsHex( ) : String? { + + if( null == this.startTime ) return null; + return Util.bytes2HexString(startTime) + } + + + + fun setStartTime( bytes : ByteArray ) : Data { + + this.startTime = bytes + return this + } + + + + fun getEndTimeAsBin( ) : ByteArray? { + + return this.endTime + } + + + + fun getEndTimeAsStr( ) : String? { + + if( null == this.endTime ) return null; + return String(endTime!!) + } + + + + fun getEndTimeAsHex( ) : String? { + + if( null == this.endTime ) return null; + return Util.bytes2HexString(endTime) + } + + + + fun setEndTime( bytes : ByteArray ) : Data { + + this.endTime = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != nid ){ + + + soup.put("nid", this.nid!!) + } + +if( null != flg ){ + + + soup.put("flg", this.flg!!) + } + +if( null != index ){ + + + soup.put("index", this.index!!) + } + +if( null != startTime ){ + + + soup.put("startTime", this.startTime!!) + } + +if( null != endTime ){ + + + soup.put("endTime", this.endTime!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("nid") ){ + + + this.nid = (soup.get("nid") as PacketSection).bytes +} + + +if( soup.containsKey("flg") ){ + + + this.flg = (soup.get("flg") as PacketSection).bytes +} + + +if( soup.containsKey("index") ){ + + + this.index = (soup.get("index") as PacketSection).bytes +} + + +if( soup.containsKey("startTime") ){ + + + this.startTime = (soup.get("startTime") as PacketSection).bytes +} + + +if( soup.containsKey("endTime") ){ + + + this.endTime = (soup.get("endTime") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4534")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4534") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var privateKeyLength : ByteArray? = null + private var privateKey : ByteArray? = null + private var publicKeyLength : ByteArray? = null + private var publicKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效的哈希标识(Util.hexString2Bytes("3035")), +OPV生成密钥错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的哈希标识" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "生成密钥错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + return null + } + + + + fun getPrivateKeyLengthAsBin( ) : ByteArray? { + + return this.privateKeyLength + } + + + + fun getPrivateKeyLengthAsStr( ) : String? { + + if( null == this.privateKeyLength ) return null; + return String(privateKeyLength!!) + } + + + + fun getPrivateKeyLengthAsHex( ) : String? { + + if( null == this.privateKeyLength ) return null; + return Util.bytes2HexString(privateKeyLength) + } + + + + fun setPrivateKeyLength( bytes : ByteArray ) : Data { + + this.privateKeyLength = bytes + return this + } + + + + fun getPrivateKeyAsBin( ) : ByteArray? { + + return this.privateKey + } + + + + fun getPrivateKeyAsStr( ) : String? { + + if( null == this.privateKey ) return null; + return String(privateKey!!) + } + + + + fun getPrivateKeyAsHex( ) : String? { + + if( null == this.privateKey ) return null; + return Util.bytes2HexString(privateKey) + } + + + + fun setPrivateKey( bytes : ByteArray ) : Data { + + this.privateKey = bytes + return this + } + + + + fun getPublicKeyLengthAsBin( ) : ByteArray? { + + return this.publicKeyLength + } + + + + fun getPublicKeyLengthAsStr( ) : String? { + + if( null == this.publicKeyLength ) return null; + return String(publicKeyLength!!) + } + + + + fun getPublicKeyLengthAsHex( ) : String? { + + if( null == this.publicKeyLength ) return null; + return Util.bytes2HexString(publicKeyLength) + } + + + + fun setPublicKeyLength( bytes : ByteArray ) : Data { + + this.publicKeyLength = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != privateKeyLength ){ + + + soup.put("privateKeyLength", this.privateKeyLength!!) + } + +if( null != privateKey ){ + + + soup.put("privateKey", this.privateKey!!) + } + +if( null != publicKeyLength ){ + + + soup.put("publicKeyLength", this.publicKeyLength!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("privateKeyLength") ){ + + + this.privateKeyLength = (soup.get("privateKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("privateKey") ){ + + + this.privateKey = (soup.get("privateKey") as PacketSection).bytes +} + + +if( soup.containsKey("publicKeyLength") ){ + + + this.publicKeyLength = (soup.get("publicKeyLength") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4535")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4535") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOFA.kt b/src/main/java/racal/sunyard/main/dto/DTOFA.kt new file mode 100644 index 0000000..6290219 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOFA.kt @@ -0,0 +1,1282 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOFA { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var zmk : ByteArray? = null + private var zpk : ByteArray? = null + private var businessKey : ByteArray? = null + private var separator : ByteArray? = null + private var zmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getZpkAsBin( ) : ByteArray? { + + return this.zpk + } + + + + fun getZpkAsStr( ) : String? { + + if( null == this.zpk ) return null; + return String(zpk!!) + } + + + + fun getZpkAsHex( ) : String? { + + if( null == this.zpk ) return null; + return Util.bytes2HexString(zpk) + } + + + + fun setZpk( bytes : ByteArray ) : Data { + + this.zpk = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getZmkSolutionAsBin( ) : ByteArray? { + + return this.zmkSolution + } + + + + fun getZmkSolutionAsStr( ) : String? { + + if( null == this.zmkSolution ) return null; + return String(zmkSolution!!) + } + + + + fun getZmkSolutionAsHex( ) : String? { + + if( null == this.zmkSolution ) return null; + return Util.bytes2HexString(zmkSolution) + } + + + + fun setZmkSolution( bytes : ByteArray ) : Data { + + this.zmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != zpk ){ + + + soup.put("zpk", this.zpk!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != zmkSolution ){ + + + soup.put("zmkSolution", this.zmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("zpk") ){ + + + this.zpk = (soup.get("zpk") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("zmkSolution") ){ + + + this.zmkSolution = (soup.get("zmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4641")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4641") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var zpkHead : ByteArray? = null + private var zpk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV密钥奇偶校验错仅仅是报告错误并不影响结果(Util.hexString2Bytes("3031")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPV全0的ZPK为偶校验终止运行(Util.hexString2Bytes("3131")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错,仅仅是报告错误,并不影响结果" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "全 0 的 ZPK 为偶校验(终止运行)" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getZpkHeadAsBin( ) : ByteArray? { + + return this.zpkHead + } + + + + fun getZpkHeadAsStr( ) : String? { + + if( null == this.zpkHead ) return null; + return String(zpkHead!!) + } + + + + fun getZpkHeadAsHex( ) : String? { + + if( null == this.zpkHead ) return null; + return Util.bytes2HexString(zpkHead) + } + + + + fun setZpkHead( bytes : ByteArray ) : Data { + + this.zpkHead = bytes + return this + } + + + + fun getZpkAsBin( ) : ByteArray? { + + return this.zpk + } + + + + fun getZpkAsStr( ) : String? { + + if( null == this.zpk ) return null; + return String(zpk!!) + } + + + + fun getZpkAsHex( ) : String? { + + if( null == this.zpk ) return null; + return Util.bytes2HexString(zpk) + } + + + + fun setZpk( bytes : ByteArray ) : Data { + + this.zpk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != zpkHead ){ + + + soup.put("zpkHead", this.zpkHead!!) + } + +if( null != zpk ){ + + + soup.put("zpk", this.zpk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("zpkHead") ){ + + + this.zpkHead = (soup.get("zpkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zpk") ){ + + + this.zpk = (soup.get("zpk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4642")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4642") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOFC.kt b/src/main/java/racal/sunyard/main/dto/DTOFC.kt new file mode 100644 index 0000000..a50edff --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOFC.kt @@ -0,0 +1,1252 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOFC { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var zmk : ByteArray? = null + private var tmk : ByteArray? = null + private var businessKey : ByteArray? = null + private var separator : ByteArray? = null + private var zmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getTmkAsBin( ) : ByteArray? { + + return this.tmk + } + + + + fun getTmkAsStr( ) : String? { + + if( null == this.tmk ) return null; + return String(tmk!!) + } + + + + fun getTmkAsHex( ) : String? { + + if( null == this.tmk ) return null; + return Util.bytes2HexString(tmk) + } + + + + fun setTmk( bytes : ByteArray ) : Data { + + this.tmk = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getZmkSolutionAsBin( ) : ByteArray? { + + return this.zmkSolution + } + + + + fun getZmkSolutionAsStr( ) : String? { + + if( null == this.zmkSolution ) return null; + return String(zmkSolution!!) + } + + + + fun getZmkSolutionAsHex( ) : String? { + + if( null == this.zmkSolution ) return null; + return Util.bytes2HexString(zmkSolution) + } + + + + fun setZmkSolution( bytes : ByteArray ) : Data { + + this.zmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != tmk ){ + + + soup.put("tmk", this.tmk!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != zmkSolution ){ + + + soup.put("zmkSolution", this.zmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("tmk") ){ + + + this.tmk = (soup.get("tmk") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("zmkSolution") ){ + + + this.zmkSolution = (soup.get("zmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4643")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4643") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tmkHead : ByteArray? = null + private var tmkKey : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPVTMKTPK或PVK奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "TMK、 TPK 或 PVK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + return null + } + + + + fun getTmkHeadAsBin( ) : ByteArray? { + + return this.tmkHead + } + + + + fun getTmkHeadAsStr( ) : String? { + + if( null == this.tmkHead ) return null; + return String(tmkHead!!) + } + + + + fun getTmkHeadAsHex( ) : String? { + + if( null == this.tmkHead ) return null; + return Util.bytes2HexString(tmkHead) + } + + + + fun setTmkHead( bytes : ByteArray ) : Data { + + this.tmkHead = bytes + return this + } + + + + fun getTmkKeyAsBin( ) : ByteArray? { + + return this.tmkKey + } + + + + fun getTmkKeyAsStr( ) : String? { + + if( null == this.tmkKey ) return null; + return String(tmkKey!!) + } + + + + fun getTmkKeyAsHex( ) : String? { + + if( null == this.tmkKey ) return null; + return Util.bytes2HexString(tmkKey) + } + + + + fun setTmkKey( bytes : ByteArray ) : Data { + + this.tmkKey = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != tmkHead ){ + + + soup.put("tmkHead", this.tmkHead!!) + } + +if( null != tmkKey ){ + + + soup.put("tmkKey", this.tmkKey!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("tmkHead") ){ + + + this.tmkHead = (soup.get("tmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("tmkKey") ){ + + + this.tmkKey = (soup.get("tmkKey") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4644")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4644") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOFE.kt b/src/main/java/racal/sunyard/main/dto/DTOFE.kt new file mode 100644 index 0000000..3817e37 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOFE.kt @@ -0,0 +1,1267 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOFE { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var zmk : ByteArray? = null + private var tmk : ByteArray? = null + private var businessKey : ByteArray? = null + private var separator : ByteArray? = null + private var zmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getTmkAsBin( ) : ByteArray? { + + return this.tmk + } + + + + fun getTmkAsStr( ) : String? { + + if( null == this.tmk ) return null; + return String(tmk!!) + } + + + + fun getTmkAsHex( ) : String? { + + if( null == this.tmk ) return null; + return Util.bytes2HexString(tmk) + } + + + + fun setTmk( bytes : ByteArray ) : Data { + + this.tmk = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getZmkSolutionAsBin( ) : ByteArray? { + + return this.zmkSolution + } + + + + fun getZmkSolutionAsStr( ) : String? { + + if( null == this.zmkSolution ) return null; + return String(zmkSolution!!) + } + + + + fun getZmkSolutionAsHex( ) : String? { + + if( null == this.zmkSolution ) return null; + return Util.bytes2HexString(zmkSolution) + } + + + + fun setZmkSolution( bytes : ByteArray ) : Data { + + this.zmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != tmk ){ + + + soup.put("tmk", this.tmk!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != zmkSolution ){ + + + soup.put("zmkSolution", this.zmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("tmk") ){ + + + this.tmk = (soup.get("tmk") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("zmkSolution") ){ + + + this.zmkSolution = (soup.get("zmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4645")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4645") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tmkHead : ByteArray? = null + private var tmkKey : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPVTMKTPK或PVK奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "TMK、 TPK 或 PVK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + return null + } + + + + fun getTmkHeadAsBin( ) : ByteArray? { + + return this.tmkHead + } + + + + fun getTmkHeadAsStr( ) : String? { + + if( null == this.tmkHead ) return null; + return String(tmkHead!!) + } + + + + fun getTmkHeadAsHex( ) : String? { + + if( null == this.tmkHead ) return null; + return Util.bytes2HexString(tmkHead) + } + + + + fun setTmkHead( bytes : ByteArray ) : Data { + + this.tmkHead = bytes + return this + } + + + + fun getTmkKeyAsBin( ) : ByteArray? { + + return this.tmkKey + } + + + + fun getTmkKeyAsStr( ) : String? { + + if( null == this.tmkKey ) return null; + return String(tmkKey!!) + } + + + + fun getTmkKeyAsHex( ) : String? { + + if( null == this.tmkKey ) return null; + return Util.bytes2HexString(tmkKey) + } + + + + fun setTmkKey( bytes : ByteArray ) : Data { + + this.tmkKey = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != tmkHead ){ + + + soup.put("tmkHead", this.tmkHead!!) + } + +if( null != tmkKey ){ + + + soup.put("tmkKey", this.tmkKey!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("tmkHead") ){ + + + this.tmkHead = (soup.get("tmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("tmkKey") ){ + + + this.tmkKey = (soup.get("tmkKey") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4646")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4646") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOFI.kt b/src/main/java/racal/sunyard/main/dto/DTOFI.kt new file mode 100644 index 0000000..977c54e --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOFI.kt @@ -0,0 +1,1557 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOFI { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var key : ByteArray? = null + private var zmk : ByteArray? = null + private var businessKey : ByteArray? = null + private var separator : ByteArray? = null + private var zmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + enum class KeyOptions( val bin : ByteArray ) { + +OPVZEK(Util.hexString2Bytes("30")), +OPVZAK(Util.hexString2Bytes("31")), + } + + fun getKeyCn( ) : String? { + + if( null == key ) { return null } + +if( "30".equals(Util.bytes2HexString(this.key) ) ) { + + return "ZEK" + +} + + +if( "31".equals(Util.bytes2HexString(this.key) ) ) { + + return "ZAK" + +} + + return null + } + + + + fun getKeyOptionIndex( ) : Int? { + + if( null == key ) { return null } + +if( "30".equals(Util.bytes2HexString(this.key) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.key) ) ) { + + return 1 + +} + + return null + } + + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getZmkSolutionAsBin( ) : ByteArray? { + + return this.zmkSolution + } + + + + fun getZmkSolutionAsStr( ) : String? { + + if( null == this.zmkSolution ) return null; + return String(zmkSolution!!) + } + + + + fun getZmkSolutionAsHex( ) : String? { + + if( null == this.zmkSolution ) return null; + return Util.bytes2HexString(zmkSolution) + } + + + + fun setZmkSolution( bytes : ByteArray ) : Data { + + this.zmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != key ){ + + + soup.put("key", this.key!!) + soup.put("key\$option", getKeyOptionIndex()!!) + } + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != zmkSolution ){ + + + soup.put("zmkSolution", this.zmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("zmkSolution") ){ + + + this.zmkSolution = (soup.get("zmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4649")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4649") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var zekZmkHead : ByteArray? = null + private var zekZmk : ByteArray? = null + private var zekLmkHead : ByteArray? = null + private var zekLmk : ByteArray? = null + private var zakZmkHead : ByteArray? = null + private var zakZmk : ByteArray? = null + private var zakLmkHead : ByteArray? = null + private var zakLmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV第一个成份奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "第一个成份奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + return null + } + + + + fun getZekZmkHeadAsBin( ) : ByteArray? { + + return this.zekZmkHead + } + + + + fun getZekZmkHeadAsStr( ) : String? { + + if( null == this.zekZmkHead ) return null; + return String(zekZmkHead!!) + } + + + + fun getZekZmkHeadAsHex( ) : String? { + + if( null == this.zekZmkHead ) return null; + return Util.bytes2HexString(zekZmkHead) + } + + + + fun setZekZmkHead( bytes : ByteArray ) : Data { + + this.zekZmkHead = bytes + return this + } + + + + fun getZekZmkAsBin( ) : ByteArray? { + + return this.zekZmk + } + + + + fun getZekZmkAsStr( ) : String? { + + if( null == this.zekZmk ) return null; + return String(zekZmk!!) + } + + + + fun getZekZmkAsHex( ) : String? { + + if( null == this.zekZmk ) return null; + return Util.bytes2HexString(zekZmk) + } + + + + fun setZekZmk( bytes : ByteArray ) : Data { + + this.zekZmk = bytes + return this + } + + + + fun getZekLmkHeadAsBin( ) : ByteArray? { + + return this.zekLmkHead + } + + + + fun getZekLmkHeadAsStr( ) : String? { + + if( null == this.zekLmkHead ) return null; + return String(zekLmkHead!!) + } + + + + fun getZekLmkHeadAsHex( ) : String? { + + if( null == this.zekLmkHead ) return null; + return Util.bytes2HexString(zekLmkHead) + } + + + + fun setZekLmkHead( bytes : ByteArray ) : Data { + + this.zekLmkHead = bytes + return this + } + + + + fun getZekLmkAsBin( ) : ByteArray? { + + return this.zekLmk + } + + + + fun getZekLmkAsStr( ) : String? { + + if( null == this.zekLmk ) return null; + return String(zekLmk!!) + } + + + + fun getZekLmkAsHex( ) : String? { + + if( null == this.zekLmk ) return null; + return Util.bytes2HexString(zekLmk) + } + + + + fun setZekLmk( bytes : ByteArray ) : Data { + + this.zekLmk = bytes + return this + } + + + + fun getZakZmkHeadAsBin( ) : ByteArray? { + + return this.zakZmkHead + } + + + + fun getZakZmkHeadAsStr( ) : String? { + + if( null == this.zakZmkHead ) return null; + return String(zakZmkHead!!) + } + + + + fun getZakZmkHeadAsHex( ) : String? { + + if( null == this.zakZmkHead ) return null; + return Util.bytes2HexString(zakZmkHead) + } + + + + fun setZakZmkHead( bytes : ByteArray ) : Data { + + this.zakZmkHead = bytes + return this + } + + + + fun getZakZmkAsBin( ) : ByteArray? { + + return this.zakZmk + } + + + + fun getZakZmkAsStr( ) : String? { + + if( null == this.zakZmk ) return null; + return String(zakZmk!!) + } + + + + fun getZakZmkAsHex( ) : String? { + + if( null == this.zakZmk ) return null; + return Util.bytes2HexString(zakZmk) + } + + + + fun setZakZmk( bytes : ByteArray ) : Data { + + this.zakZmk = bytes + return this + } + + + + fun getZakLmkHeadAsBin( ) : ByteArray? { + + return this.zakLmkHead + } + + + + fun getZakLmkHeadAsStr( ) : String? { + + if( null == this.zakLmkHead ) return null; + return String(zakLmkHead!!) + } + + + + fun getZakLmkHeadAsHex( ) : String? { + + if( null == this.zakLmkHead ) return null; + return Util.bytes2HexString(zakLmkHead) + } + + + + fun setZakLmkHead( bytes : ByteArray ) : Data { + + this.zakLmkHead = bytes + return this + } + + + + fun getZakLmkAsBin( ) : ByteArray? { + + return this.zakLmk + } + + + + fun getZakLmkAsStr( ) : String? { + + if( null == this.zakLmk ) return null; + return String(zakLmk!!) + } + + + + fun getZakLmkAsHex( ) : String? { + + if( null == this.zakLmk ) return null; + return Util.bytes2HexString(zakLmk) + } + + + + fun setZakLmk( bytes : ByteArray ) : Data { + + this.zakLmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != zekZmkHead ){ + + + soup.put("zekZmkHead", this.zekZmkHead!!) + } + +if( null != zekZmk ){ + + + soup.put("zekZmk", this.zekZmk!!) + } + +if( null != zekLmkHead ){ + + + soup.put("zekLmkHead", this.zekLmkHead!!) + } + +if( null != zekLmk ){ + + + soup.put("zekLmk", this.zekLmk!!) + } + +if( null != zakZmkHead ){ + + + soup.put("zakZmkHead", this.zakZmkHead!!) + } + +if( null != zakZmk ){ + + + soup.put("zakZmk", this.zakZmk!!) + } + +if( null != zakLmkHead ){ + + + soup.put("zakLmkHead", this.zakLmkHead!!) + } + +if( null != zakLmk ){ + + + soup.put("zakLmk", this.zakLmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("zekZmkHead") ){ + + + this.zekZmkHead = (soup.get("zekZmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zekZmk") ){ + + + this.zekZmk = (soup.get("zekZmk") as PacketSection).bytes +} + + +if( soup.containsKey("zekLmkHead") ){ + + + this.zekLmkHead = (soup.get("zekLmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zekLmk") ){ + + + this.zekLmk = (soup.get("zekLmk") as PacketSection).bytes +} + + +if( soup.containsKey("zakZmkHead") ){ + + + this.zakZmkHead = (soup.get("zakZmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zakZmk") ){ + + + this.zakZmk = (soup.get("zakZmk") as PacketSection).bytes +} + + +if( soup.containsKey("zakLmkHead") ){ + + + this.zakLmkHead = (soup.get("zakLmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zakLmk") ){ + + + this.zakLmk = (soup.get("zakLmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("464A")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("464A") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOFK.kt b/src/main/java/racal/sunyard/main/dto/DTOFK.kt new file mode 100644 index 0000000..6ac75ce --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOFK.kt @@ -0,0 +1,1437 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOFK { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var key : ByteArray? = null + private var zmk : ByteArray? = null + private var zekOrzak : ByteArray? = null + private var businessKey : ByteArray? = null + private var separator : ByteArray? = null + private var zmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + enum class KeyOptions( val bin : ByteArray ) { + +OPVZEK(Util.hexString2Bytes("30")), +OPVZAK(Util.hexString2Bytes("31")), + } + + fun getKeyCn( ) : String? { + + if( null == key ) { return null } + +if( "30".equals(Util.bytes2HexString(this.key) ) ) { + + return "ZEK" + +} + + +if( "31".equals(Util.bytes2HexString(this.key) ) ) { + + return "ZAK" + +} + + return null + } + + + + fun getKeyOptionIndex( ) : Int? { + + if( null == key ) { return null } + +if( "30".equals(Util.bytes2HexString(this.key) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.key) ) ) { + + return 1 + +} + + return null + } + + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getZekOrzakAsBin( ) : ByteArray? { + + return this.zekOrzak + } + + + + fun getZekOrzakAsStr( ) : String? { + + if( null == this.zekOrzak ) return null; + return String(zekOrzak!!) + } + + + + fun getZekOrzakAsHex( ) : String? { + + if( null == this.zekOrzak ) return null; + return Util.bytes2HexString(zekOrzak) + } + + + + fun setZekOrzak( bytes : ByteArray ) : Data { + + this.zekOrzak = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getZmkSolutionAsBin( ) : ByteArray? { + + return this.zmkSolution + } + + + + fun getZmkSolutionAsStr( ) : String? { + + if( null == this.zmkSolution ) return null; + return String(zmkSolution!!) + } + + + + fun getZmkSolutionAsHex( ) : String? { + + if( null == this.zmkSolution ) return null; + return Util.bytes2HexString(zmkSolution) + } + + + + fun setZmkSolution( bytes : ByteArray ) : Data { + + this.zmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != key ){ + + + soup.put("key", this.key!!) + soup.put("key\$option", getKeyOptionIndex()!!) + } + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != zekOrzak ){ + + + soup.put("zekOrzak", this.zekOrzak!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != zmkSolution ){ + + + soup.put("zmkSolution", this.zmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("zekOrzak") ){ + + + this.zekOrzak = (soup.get("zekOrzak") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("zmkSolution") ){ + + + this.zmkSolution = (soup.get("zmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("464B")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("464B") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var zekLmkHead : ByteArray? = null + private var zekLmk : ByteArray? = null + private var zakLmkHead : ByteArray? = null + private var zakLmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV第一个成份奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "第一个成份奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + return null + } + + + + fun getZekLmkHeadAsBin( ) : ByteArray? { + + return this.zekLmkHead + } + + + + fun getZekLmkHeadAsStr( ) : String? { + + if( null == this.zekLmkHead ) return null; + return String(zekLmkHead!!) + } + + + + fun getZekLmkHeadAsHex( ) : String? { + + if( null == this.zekLmkHead ) return null; + return Util.bytes2HexString(zekLmkHead) + } + + + + fun setZekLmkHead( bytes : ByteArray ) : Data { + + this.zekLmkHead = bytes + return this + } + + + + fun getZekLmkAsBin( ) : ByteArray? { + + return this.zekLmk + } + + + + fun getZekLmkAsStr( ) : String? { + + if( null == this.zekLmk ) return null; + return String(zekLmk!!) + } + + + + fun getZekLmkAsHex( ) : String? { + + if( null == this.zekLmk ) return null; + return Util.bytes2HexString(zekLmk) + } + + + + fun setZekLmk( bytes : ByteArray ) : Data { + + this.zekLmk = bytes + return this + } + + + + fun getZakLmkHeadAsBin( ) : ByteArray? { + + return this.zakLmkHead + } + + + + fun getZakLmkHeadAsStr( ) : String? { + + if( null == this.zakLmkHead ) return null; + return String(zakLmkHead!!) + } + + + + fun getZakLmkHeadAsHex( ) : String? { + + if( null == this.zakLmkHead ) return null; + return Util.bytes2HexString(zakLmkHead) + } + + + + fun setZakLmkHead( bytes : ByteArray ) : Data { + + this.zakLmkHead = bytes + return this + } + + + + fun getZakLmkAsBin( ) : ByteArray? { + + return this.zakLmk + } + + + + fun getZakLmkAsStr( ) : String? { + + if( null == this.zakLmk ) return null; + return String(zakLmk!!) + } + + + + fun getZakLmkAsHex( ) : String? { + + if( null == this.zakLmk ) return null; + return Util.bytes2HexString(zakLmk) + } + + + + fun setZakLmk( bytes : ByteArray ) : Data { + + this.zakLmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != zekLmkHead ){ + + + soup.put("zekLmkHead", this.zekLmkHead!!) + } + +if( null != zekLmk ){ + + + soup.put("zekLmk", this.zekLmk!!) + } + +if( null != zakLmkHead ){ + + + soup.put("zakLmkHead", this.zakLmkHead!!) + } + +if( null != zakLmk ){ + + + soup.put("zakLmk", this.zakLmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("zekLmkHead") ){ + + + this.zekLmkHead = (soup.get("zekLmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zekLmk") ){ + + + this.zekLmk = (soup.get("zekLmk") as PacketSection).bytes +} + + +if( soup.containsKey("zakLmkHead") ){ + + + this.zakLmkHead = (soup.get("zakLmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zakLmk") ){ + + + this.zakLmk = (soup.get("zakLmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("464C")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("464C") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOFM.kt b/src/main/java/racal/sunyard/main/dto/DTOFM.kt new file mode 100644 index 0000000..51d8ebb --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOFM.kt @@ -0,0 +1,1437 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOFM { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var key : ByteArray? = null + private var zmk : ByteArray? = null + private var zekOrzak : ByteArray? = null + private var businessKey : ByteArray? = null + private var separator : ByteArray? = null + private var zmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + enum class KeyOptions( val bin : ByteArray ) { + +OPVZEK(Util.hexString2Bytes("30")), +OPVZAK(Util.hexString2Bytes("31")), + } + + fun getKeyCn( ) : String? { + + if( null == key ) { return null } + +if( "30".equals(Util.bytes2HexString(this.key) ) ) { + + return "ZEK" + +} + + +if( "31".equals(Util.bytes2HexString(this.key) ) ) { + + return "ZAK" + +} + + return null + } + + + + fun getKeyOptionIndex( ) : Int? { + + if( null == key ) { return null } + +if( "30".equals(Util.bytes2HexString(this.key) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.key) ) ) { + + return 1 + +} + + return null + } + + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getZekOrzakAsBin( ) : ByteArray? { + + return this.zekOrzak + } + + + + fun getZekOrzakAsStr( ) : String? { + + if( null == this.zekOrzak ) return null; + return String(zekOrzak!!) + } + + + + fun getZekOrzakAsHex( ) : String? { + + if( null == this.zekOrzak ) return null; + return Util.bytes2HexString(zekOrzak) + } + + + + fun setZekOrzak( bytes : ByteArray ) : Data { + + this.zekOrzak = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getZmkSolutionAsBin( ) : ByteArray? { + + return this.zmkSolution + } + + + + fun getZmkSolutionAsStr( ) : String? { + + if( null == this.zmkSolution ) return null; + return String(zmkSolution!!) + } + + + + fun getZmkSolutionAsHex( ) : String? { + + if( null == this.zmkSolution ) return null; + return Util.bytes2HexString(zmkSolution) + } + + + + fun setZmkSolution( bytes : ByteArray ) : Data { + + this.zmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != key ){ + + + soup.put("key", this.key!!) + soup.put("key\$option", getKeyOptionIndex()!!) + } + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != zekOrzak ){ + + + soup.put("zekOrzak", this.zekOrzak!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != zmkSolution ){ + + + soup.put("zmkSolution", this.zmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("zekOrzak") ){ + + + this.zekOrzak = (soup.get("zekOrzak") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("zmkSolution") ){ + + + this.zmkSolution = (soup.get("zmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("464D")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("464D") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var zekZmkHead : ByteArray? = null + private var zekZmk : ByteArray? = null + private var zakZmkHead : ByteArray? = null + private var zakZmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV第一个成份奇偶校验错(Util.hexString2Bytes("3130")), +OPV第二或第三个成份奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "第一个成份奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "第二或第三个成份奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + return null + } + + + + fun getZekZmkHeadAsBin( ) : ByteArray? { + + return this.zekZmkHead + } + + + + fun getZekZmkHeadAsStr( ) : String? { + + if( null == this.zekZmkHead ) return null; + return String(zekZmkHead!!) + } + + + + fun getZekZmkHeadAsHex( ) : String? { + + if( null == this.zekZmkHead ) return null; + return Util.bytes2HexString(zekZmkHead) + } + + + + fun setZekZmkHead( bytes : ByteArray ) : Data { + + this.zekZmkHead = bytes + return this + } + + + + fun getZekZmkAsBin( ) : ByteArray? { + + return this.zekZmk + } + + + + fun getZekZmkAsStr( ) : String? { + + if( null == this.zekZmk ) return null; + return String(zekZmk!!) + } + + + + fun getZekZmkAsHex( ) : String? { + + if( null == this.zekZmk ) return null; + return Util.bytes2HexString(zekZmk) + } + + + + fun setZekZmk( bytes : ByteArray ) : Data { + + this.zekZmk = bytes + return this + } + + + + fun getZakZmkHeadAsBin( ) : ByteArray? { + + return this.zakZmkHead + } + + + + fun getZakZmkHeadAsStr( ) : String? { + + if( null == this.zakZmkHead ) return null; + return String(zakZmkHead!!) + } + + + + fun getZakZmkHeadAsHex( ) : String? { + + if( null == this.zakZmkHead ) return null; + return Util.bytes2HexString(zakZmkHead) + } + + + + fun setZakZmkHead( bytes : ByteArray ) : Data { + + this.zakZmkHead = bytes + return this + } + + + + fun getZakZmkAsBin( ) : ByteArray? { + + return this.zakZmk + } + + + + fun getZakZmkAsStr( ) : String? { + + if( null == this.zakZmk ) return null; + return String(zakZmk!!) + } + + + + fun getZakZmkAsHex( ) : String? { + + if( null == this.zakZmk ) return null; + return Util.bytes2HexString(zakZmk) + } + + + + fun setZakZmk( bytes : ByteArray ) : Data { + + this.zakZmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != zekZmkHead ){ + + + soup.put("zekZmkHead", this.zekZmkHead!!) + } + +if( null != zekZmk ){ + + + soup.put("zekZmk", this.zekZmk!!) + } + +if( null != zakZmkHead ){ + + + soup.put("zakZmkHead", this.zakZmkHead!!) + } + +if( null != zakZmk ){ + + + soup.put("zakZmk", this.zakZmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("zekZmkHead") ){ + + + this.zekZmkHead = (soup.get("zekZmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zekZmk") ){ + + + this.zekZmk = (soup.get("zekZmk") as PacketSection).bytes +} + + +if( soup.containsKey("zakZmkHead") ){ + + + this.zakZmkHead = (soup.get("zakZmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zakZmk") ){ + + + this.zakZmk = (soup.get("zakZmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("464E")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("464E") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOGC.kt b/src/main/java/racal/sunyard/main/dto/DTOGC.kt new file mode 100644 index 0000000..594be56 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOGC.kt @@ -0,0 +1,1282 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOGC { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var zmk : ByteArray? = null + private var zpk : ByteArray? = null + private var businessKey : ByteArray? = null + private var separator : ByteArray? = null + private var zmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getZpkAsBin( ) : ByteArray? { + + return this.zpk + } + + + + fun getZpkAsStr( ) : String? { + + if( null == this.zpk ) return null; + return String(zpk!!) + } + + + + fun getZpkAsHex( ) : String? { + + if( null == this.zpk ) return null; + return Util.bytes2HexString(zpk) + } + + + + fun setZpk( bytes : ByteArray ) : Data { + + this.zpk = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getZmkSolutionAsBin( ) : ByteArray? { + + return this.zmkSolution + } + + + + fun getZmkSolutionAsStr( ) : String? { + + if( null == this.zmkSolution ) return null; + return String(zmkSolution!!) + } + + + + fun getZmkSolutionAsHex( ) : String? { + + if( null == this.zmkSolution ) return null; + return Util.bytes2HexString(zmkSolution) + } + + + + fun setZmkSolution( bytes : ByteArray ) : Data { + + this.zmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != zpk ){ + + + soup.put("zpk", this.zpk!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != zmkSolution ){ + + + soup.put("zmkSolution", this.zmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("zpk") ){ + + + this.zpk = (soup.get("zpk") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("zmkSolution") ){ + + + this.zmkSolution = (soup.get("zmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4743")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4743") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var zpkHead : ByteArray? = null + private var zpk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV密钥奇偶校验错仅仅是报告错误并不影响结果(Util.hexString2Bytes("3031")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPV全0的ZPK为偶校验终止运行(Util.hexString2Bytes("3131")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错,仅仅是报告错误,并不影响结果" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "全 0 的 ZPK 为偶校验(终止运行)" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getZpkHeadAsBin( ) : ByteArray? { + + return this.zpkHead + } + + + + fun getZpkHeadAsStr( ) : String? { + + if( null == this.zpkHead ) return null; + return String(zpkHead!!) + } + + + + fun getZpkHeadAsHex( ) : String? { + + if( null == this.zpkHead ) return null; + return Util.bytes2HexString(zpkHead) + } + + + + fun setZpkHead( bytes : ByteArray ) : Data { + + this.zpkHead = bytes + return this + } + + + + fun getZpkAsBin( ) : ByteArray? { + + return this.zpk + } + + + + fun getZpkAsStr( ) : String? { + + if( null == this.zpk ) return null; + return String(zpk!!) + } + + + + fun getZpkAsHex( ) : String? { + + if( null == this.zpk ) return null; + return Util.bytes2HexString(zpk) + } + + + + fun setZpk( bytes : ByteArray ) : Data { + + this.zpk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != zpkHead ){ + + + soup.put("zpkHead", this.zpkHead!!) + } + +if( null != zpk ){ + + + soup.put("zpk", this.zpk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("zpkHead") ){ + + + this.zpkHead = (soup.get("zpkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zpk") ){ + + + this.zpk = (soup.get("zpk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4744")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4744") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOGY.kt b/src/main/java/racal/sunyard/main/dto/DTOGY.kt new file mode 100644 index 0000000..3f1d273 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOGY.kt @@ -0,0 +1,1297 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOGY { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var num : ByteArray? = null + private var keys : ByteArray? = null + private var flag : ByteArray? = null + private var split : ByteArray? = null + private var zmk : ByteArray? = null + private var lmk : ByteArray? = null + private var kcvType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getNumAsBin( ) : ByteArray? { + + return this.num + } + + + + fun getNumAsStr( ) : String? { + + if( null == this.num ) return null; + return String(num!!) + } + + + + fun getNumAsHex( ) : String? { + + if( null == this.num ) return null; + return Util.bytes2HexString(num) + } + + + + fun setNum( bytes : ByteArray ) : Data { + + this.num = bytes + return this + } + + + + fun getKeysAsBin( ) : ByteArray? { + + return this.keys + } + + + + fun getKeysAsStr( ) : String? { + + if( null == this.keys ) return null; + return String(keys!!) + } + + + + fun getKeysAsHex( ) : String? { + + if( null == this.keys ) return null; + return Util.bytes2HexString(keys) + } + + + + fun setKeys( bytes : ByteArray ) : Data { + + this.keys = bytes + return this + } + + + + fun getFlagAsBin( ) : ByteArray? { + + return this.flag + } + + + + fun getFlagAsStr( ) : String? { + + if( null == this.flag ) return null; + return String(flag!!) + } + + + + fun getFlagAsHex( ) : String? { + + if( null == this.flag ) return null; + return Util.bytes2HexString(flag) + } + + + + fun setFlag( bytes : ByteArray ) : Data { + + this.flag = bytes + return this + } + + + + fun getSplitAsBin( ) : ByteArray? { + + return this.split + } + + + + fun getSplitAsStr( ) : String? { + + if( null == this.split ) return null; + return String(split!!) + } + + + + fun getSplitAsHex( ) : String? { + + if( null == this.split ) return null; + return Util.bytes2HexString(split) + } + + + + fun setSplit( bytes : ByteArray ) : Data { + + this.split = bytes + return this + } + + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getLmkAsBin( ) : ByteArray? { + + return this.lmk + } + + + + fun getLmkAsStr( ) : String? { + + if( null == this.lmk ) return null; + return String(lmk!!) + } + + + + fun getLmkAsHex( ) : String? { + + if( null == this.lmk ) return null; + return Util.bytes2HexString(lmk) + } + + + + fun setLmk( bytes : ByteArray ) : Data { + + this.lmk = bytes + return this + } + + + + fun getKcvTypeAsBin( ) : ByteArray? { + + return this.kcvType + } + + + + fun getKcvTypeAsStr( ) : String? { + + if( null == this.kcvType ) return null; + return String(kcvType!!) + } + + + + fun getKcvTypeAsHex( ) : String? { + + if( null == this.kcvType ) return null; + return Util.bytes2HexString(kcvType) + } + + + + fun setKcvType( bytes : ByteArray ) : Data { + + this.kcvType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != num ){ + + + soup.put("num", this.num!!) + } + +if( null != keys ){ + + + soup.put("keys", this.keys!!) + } + +if( null != flag ){ + + + soup.put("flag", this.flag!!) + } + +if( null != split ){ + + + soup.put("split", this.split!!) + } + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != lmk ){ + + + soup.put("lmk", this.lmk!!) + } + +if( null != kcvType ){ + + + soup.put("kcvType", this.kcvType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("num") ){ + + + this.num = (soup.get("num") as PacketSection).bytes +} + + +if( soup.containsKey("keys") ){ + + + this.keys = (soup.get("keys") as PacketSection).bytes +} + + +if( soup.containsKey("flag") ){ + + + this.flag = (soup.get("flag") as PacketSection).bytes +} + + +if( soup.containsKey("split") ){ + + + this.split = (soup.get("split") as PacketSection).bytes +} + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("lmk") ){ + + + this.lmk = (soup.get("lmk") as PacketSection).bytes +} + + +if( soup.containsKey("kcvType") ){ + + + this.kcvType = (soup.get("kcvType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4759")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4759") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var keyHead : ByteArray? = null + private var key : ByteArray? = null + private var kcv : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV密钥奇偶校验错(Util.hexString2Bytes("3031")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV无效的密钥类型(Util.hexString2Bytes("3238")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥类型" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getKeyHeadAsBin( ) : ByteArray? { + + return this.keyHead + } + + + + fun getKeyHeadAsStr( ) : String? { + + if( null == this.keyHead ) return null; + return String(keyHead!!) + } + + + + fun getKeyHeadAsHex( ) : String? { + + if( null == this.keyHead ) return null; + return Util.bytes2HexString(keyHead) + } + + + + fun setKeyHead( bytes : ByteArray ) : Data { + + this.keyHead = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getKcvAsBin( ) : ByteArray? { + + return this.kcv + } + + + + fun getKcvAsStr( ) : String? { + + if( null == this.kcv ) return null; + return String(kcv!!) + } + + + + fun getKcvAsHex( ) : String? { + + if( null == this.kcv ) return null; + return Util.bytes2HexString(kcv) + } + + + + fun setKcv( bytes : ByteArray ) : Data { + + this.kcv = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != keyHead ){ + + + soup.put("keyHead", this.keyHead!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != kcv ){ + + + soup.put("kcv", this.kcv!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("keyHead") ){ + + + this.keyHead = (soup.get("keyHead") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("kcv") ){ + + + this.kcv = (soup.get("kcv") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("475A")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("475A") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOHA.kt b/src/main/java/racal/sunyard/main/dto/DTOHA.kt new file mode 100644 index 0000000..9c4c9f2 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOHA.kt @@ -0,0 +1,1299 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOHA { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var tmk : ByteArray? = null + private var businessKey : ByteArray? = null + private var separator : ByteArray? = null + private var tmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getTmkAsBin( ) : ByteArray? { + + return this.tmk + } + + + + fun getTmkAsStr( ) : String? { + + if( null == this.tmk ) return null; + return String(tmk!!) + } + + + + fun getTmkAsHex( ) : String? { + + if( null == this.tmk ) return null; + return Util.bytes2HexString(tmk) + } + + + + fun setTmk( bytes : ByteArray ) : Data { + + this.tmk = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getTmkSolutionAsBin( ) : ByteArray? { + + return this.tmkSolution + } + + + + fun getTmkSolutionAsStr( ) : String? { + + if( null == this.tmkSolution ) return null; + return String(tmkSolution!!) + } + + + + fun getTmkSolutionAsHex( ) : String? { + + if( null == this.tmkSolution ) return null; + return Util.bytes2HexString(tmkSolution) + } + + + + fun setTmkSolution( bytes : ByteArray ) : Data { + + this.tmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != tmk ){ + + + soup.put("tmk", this.tmk!!) + } + soup.put("businessKey", Util.hexString2Bytes("4E")) + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != tmkSolution ){ + + + soup.put("tmkSolution", this.tmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("tmk") ){ + + + this.tmk = (soup.get("tmk") as PacketSection).bytes +} + + this.businessKey = Util.hexString2Bytes("4E") + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("tmkSolution") ){ + + + this.tmkSolution = (soup.get("tmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4841")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4841") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var takTmkHead : ByteArray? = null + private var takTmk : ByteArray? = null + private var takLmkHead : ByteArray? = null + private var takLmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV第一个成份奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "第一个成份奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + return null + } + + + + fun getTakTmkHeadAsBin( ) : ByteArray? { + + return this.takTmkHead + } + + + + fun getTakTmkHeadAsStr( ) : String? { + + if( null == this.takTmkHead ) return null; + return String(takTmkHead!!) + } + + + + fun getTakTmkHeadAsHex( ) : String? { + + if( null == this.takTmkHead ) return null; + return Util.bytes2HexString(takTmkHead) + } + + + + fun setTakTmkHead( bytes : ByteArray ) : Data { + + this.takTmkHead = bytes + return this + } + + + + fun getTakTmkAsBin( ) : ByteArray? { + + return this.takTmk + } + + + + fun getTakTmkAsStr( ) : String? { + + if( null == this.takTmk ) return null; + return String(takTmk!!) + } + + + + fun getTakTmkAsHex( ) : String? { + + if( null == this.takTmk ) return null; + return Util.bytes2HexString(takTmk) + } + + + + fun setTakTmk( bytes : ByteArray ) : Data { + + this.takTmk = bytes + return this + } + + + + fun getTakLmkHeadAsBin( ) : ByteArray? { + + return this.takLmkHead + } + + + + fun getTakLmkHeadAsStr( ) : String? { + + if( null == this.takLmkHead ) return null; + return String(takLmkHead!!) + } + + + + fun getTakLmkHeadAsHex( ) : String? { + + if( null == this.takLmkHead ) return null; + return Util.bytes2HexString(takLmkHead) + } + + + + fun setTakLmkHead( bytes : ByteArray ) : Data { + + this.takLmkHead = bytes + return this + } + + + + fun getTakLmkAsBin( ) : ByteArray? { + + return this.takLmk + } + + + + fun getTakLmkAsStr( ) : String? { + + if( null == this.takLmk ) return null; + return String(takLmk!!) + } + + + + fun getTakLmkAsHex( ) : String? { + + if( null == this.takLmk ) return null; + return Util.bytes2HexString(takLmk) + } + + + + fun setTakLmk( bytes : ByteArray ) : Data { + + this.takLmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != takTmkHead ){ + + + soup.put("takTmkHead", this.takTmkHead!!) + } + +if( null != takTmk ){ + + + soup.put("takTmk", this.takTmk!!) + } + +if( null != takLmkHead ){ + + + soup.put("takLmkHead", this.takLmkHead!!) + } + +if( null != takLmk ){ + + + soup.put("takLmk", this.takLmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("takTmkHead") ){ + + + this.takTmkHead = (soup.get("takTmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("takTmk") ){ + + + this.takTmk = (soup.get("takTmk") as PacketSection).bytes +} + + +if( soup.containsKey("takLmkHead") ){ + + + this.takLmkHead = (soup.get("takLmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("takLmk") ){ + + + this.takLmk = (soup.get("takLmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4842")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4842") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOHC.kt b/src/main/java/racal/sunyard/main/dto/DTOHC.kt new file mode 100644 index 0000000..17ad571 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOHC.kt @@ -0,0 +1,1297 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOHC { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var tmk : ByteArray? = null + private var businessKey : ByteArray? = null + private var separator : ByteArray? = null + private var tmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getTmkAsBin( ) : ByteArray? { + + return this.tmk + } + + + + fun getTmkAsStr( ) : String? { + + if( null == this.tmk ) return null; + return String(tmk!!) + } + + + + fun getTmkAsHex( ) : String? { + + if( null == this.tmk ) return null; + return Util.bytes2HexString(tmk) + } + + + + fun setTmk( bytes : ByteArray ) : Data { + + this.tmk = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getTmkSolutionAsBin( ) : ByteArray? { + + return this.tmkSolution + } + + + + fun getTmkSolutionAsStr( ) : String? { + + if( null == this.tmkSolution ) return null; + return String(tmkSolution!!) + } + + + + fun getTmkSolutionAsHex( ) : String? { + + if( null == this.tmkSolution ) return null; + return Util.bytes2HexString(tmkSolution) + } + + + + fun setTmkSolution( bytes : ByteArray ) : Data { + + this.tmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != tmk ){ + + + soup.put("tmk", this.tmk!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != tmkSolution ){ + + + soup.put("tmkSolution", this.tmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("tmk") ){ + + + this.tmk = (soup.get("tmk") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("tmkSolution") ){ + + + this.tmkSolution = (soup.get("tmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4843")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4843") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tmkHead : ByteArray? = null + private var tmkKey : ByteArray? = null + private var lmkHead : ByteArray? = null + private var lmkKey : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV第一个成份奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "第一个成份奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + return null + } + + + + fun getTmkHeadAsBin( ) : ByteArray? { + + return this.tmkHead + } + + + + fun getTmkHeadAsStr( ) : String? { + + if( null == this.tmkHead ) return null; + return String(tmkHead!!) + } + + + + fun getTmkHeadAsHex( ) : String? { + + if( null == this.tmkHead ) return null; + return Util.bytes2HexString(tmkHead) + } + + + + fun setTmkHead( bytes : ByteArray ) : Data { + + this.tmkHead = bytes + return this + } + + + + fun getTmkKeyAsBin( ) : ByteArray? { + + return this.tmkKey + } + + + + fun getTmkKeyAsStr( ) : String? { + + if( null == this.tmkKey ) return null; + return String(tmkKey!!) + } + + + + fun getTmkKeyAsHex( ) : String? { + + if( null == this.tmkKey ) return null; + return Util.bytes2HexString(tmkKey) + } + + + + fun setTmkKey( bytes : ByteArray ) : Data { + + this.tmkKey = bytes + return this + } + + + + fun getLmkHeadAsBin( ) : ByteArray? { + + return this.lmkHead + } + + + + fun getLmkHeadAsStr( ) : String? { + + if( null == this.lmkHead ) return null; + return String(lmkHead!!) + } + + + + fun getLmkHeadAsHex( ) : String? { + + if( null == this.lmkHead ) return null; + return Util.bytes2HexString(lmkHead) + } + + + + fun setLmkHead( bytes : ByteArray ) : Data { + + this.lmkHead = bytes + return this + } + + + + fun getLmkKeyAsBin( ) : ByteArray? { + + return this.lmkKey + } + + + + fun getLmkKeyAsStr( ) : String? { + + if( null == this.lmkKey ) return null; + return String(lmkKey!!) + } + + + + fun getLmkKeyAsHex( ) : String? { + + if( null == this.lmkKey ) return null; + return Util.bytes2HexString(lmkKey) + } + + + + fun setLmkKey( bytes : ByteArray ) : Data { + + this.lmkKey = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != tmkHead ){ + + + soup.put("tmkHead", this.tmkHead!!) + } + +if( null != tmkKey ){ + + + soup.put("tmkKey", this.tmkKey!!) + } + +if( null != lmkHead ){ + + + soup.put("lmkHead", this.lmkHead!!) + } + +if( null != lmkKey ){ + + + soup.put("lmkKey", this.lmkKey!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("tmkHead") ){ + + + this.tmkHead = (soup.get("tmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("tmkKey") ){ + + + this.tmkKey = (soup.get("tmkKey") as PacketSection).bytes +} + + +if( soup.containsKey("lmkHead") ){ + + + this.lmkHead = (soup.get("lmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("lmkKey") ){ + + + this.lmkKey = (soup.get("lmkKey") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4844")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4844") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOHI.kt b/src/main/java/racal/sunyard/main/dto/DTOHI.kt new file mode 100644 index 0000000..1d10b2b --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOHI.kt @@ -0,0 +1,847 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOHI { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4849")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4849") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var cpu : ByteArray? = null + private var mem : ByteArray? = null + private var disk : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV系统调用错误(Util.hexString2Bytes("3733")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3733".equals(Util.bytes2HexString(this.error) ) ) { + + return "系统调用错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3733".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + return null + } + + + + fun getCpuAsBin( ) : ByteArray? { + + return this.cpu + } + + + + fun getCpuAsStr( ) : String? { + + if( null == this.cpu ) return null; + return String(cpu!!) + } + + + + fun getCpuAsHex( ) : String? { + + if( null == this.cpu ) return null; + return Util.bytes2HexString(cpu) + } + + + + fun setCpu( bytes : ByteArray ) : Data { + + this.cpu = bytes + return this + } + + + + fun getMemAsBin( ) : ByteArray? { + + return this.mem + } + + + + fun getMemAsStr( ) : String? { + + if( null == this.mem ) return null; + return String(mem!!) + } + + + + fun getMemAsHex( ) : String? { + + if( null == this.mem ) return null; + return Util.bytes2HexString(mem) + } + + + + fun setMem( bytes : ByteArray ) : Data { + + this.mem = bytes + return this + } + + + + fun getDiskAsBin( ) : ByteArray? { + + return this.disk + } + + + + fun getDiskAsStr( ) : String? { + + if( null == this.disk ) return null; + return String(disk!!) + } + + + + fun getDiskAsHex( ) : String? { + + if( null == this.disk ) return null; + return Util.bytes2HexString(disk) + } + + + + fun setDisk( bytes : ByteArray ) : Data { + + this.disk = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != cpu ){ + + + soup.put("cpu", this.cpu!!) + } + +if( null != mem ){ + + + soup.put("mem", this.mem!!) + } + +if( null != disk ){ + + + soup.put("disk", this.disk!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("cpu") ){ + + + this.cpu = (soup.get("cpu") as PacketSection).bytes +} + + +if( soup.containsKey("mem") ){ + + + this.mem = (soup.get("mem") as PacketSection).bytes +} + + +if( soup.containsKey("disk") ){ + + + this.disk = (soup.get("disk") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("484A")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("484A") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOHV.kt b/src/main/java/racal/sunyard/main/dto/DTOHV.kt new file mode 100644 index 0000000..f99b8dc --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOHV.kt @@ -0,0 +1,937 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOHV { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var num : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getNumAsBin( ) : ByteArray? { + + return this.num + } + + + + fun getNumAsStr( ) : String? { + + if( null == this.num ) return null; + return String(num!!) + } + + + + fun getNumAsHex( ) : String? { + + if( null == this.num ) return null; + return Util.bytes2HexString(num) + } + + + + fun setNum( bytes : ByteArray ) : Data { + + this.num = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != num ){ + + + soup.put("num", this.num!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("num") ){ + + + this.num = (soup.get("num") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4856")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4856") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var name : ByteArray? = null + private var model : ByteArray? = null + private var equipNo : ByteArray? = null + private var softVersion : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV系统调用错误(Util.hexString2Bytes("3733")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3733".equals(Util.bytes2HexString(this.error) ) ) { + + return "系统调用错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3733".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + return null + } + + + + fun getNameAsBin( ) : ByteArray? { + + return this.name + } + + + + fun getNameAsStr( ) : String? { + + if( null == this.name ) return null; + return String(name!!) + } + + + + fun getNameAsHex( ) : String? { + + if( null == this.name ) return null; + return Util.bytes2HexString(name) + } + + + + fun setName( bytes : ByteArray ) : Data { + + this.name = bytes + return this + } + + + + fun getModelAsBin( ) : ByteArray? { + + return this.model + } + + + + fun getModelAsStr( ) : String? { + + if( null == this.model ) return null; + return String(model!!) + } + + + + fun getModelAsHex( ) : String? { + + if( null == this.model ) return null; + return Util.bytes2HexString(model) + } + + + + fun setModel( bytes : ByteArray ) : Data { + + this.model = bytes + return this + } + + + + fun getEquipNoAsBin( ) : ByteArray? { + + return this.equipNo + } + + + + fun getEquipNoAsStr( ) : String? { + + if( null == this.equipNo ) return null; + return String(equipNo!!) + } + + + + fun getEquipNoAsHex( ) : String? { + + if( null == this.equipNo ) return null; + return Util.bytes2HexString(equipNo) + } + + + + fun setEquipNo( bytes : ByteArray ) : Data { + + this.equipNo = bytes + return this + } + + + + fun getSoftVersionAsBin( ) : ByteArray? { + + return this.softVersion + } + + + + fun getSoftVersionAsStr( ) : String? { + + if( null == this.softVersion ) return null; + return String(softVersion!!) + } + + + + fun getSoftVersionAsHex( ) : String? { + + if( null == this.softVersion ) return null; + return Util.bytes2HexString(softVersion) + } + + + + fun setSoftVersion( bytes : ByteArray ) : Data { + + this.softVersion = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != name ){ + + + soup.put("name", this.name!!) + } + +if( null != model ){ + + + soup.put("model", this.model!!) + } + +if( null != equipNo ){ + + + soup.put("equipNo", this.equipNo!!) + } + +if( null != softVersion ){ + + + soup.put("softVersion", this.softVersion!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("name") ){ + + + this.name = (soup.get("name") as PacketSection).bytes +} + + +if( soup.containsKey("model") ){ + + + this.model = (soup.get("model") as PacketSection).bytes +} + + +if( soup.containsKey("equipNo") ){ + + + this.equipNo = (soup.get("equipNo") as PacketSection).bytes +} + + +if( soup.containsKey("softVersion") ){ + + + this.softVersion = (soup.get("softVersion") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4857")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4857") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOIA.kt b/src/main/java/racal/sunyard/main/dto/DTOIA.kt new file mode 100644 index 0000000..bdcf6ac --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOIA.kt @@ -0,0 +1,1282 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOIA { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var zmk : ByteArray? = null + private var businessKey : ByteArray? = null + private var separator : ByteArray? = null + private var zmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getZmkSolutionAsBin( ) : ByteArray? { + + return this.zmkSolution + } + + + + fun getZmkSolutionAsStr( ) : String? { + + if( null == this.zmkSolution ) return null; + return String(zmkSolution!!) + } + + + + fun getZmkSolutionAsHex( ) : String? { + + if( null == this.zmkSolution ) return null; + return Util.bytes2HexString(zmkSolution) + } + + + + fun setZmkSolution( bytes : ByteArray ) : Data { + + this.zmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != zmkSolution ){ + + + soup.put("zmkSolution", this.zmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("zmkSolution") ){ + + + this.zmkSolution = (soup.get("zmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4941")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4941") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var zpkZmkHead : ByteArray? = null + private var zpkZmk : ByteArray? = null + private var zpkLmkHead : ByteArray? = null + private var zpkLmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + return null + } + + + + fun getZpkZmkHeadAsBin( ) : ByteArray? { + + return this.zpkZmkHead + } + + + + fun getZpkZmkHeadAsStr( ) : String? { + + if( null == this.zpkZmkHead ) return null; + return String(zpkZmkHead!!) + } + + + + fun getZpkZmkHeadAsHex( ) : String? { + + if( null == this.zpkZmkHead ) return null; + return Util.bytes2HexString(zpkZmkHead) + } + + + + fun setZpkZmkHead( bytes : ByteArray ) : Data { + + this.zpkZmkHead = bytes + return this + } + + + + fun getZpkZmkAsBin( ) : ByteArray? { + + return this.zpkZmk + } + + + + fun getZpkZmkAsStr( ) : String? { + + if( null == this.zpkZmk ) return null; + return String(zpkZmk!!) + } + + + + fun getZpkZmkAsHex( ) : String? { + + if( null == this.zpkZmk ) return null; + return Util.bytes2HexString(zpkZmk) + } + + + + fun setZpkZmk( bytes : ByteArray ) : Data { + + this.zpkZmk = bytes + return this + } + + + + fun getZpkLmkHeadAsBin( ) : ByteArray? { + + return this.zpkLmkHead + } + + + + fun getZpkLmkHeadAsStr( ) : String? { + + if( null == this.zpkLmkHead ) return null; + return String(zpkLmkHead!!) + } + + + + fun getZpkLmkHeadAsHex( ) : String? { + + if( null == this.zpkLmkHead ) return null; + return Util.bytes2HexString(zpkLmkHead) + } + + + + fun setZpkLmkHead( bytes : ByteArray ) : Data { + + this.zpkLmkHead = bytes + return this + } + + + + fun getZpkLmkAsBin( ) : ByteArray? { + + return this.zpkLmk + } + + + + fun getZpkLmkAsStr( ) : String? { + + if( null == this.zpkLmk ) return null; + return String(zpkLmk!!) + } + + + + fun getZpkLmkAsHex( ) : String? { + + if( null == this.zpkLmk ) return null; + return Util.bytes2HexString(zpkLmk) + } + + + + fun setZpkLmk( bytes : ByteArray ) : Data { + + this.zpkLmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != zpkZmkHead ){ + + + soup.put("zpkZmkHead", this.zpkZmkHead!!) + } + +if( null != zpkZmk ){ + + + soup.put("zpkZmk", this.zpkZmk!!) + } + +if( null != zpkLmkHead ){ + + + soup.put("zpkLmkHead", this.zpkLmkHead!!) + } + +if( null != zpkLmk ){ + + + soup.put("zpkLmk", this.zpkLmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("zpkZmkHead") ){ + + + this.zpkZmkHead = (soup.get("zpkZmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zpkZmk") ){ + + + this.zpkZmk = (soup.get("zpkZmk") as PacketSection).bytes +} + + +if( soup.containsKey("zpkLmkHead") ){ + + + this.zpkLmkHead = (soup.get("zpkLmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("zpkLmk") ){ + + + this.zpkLmk = (soup.get("zpkLmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4942")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4942") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOJA.kt b/src/main/java/racal/sunyard/main/dto/DTOJA.kt new file mode 100644 index 0000000..74d1a4e --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOJA.kt @@ -0,0 +1,1032 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOJA { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var account : ByteArray? = null + private var pinLen : ByteArray? = null + private var algorithmKey : ByteArray? = null + private var encryptionAlg : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getAccountAsBin( ) : ByteArray? { + + return this.account + } + + + + fun getAccountAsStr( ) : String? { + + if( null == this.account ) return null; + return String(account!!) + } + + + + fun getAccountAsHex( ) : String? { + + if( null == this.account ) return null; + return Util.bytes2HexString(account) + } + + + + fun setAccount( bytes : ByteArray ) : Data { + + this.account = bytes + return this + } + + + + fun getPinLenAsBin( ) : ByteArray? { + + return this.pinLen + } + + + + fun getPinLenAsStr( ) : String? { + + if( null == this.pinLen ) return null; + return String(pinLen!!) + } + + + + fun getPinLenAsHex( ) : String? { + + if( null == this.pinLen ) return null; + return Util.bytes2HexString(pinLen) + } + + + + fun setPinLen( bytes : ByteArray ) : Data { + + this.pinLen = bytes + return this + } + + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + + fun getEncryptionAlgAsBin( ) : ByteArray? { + + return this.encryptionAlg + } + + + + fun getEncryptionAlgAsStr( ) : String? { + + if( null == this.encryptionAlg ) return null; + return String(encryptionAlg!!) + } + + + + fun getEncryptionAlgAsHex( ) : String? { + + if( null == this.encryptionAlg ) return null; + return Util.bytes2HexString(encryptionAlg) + } + + + + fun setEncryptionAlg( bytes : ByteArray ) : Data { + + this.encryptionAlg = bytes + return this + } + + + enum class EncryptionAlgOptions( val bin : ByteArray ) { + +OPV3DES默认(Util.hexString2Bytes("30")), +OPVSM4(Util.hexString2Bytes("31")), + } + + fun getEncryptionAlgCn( ) : String? { + + if( null == encryptionAlg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.encryptionAlg) ) ) { + + return "3DES(默认)" + +} + + +if( "31".equals(Util.bytes2HexString(this.encryptionAlg) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getEncryptionAlgOptionIndex( ) : Int? { + + if( null == encryptionAlg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.encryptionAlg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.encryptionAlg) ) ) { + + return 1 + +} + + return null + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != account ){ + + + soup.put("account", this.account!!) + } + +if( null != pinLen ){ + + + soup.put("pinLen", this.pinLen!!) + } + +if( null != algorithmKey ){ + + + soup.put("algorithmKey", this.algorithmKey!!) + } + +if( null != encryptionAlg ){ + + + soup.put("encryptionAlg", this.encryptionAlg!!) + soup.put("encryptionAlg\$option", getEncryptionAlgOptionIndex()!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("account") ){ + + + this.account = (soup.get("account") as PacketSection).bytes +} + + +if( soup.containsKey("pinLen") ){ + + + this.pinLen = (soup.get("pinLen") as PacketSection).bytes +} + + +if( soup.containsKey("algorithmKey") ){ + + + this.algorithmKey = (soup.get("algorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("encryptionAlg") ){ + + + this.encryptionAlg = (soup.get("encryptionAlg") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4A41")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4A41") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var pinBlock : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVPIN长度等于或大于被加密的PIN长度(Util.hexString2Bytes("3234")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return "PIN 长度等于或大于被加密的 PIN 长度。" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + return null + } + + + + fun getPinBlockAsBin( ) : ByteArray? { + + return this.pinBlock + } + + + + fun getPinBlockAsStr( ) : String? { + + if( null == this.pinBlock ) return null; + return String(pinBlock!!) + } + + + + fun getPinBlockAsHex( ) : String? { + + if( null == this.pinBlock ) return null; + return Util.bytes2HexString(pinBlock) + } + + + + fun setPinBlock( bytes : ByteArray ) : Data { + + this.pinBlock = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != pinBlock ){ + + + soup.put("pinBlock", this.pinBlock!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("pinBlock") ){ + + + this.pinBlock = (soup.get("pinBlock") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4A42")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4A42") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOJC.kt b/src/main/java/racal/sunyard/main/dto/DTOJC.kt new file mode 100644 index 0000000..cade0f5 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOJC.kt @@ -0,0 +1,1367 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOJC { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var zpk : ByteArray? = null + private var algorithmKey : ByteArray? = null + private var sca : ByteArray? = null + private var dca : ByteArray? = null + private var businessKey : ByteArray? = null + private var pinBlock : ByteArray? = null + private var pinBlockFormat : ByteArray? = null + private var account : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getZpkAsBin( ) : ByteArray? { + + return this.zpk + } + + + + fun getZpkAsStr( ) : String? { + + if( null == this.zpk ) return null; + return String(zpk!!) + } + + + + fun getZpkAsHex( ) : String? { + + if( null == this.zpk ) return null; + return Util.bytes2HexString(zpk) + } + + + + fun setZpk( bytes : ByteArray ) : Data { + + this.zpk = bytes + return this + } + + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + + fun getScaAsBin( ) : ByteArray? { + + return this.sca + } + + + + fun getScaAsStr( ) : String? { + + if( null == this.sca ) return null; + return String(sca!!) + } + + + + fun getScaAsHex( ) : String? { + + if( null == this.sca ) return null; + return Util.bytes2HexString(sca) + } + + + + fun setSca( bytes : ByteArray ) : Data { + + this.sca = bytes + return this + } + + + enum class ScaOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getScaCn( ) : String? { + + if( null == sca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.sca) ) ) { + + return "3DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.sca) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getScaOptionIndex( ) : Int? { + + if( null == sca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.sca) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.sca) ) ) { + + return 1 + +} + + return null + } + + + + fun getDcaAsBin( ) : ByteArray? { + + return this.dca + } + + + + fun getDcaAsStr( ) : String? { + + if( null == this.dca ) return null; + return String(dca!!) + } + + + + fun getDcaAsHex( ) : String? { + + if( null == this.dca ) return null; + return Util.bytes2HexString(dca) + } + + + + fun setDca( bytes : ByteArray ) : Data { + + this.dca = bytes + return this + } + + + enum class DcaOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getDcaCn( ) : String? { + + if( null == dca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.dca) ) ) { + + return "3DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.dca) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getDcaOptionIndex( ) : Int? { + + if( null == dca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.dca) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.dca) ) ) { + + return 1 + +} + + return null + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getPinBlockAsBin( ) : ByteArray? { + + return this.pinBlock + } + + + + fun getPinBlockAsStr( ) : String? { + + if( null == this.pinBlock ) return null; + return String(pinBlock!!) + } + + + + fun getPinBlockAsHex( ) : String? { + + if( null == this.pinBlock ) return null; + return Util.bytes2HexString(pinBlock) + } + + + + fun setPinBlock( bytes : ByteArray ) : Data { + + this.pinBlock = bytes + return this + } + + + + fun getPinBlockFormatAsBin( ) : ByteArray? { + + return this.pinBlockFormat + } + + + + fun getPinBlockFormatAsStr( ) : String? { + + if( null == this.pinBlockFormat ) return null; + return String(pinBlockFormat!!) + } + + + + fun getPinBlockFormatAsHex( ) : String? { + + if( null == this.pinBlockFormat ) return null; + return Util.bytes2HexString(pinBlockFormat) + } + + + + fun setPinBlockFormat( bytes : ByteArray ) : Data { + + this.pinBlockFormat = bytes + return this + } + + + + fun getAccountAsBin( ) : ByteArray? { + + return this.account + } + + + + fun getAccountAsStr( ) : String? { + + if( null == this.account ) return null; + return String(account!!) + } + + + + fun getAccountAsHex( ) : String? { + + if( null == this.account ) return null; + return Util.bytes2HexString(account) + } + + + + fun setAccount( bytes : ByteArray ) : Data { + + this.account = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != zpk ){ + + + soup.put("zpk", this.zpk!!) + } + +if( null != algorithmKey ){ + + + soup.put("algorithmKey", this.algorithmKey!!) + } + +if( null != sca ){ + + + soup.put("sca", this.sca!!) + soup.put("sca\$option", getScaOptionIndex()!!) + } + +if( null != dca ){ + + + soup.put("dca", this.dca!!) + soup.put("dca\$option", getDcaOptionIndex()!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != pinBlock ){ + + + soup.put("PinBlock", this.pinBlock!!) + } + +if( null != pinBlockFormat ){ + + + soup.put("pinBlockFormat", this.pinBlockFormat!!) + } + +if( null != account ){ + + + soup.put("account", this.account!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("zpk") ){ + + + this.zpk = (soup.get("zpk") as PacketSection).bytes +} + + +if( soup.containsKey("algorithmKey") ){ + + + this.algorithmKey = (soup.get("algorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("sca") ){ + + + this.sca = (soup.get("sca") as PacketSection).bytes +} + + +if( soup.containsKey("dca") ){ + + + this.dca = (soup.get("dca") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("PinBlock") ){ + + + this.pinBlock = (soup.get("PinBlock") as PacketSection).bytes +} + + +if( soup.containsKey("pinBlockFormat") ){ + + + this.pinBlockFormat = (soup.get("pinBlockFormat") as PacketSection).bytes +} + + +if( soup.containsKey("account") ){ + + + this.account = (soup.get("account") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4A43")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4A43") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var pinBlock : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV源TPK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVPIN块错误(Util.hexString2Bytes("3230")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV帐号无效(Util.hexString2Bytes("3232")), +OPV无效PIN块格式代码(Util.hexString2Bytes("3233")), +OPVPIN小于4位或大于12位(Util.hexString2Bytes("3234")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "源TPK奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3230".equals(Util.bytes2HexString(this.error) ) ) { + + return "PIN块错误" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return "帐号无效" + +} + + +if( "3233".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效 PIN 块格式代码" + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return "PIN 小于 4 位或大于 12 位。" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3230".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3233".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + return null + } + + + + fun getPinBlockAsBin( ) : ByteArray? { + + return this.pinBlock + } + + + + fun getPinBlockAsStr( ) : String? { + + if( null == this.pinBlock ) return null; + return String(pinBlock!!) + } + + + + fun getPinBlockAsHex( ) : String? { + + if( null == this.pinBlock ) return null; + return Util.bytes2HexString(pinBlock) + } + + + + fun setPinBlock( bytes : ByteArray ) : Data { + + this.pinBlock = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != pinBlock ){ + + + soup.put("pinBlock", this.pinBlock!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("pinBlock") ){ + + + this.pinBlock = (soup.get("pinBlock") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4A44")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4A44") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOJE.kt b/src/main/java/racal/sunyard/main/dto/DTOJE.kt new file mode 100644 index 0000000..d9b643b --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOJE.kt @@ -0,0 +1,1367 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOJE { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var zpk : ByteArray? = null + private var algorithmKey : ByteArray? = null + private var sca : ByteArray? = null + private var dca : ByteArray? = null + private var businessKey : ByteArray? = null + private var pinBlock : ByteArray? = null + private var pinBlockFormat : ByteArray? = null + private var account : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getZpkAsBin( ) : ByteArray? { + + return this.zpk + } + + + + fun getZpkAsStr( ) : String? { + + if( null == this.zpk ) return null; + return String(zpk!!) + } + + + + fun getZpkAsHex( ) : String? { + + if( null == this.zpk ) return null; + return Util.bytes2HexString(zpk) + } + + + + fun setZpk( bytes : ByteArray ) : Data { + + this.zpk = bytes + return this + } + + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + + fun getScaAsBin( ) : ByteArray? { + + return this.sca + } + + + + fun getScaAsStr( ) : String? { + + if( null == this.sca ) return null; + return String(sca!!) + } + + + + fun getScaAsHex( ) : String? { + + if( null == this.sca ) return null; + return Util.bytes2HexString(sca) + } + + + + fun setSca( bytes : ByteArray ) : Data { + + this.sca = bytes + return this + } + + + enum class ScaOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getScaCn( ) : String? { + + if( null == sca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.sca) ) ) { + + return "3DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.sca) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getScaOptionIndex( ) : Int? { + + if( null == sca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.sca) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.sca) ) ) { + + return 1 + +} + + return null + } + + + + fun getDcaAsBin( ) : ByteArray? { + + return this.dca + } + + + + fun getDcaAsStr( ) : String? { + + if( null == this.dca ) return null; + return String(dca!!) + } + + + + fun getDcaAsHex( ) : String? { + + if( null == this.dca ) return null; + return Util.bytes2HexString(dca) + } + + + + fun setDca( bytes : ByteArray ) : Data { + + this.dca = bytes + return this + } + + + enum class DcaOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getDcaCn( ) : String? { + + if( null == dca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.dca) ) ) { + + return "3DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.dca) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getDcaOptionIndex( ) : Int? { + + if( null == dca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.dca) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.dca) ) ) { + + return 1 + +} + + return null + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getPinBlockAsBin( ) : ByteArray? { + + return this.pinBlock + } + + + + fun getPinBlockAsStr( ) : String? { + + if( null == this.pinBlock ) return null; + return String(pinBlock!!) + } + + + + fun getPinBlockAsHex( ) : String? { + + if( null == this.pinBlock ) return null; + return Util.bytes2HexString(pinBlock) + } + + + + fun setPinBlock( bytes : ByteArray ) : Data { + + this.pinBlock = bytes + return this + } + + + + fun getPinBlockFormatAsBin( ) : ByteArray? { + + return this.pinBlockFormat + } + + + + fun getPinBlockFormatAsStr( ) : String? { + + if( null == this.pinBlockFormat ) return null; + return String(pinBlockFormat!!) + } + + + + fun getPinBlockFormatAsHex( ) : String? { + + if( null == this.pinBlockFormat ) return null; + return Util.bytes2HexString(pinBlockFormat) + } + + + + fun setPinBlockFormat( bytes : ByteArray ) : Data { + + this.pinBlockFormat = bytes + return this + } + + + + fun getAccountAsBin( ) : ByteArray? { + + return this.account + } + + + + fun getAccountAsStr( ) : String? { + + if( null == this.account ) return null; + return String(account!!) + } + + + + fun getAccountAsHex( ) : String? { + + if( null == this.account ) return null; + return Util.bytes2HexString(account) + } + + + + fun setAccount( bytes : ByteArray ) : Data { + + this.account = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != zpk ){ + + + soup.put("zpk", this.zpk!!) + } + +if( null != algorithmKey ){ + + + soup.put("algorithmKey", this.algorithmKey!!) + } + +if( null != sca ){ + + + soup.put("sca", this.sca!!) + soup.put("sca\$option", getScaOptionIndex()!!) + } + +if( null != dca ){ + + + soup.put("dca", this.dca!!) + soup.put("dca\$option", getDcaOptionIndex()!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != pinBlock ){ + + + soup.put("PinBlock", this.pinBlock!!) + } + +if( null != pinBlockFormat ){ + + + soup.put("pinBlockFormat", this.pinBlockFormat!!) + } + +if( null != account ){ + + + soup.put("account", this.account!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("zpk") ){ + + + this.zpk = (soup.get("zpk") as PacketSection).bytes +} + + +if( soup.containsKey("algorithmKey") ){ + + + this.algorithmKey = (soup.get("algorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("sca") ){ + + + this.sca = (soup.get("sca") as PacketSection).bytes +} + + +if( soup.containsKey("dca") ){ + + + this.dca = (soup.get("dca") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("PinBlock") ){ + + + this.pinBlock = (soup.get("PinBlock") as PacketSection).bytes +} + + +if( soup.containsKey("pinBlockFormat") ){ + + + this.pinBlockFormat = (soup.get("pinBlockFormat") as PacketSection).bytes +} + + +if( soup.containsKey("account") ){ + + + this.account = (soup.get("account") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4A45")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4A45") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var pinBlock : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV源ZPK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVPIN块错误(Util.hexString2Bytes("3230")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV帐号无效(Util.hexString2Bytes("3232")), +OPV无效PIN块格式代码(Util.hexString2Bytes("3233")), +OPVPIN小于4位或大于12位(Util.hexString2Bytes("3234")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "源 ZPK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3230".equals(Util.bytes2HexString(this.error) ) ) { + + return "PIN块错误" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return "帐号无效" + +} + + +if( "3233".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效 PIN 块格式代码" + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return "PIN 小于 4 位或大于 12 位。" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3230".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3233".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + return null + } + + + + fun getPinBlockAsBin( ) : ByteArray? { + + return this.pinBlock + } + + + + fun getPinBlockAsStr( ) : String? { + + if( null == this.pinBlock ) return null; + return String(pinBlock!!) + } + + + + fun getPinBlockAsHex( ) : String? { + + if( null == this.pinBlock ) return null; + return Util.bytes2HexString(pinBlock) + } + + + + fun setPinBlock( bytes : ByteArray ) : Data { + + this.pinBlock = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != pinBlock ){ + + + soup.put("pinBlock", this.pinBlock!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("pinBlock") ){ + + + this.pinBlock = (soup.get("pinBlock") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4A46")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4A46") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOJG.kt b/src/main/java/racal/sunyard/main/dto/DTOJG.kt new file mode 100644 index 0000000..73aa866 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOJG.kt @@ -0,0 +1,1367 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOJG { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var zpk : ByteArray? = null + private var algorithmKey : ByteArray? = null + private var sca : ByteArray? = null + private var dca : ByteArray? = null + private var businessKey : ByteArray? = null + private var pinBlock : ByteArray? = null + private var pinBlockFormat : ByteArray? = null + private var account : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getZpkAsBin( ) : ByteArray? { + + return this.zpk + } + + + + fun getZpkAsStr( ) : String? { + + if( null == this.zpk ) return null; + return String(zpk!!) + } + + + + fun getZpkAsHex( ) : String? { + + if( null == this.zpk ) return null; + return Util.bytes2HexString(zpk) + } + + + + fun setZpk( bytes : ByteArray ) : Data { + + this.zpk = bytes + return this + } + + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + + fun getScaAsBin( ) : ByteArray? { + + return this.sca + } + + + + fun getScaAsStr( ) : String? { + + if( null == this.sca ) return null; + return String(sca!!) + } + + + + fun getScaAsHex( ) : String? { + + if( null == this.sca ) return null; + return Util.bytes2HexString(sca) + } + + + + fun setSca( bytes : ByteArray ) : Data { + + this.sca = bytes + return this + } + + + enum class ScaOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getScaCn( ) : String? { + + if( null == sca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.sca) ) ) { + + return "3DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.sca) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getScaOptionIndex( ) : Int? { + + if( null == sca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.sca) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.sca) ) ) { + + return 1 + +} + + return null + } + + + + fun getDcaAsBin( ) : ByteArray? { + + return this.dca + } + + + + fun getDcaAsStr( ) : String? { + + if( null == this.dca ) return null; + return String(dca!!) + } + + + + fun getDcaAsHex( ) : String? { + + if( null == this.dca ) return null; + return Util.bytes2HexString(dca) + } + + + + fun setDca( bytes : ByteArray ) : Data { + + this.dca = bytes + return this + } + + + enum class DcaOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getDcaCn( ) : String? { + + if( null == dca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.dca) ) ) { + + return "3DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.dca) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getDcaOptionIndex( ) : Int? { + + if( null == dca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.dca) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.dca) ) ) { + + return 1 + +} + + return null + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getPinBlockAsBin( ) : ByteArray? { + + return this.pinBlock + } + + + + fun getPinBlockAsStr( ) : String? { + + if( null == this.pinBlock ) return null; + return String(pinBlock!!) + } + + + + fun getPinBlockAsHex( ) : String? { + + if( null == this.pinBlock ) return null; + return Util.bytes2HexString(pinBlock) + } + + + + fun setPinBlock( bytes : ByteArray ) : Data { + + this.pinBlock = bytes + return this + } + + + + fun getPinBlockFormatAsBin( ) : ByteArray? { + + return this.pinBlockFormat + } + + + + fun getPinBlockFormatAsStr( ) : String? { + + if( null == this.pinBlockFormat ) return null; + return String(pinBlockFormat!!) + } + + + + fun getPinBlockFormatAsHex( ) : String? { + + if( null == this.pinBlockFormat ) return null; + return Util.bytes2HexString(pinBlockFormat) + } + + + + fun setPinBlockFormat( bytes : ByteArray ) : Data { + + this.pinBlockFormat = bytes + return this + } + + + + fun getAccountAsBin( ) : ByteArray? { + + return this.account + } + + + + fun getAccountAsStr( ) : String? { + + if( null == this.account ) return null; + return String(account!!) + } + + + + fun getAccountAsHex( ) : String? { + + if( null == this.account ) return null; + return Util.bytes2HexString(account) + } + + + + fun setAccount( bytes : ByteArray ) : Data { + + this.account = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != zpk ){ + + + soup.put("zpk", this.zpk!!) + } + +if( null != algorithmKey ){ + + + soup.put("algorithmKey", this.algorithmKey!!) + } + +if( null != sca ){ + + + soup.put("sca", this.sca!!) + soup.put("sca\$option", getScaOptionIndex()!!) + } + +if( null != dca ){ + + + soup.put("dca", this.dca!!) + soup.put("dca\$option", getDcaOptionIndex()!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != pinBlock ){ + + + soup.put("PinBlock", this.pinBlock!!) + } + +if( null != pinBlockFormat ){ + + + soup.put("pinBlockFormat", this.pinBlockFormat!!) + } + +if( null != account ){ + + + soup.put("account", this.account!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("zpk") ){ + + + this.zpk = (soup.get("zpk") as PacketSection).bytes +} + + +if( soup.containsKey("algorithmKey") ){ + + + this.algorithmKey = (soup.get("algorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("sca") ){ + + + this.sca = (soup.get("sca") as PacketSection).bytes +} + + +if( soup.containsKey("dca") ){ + + + this.dca = (soup.get("dca") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("PinBlock") ){ + + + this.pinBlock = (soup.get("PinBlock") as PacketSection).bytes +} + + +if( soup.containsKey("pinBlockFormat") ){ + + + this.pinBlockFormat = (soup.get("pinBlockFormat") as PacketSection).bytes +} + + +if( soup.containsKey("account") ){ + + + this.account = (soup.get("account") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4A47")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4A47") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var pinBlock : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVZPK奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV来自主机的PIN错误(Util.hexString2Bytes("3134")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVPIN块错误(Util.hexString2Bytes("3230")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV无效PIN块格式代码(Util.hexString2Bytes("3233")), +OPVPIN小于4位或大于12位(Util.hexString2Bytes("3234")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZPK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3134".equals(Util.bytes2HexString(this.error) ) ) { + + return "来自主机的PIN错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3230".equals(Util.bytes2HexString(this.error) ) ) { + + return "PIN块错误" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3233".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效 PIN 块格式代码" + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return "PIN 小于 4 位或大于 12 位。" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3134".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3230".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3233".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3234".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + return null + } + + + + fun getPinBlockAsBin( ) : ByteArray? { + + return this.pinBlock + } + + + + fun getPinBlockAsStr( ) : String? { + + if( null == this.pinBlock ) return null; + return String(pinBlock!!) + } + + + + fun getPinBlockAsHex( ) : String? { + + if( null == this.pinBlock ) return null; + return Util.bytes2HexString(pinBlock) + } + + + + fun setPinBlock( bytes : ByteArray ) : Data { + + this.pinBlock = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != pinBlock ){ + + + soup.put("pinBlock", this.pinBlock!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("pinBlock") ){ + + + this.pinBlock = (soup.get("pinBlock") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4A48")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4A48") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOLB.kt b/src/main/java/racal/sunyard/main/dto/DTOLB.kt new file mode 100644 index 0000000..45a5413 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOLB.kt @@ -0,0 +1,1147 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOLB { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var indexFlag : ByteArray? = null + private var index : ByteArray? = null + private var key : ByteArray? = null + private var checkFlag : ByteArray? = null + private var checkValue : ByteArray? = null + private var startTime : ByteArray? = null + private var endTime : ByteArray? = null + private var businessKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getIndexFlagAsBin( ) : ByteArray? { + + return this.indexFlag + } + + + + fun getIndexFlagAsStr( ) : String? { + + if( null == this.indexFlag ) return null; + return String(indexFlag!!) + } + + + + fun getIndexFlagAsHex( ) : String? { + + if( null == this.indexFlag ) return null; + return Util.bytes2HexString(indexFlag) + } + + + + fun setIndexFlag( bytes : ByteArray ) : Data { + + this.indexFlag = bytes + return this + } + + + + fun getIndexAsBin( ) : ByteArray? { + + return this.index + } + + + + fun getIndexAsStr( ) : String? { + + if( null == this.index ) return null; + return String(index!!) + } + + + + fun getIndexAsHex( ) : String? { + + if( null == this.index ) return null; + return Util.bytes2HexString(index) + } + + + + fun setIndex( bytes : ByteArray ) : Data { + + this.index = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getCheckFlagAsBin( ) : ByteArray? { + + return this.checkFlag + } + + + + fun getCheckFlagAsStr( ) : String? { + + if( null == this.checkFlag ) return null; + return String(checkFlag!!) + } + + + + fun getCheckFlagAsHex( ) : String? { + + if( null == this.checkFlag ) return null; + return Util.bytes2HexString(checkFlag) + } + + + + fun setCheckFlag( bytes : ByteArray ) : Data { + + this.checkFlag = bytes + return this + } + + + + fun getCheckValueAsBin( ) : ByteArray? { + + return this.checkValue + } + + + + fun getCheckValueAsStr( ) : String? { + + if( null == this.checkValue ) return null; + return String(checkValue!!) + } + + + + fun getCheckValueAsHex( ) : String? { + + if( null == this.checkValue ) return null; + return Util.bytes2HexString(checkValue) + } + + + + fun setCheckValue( bytes : ByteArray ) : Data { + + this.checkValue = bytes + return this + } + + + + fun getStartTimeAsBin( ) : ByteArray? { + + return this.startTime + } + + + + fun getStartTimeAsStr( ) : String? { + + if( null == this.startTime ) return null; + return String(startTime!!) + } + + + + fun getStartTimeAsHex( ) : String? { + + if( null == this.startTime ) return null; + return Util.bytes2HexString(startTime) + } + + + + fun setStartTime( bytes : ByteArray ) : Data { + + this.startTime = bytes + return this + } + + + + fun getEndTimeAsBin( ) : ByteArray? { + + return this.endTime + } + + + + fun getEndTimeAsStr( ) : String? { + + if( null == this.endTime ) return null; + return String(endTime!!) + } + + + + fun getEndTimeAsHex( ) : String? { + + if( null == this.endTime ) return null; + return Util.bytes2HexString(endTime) + } + + + + fun setEndTime( bytes : ByteArray ) : Data { + + this.endTime = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != indexFlag ){ + + + soup.put("indexFlag", this.indexFlag!!) + } + +if( null != index ){ + + + soup.put("index", this.index!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != checkFlag ){ + + + soup.put("checkFlag", this.checkFlag!!) + } + +if( null != checkValue ){ + + + soup.put("checkValue", this.checkValue!!) + } + +if( null != startTime ){ + + + soup.put("startTime", this.startTime!!) + } + +if( null != endTime ){ + + + soup.put("endTime", this.endTime!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("indexFlag") ){ + + + this.indexFlag = (soup.get("indexFlag") as PacketSection).bytes +} + + +if( soup.containsKey("index") ){ + + + this.index = (soup.get("index") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("checkFlag") ){ + + + this.checkFlag = (soup.get("checkFlag") as PacketSection).bytes +} + + +if( soup.containsKey("checkValue") ){ + + + this.checkValue = (soup.get("checkValue") as PacketSection).bytes +} + + +if( soup.containsKey("startTime") ){ + + + this.startTime = (soup.get("startTime") as PacketSection).bytes +} + + +if( soup.containsKey("endTime") ){ + + + this.endTime = (soup.get("endTime") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4C42")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4C42") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVMAC校验不过(Util.hexString2Bytes("3031")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户密钥存储索引(Util.hexString2Bytes("3231")), +OPV无效的索引值(Util.hexString2Bytes("3232")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV数据长度错(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return "MAC校验不过" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户密钥存储索引" + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的索引值" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + return null + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4C43")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4C43") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOLF.kt b/src/main/java/racal/sunyard/main/dto/DTOLF.kt new file mode 100644 index 0000000..de0372d --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOLF.kt @@ -0,0 +1,982 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOLF { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var indexFlag : ByteArray? = null + private var index : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getIndexFlagAsBin( ) : ByteArray? { + + return this.indexFlag + } + + + + fun getIndexFlagAsStr( ) : String? { + + if( null == this.indexFlag ) return null; + return String(indexFlag!!) + } + + + + fun getIndexFlagAsHex( ) : String? { + + if( null == this.indexFlag ) return null; + return Util.bytes2HexString(indexFlag) + } + + + + fun setIndexFlag( bytes : ByteArray ) : Data { + + this.indexFlag = bytes + return this + } + + + + fun getIndexAsBin( ) : ByteArray? { + + return this.index + } + + + + fun getIndexAsStr( ) : String? { + + if( null == this.index ) return null; + return String(index!!) + } + + + + fun getIndexAsHex( ) : String? { + + if( null == this.index ) return null; + return Util.bytes2HexString(index) + } + + + + fun setIndex( bytes : ByteArray ) : Data { + + this.index = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != indexFlag ){ + + + soup.put("indexFlag", this.indexFlag!!) + } + +if( null != index ){ + + + soup.put("index", this.index!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("indexFlag") ){ + + + this.indexFlag = (soup.get("indexFlag") as PacketSection).bytes +} + + +if( soup.containsKey("index") ){ + + + this.index = (soup.get("index") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4C46")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4C46") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var keyHead : ByteArray? = null + private var key : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV用户密钥存储区没有装载数据(Util.hexString2Bytes("3132")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户密钥存储索引(Util.hexString2Bytes("3231")), +OPV无效的索引值(Util.hexString2Bytes("3232")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户密钥存储区没有装载数据" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户密钥存储索引" + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的索引值" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + return null + } + + + + fun getKeyHeadAsBin( ) : ByteArray? { + + return this.keyHead + } + + + + fun getKeyHeadAsStr( ) : String? { + + if( null == this.keyHead ) return null; + return String(keyHead!!) + } + + + + fun getKeyHeadAsHex( ) : String? { + + if( null == this.keyHead ) return null; + return Util.bytes2HexString(keyHead) + } + + + + fun setKeyHead( bytes : ByteArray ) : Data { + + this.keyHead = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != keyHead ){ + + + soup.put("keyHead", this.keyHead!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("keyHead") ){ + + + this.keyHead = (soup.get("keyHead") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4C47")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4C47") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOLG.kt b/src/main/java/racal/sunyard/main/dto/DTOLG.kt new file mode 100644 index 0000000..57124bf --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOLG.kt @@ -0,0 +1,1162 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOLG { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var indexFlag : ByteArray? = null + private var index : ByteArray? = null + private var key : ByteArray? = null + private var checkFlag : ByteArray? = null + private var checkValue : ByteArray? = null + private var startTime : ByteArray? = null + private var endTime : ByteArray? = null + private var oldEndTime : ByteArray? = null + private var businessKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getIndexFlagAsBin( ) : ByteArray? { + + return this.indexFlag + } + + + + fun getIndexFlagAsStr( ) : String? { + + if( null == this.indexFlag ) return null; + return String(indexFlag!!) + } + + + + fun getIndexFlagAsHex( ) : String? { + + if( null == this.indexFlag ) return null; + return Util.bytes2HexString(indexFlag) + } + + + + fun setIndexFlag( bytes : ByteArray ) : Data { + + this.indexFlag = bytes + return this + } + + + + fun getIndexAsBin( ) : ByteArray? { + + return this.index + } + + + + fun getIndexAsStr( ) : String? { + + if( null == this.index ) return null; + return String(index!!) + } + + + + fun getIndexAsHex( ) : String? { + + if( null == this.index ) return null; + return Util.bytes2HexString(index) + } + + + + fun setIndex( bytes : ByteArray ) : Data { + + this.index = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getCheckFlagAsBin( ) : ByteArray? { + + return this.checkFlag + } + + + + fun getCheckFlagAsStr( ) : String? { + + if( null == this.checkFlag ) return null; + return String(checkFlag!!) + } + + + + fun getCheckFlagAsHex( ) : String? { + + if( null == this.checkFlag ) return null; + return Util.bytes2HexString(checkFlag) + } + + + + fun setCheckFlag( bytes : ByteArray ) : Data { + + this.checkFlag = bytes + return this + } + + + + fun getCheckValueAsBin( ) : ByteArray? { + + return this.checkValue + } + + + + fun getCheckValueAsStr( ) : String? { + + if( null == this.checkValue ) return null; + return String(checkValue!!) + } + + + + fun getCheckValueAsHex( ) : String? { + + if( null == this.checkValue ) return null; + return Util.bytes2HexString(checkValue) + } + + + + fun setCheckValue( bytes : ByteArray ) : Data { + + this.checkValue = bytes + return this + } + + + + fun getStartTimeAsBin( ) : ByteArray? { + + return this.startTime + } + + + + fun getStartTimeAsStr( ) : String? { + + if( null == this.startTime ) return null; + return String(startTime!!) + } + + + + fun getStartTimeAsHex( ) : String? { + + if( null == this.startTime ) return null; + return Util.bytes2HexString(startTime) + } + + + + fun setStartTime( bytes : ByteArray ) : Data { + + this.startTime = bytes + return this + } + + + + fun getEndTimeAsBin( ) : ByteArray? { + + return this.endTime + } + + + + fun getEndTimeAsStr( ) : String? { + + if( null == this.endTime ) return null; + return String(endTime!!) + } + + + + fun getEndTimeAsHex( ) : String? { + + if( null == this.endTime ) return null; + return Util.bytes2HexString(endTime) + } + + + + fun setEndTime( bytes : ByteArray ) : Data { + + this.endTime = bytes + return this + } + + + + fun getOldEndTimeAsBin( ) : ByteArray? { + + return this.oldEndTime + } + + + + fun getOldEndTimeAsStr( ) : String? { + + if( null == this.oldEndTime ) return null; + return String(oldEndTime!!) + } + + + + fun getOldEndTimeAsHex( ) : String? { + + if( null == this.oldEndTime ) return null; + return Util.bytes2HexString(oldEndTime) + } + + + + fun setOldEndTime( bytes : ByteArray ) : Data { + + this.oldEndTime = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != indexFlag ){ + + + soup.put("indexFlag", this.indexFlag!!) + } + +if( null != index ){ + + + soup.put("index", this.index!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != checkFlag ){ + + + soup.put("checkFlag", this.checkFlag!!) + } + +if( null != checkValue ){ + + + soup.put("checkValue", this.checkValue!!) + } + +if( null != startTime ){ + + + soup.put("startTime", this.startTime!!) + } + +if( null != endTime ){ + + + soup.put("endTime", this.endTime!!) + } + +if( null != oldEndTime ){ + + + soup.put("oldEndTime", this.oldEndTime!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("indexFlag") ){ + + + this.indexFlag = (soup.get("indexFlag") as PacketSection).bytes +} + + +if( soup.containsKey("index") ){ + + + this.index = (soup.get("index") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("checkFlag") ){ + + + this.checkFlag = (soup.get("checkFlag") as PacketSection).bytes +} + + +if( soup.containsKey("checkValue") ){ + + + this.checkValue = (soup.get("checkValue") as PacketSection).bytes +} + + +if( soup.containsKey("startTime") ){ + + + this.startTime = (soup.get("startTime") as PacketSection).bytes +} + + +if( soup.containsKey("endTime") ){ + + + this.endTime = (soup.get("endTime") as PacketSection).bytes +} + + +if( soup.containsKey("oldEndTime") ){ + + + this.oldEndTime = (soup.get("oldEndTime") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4C47")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4C47") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户密钥存储索引(Util.hexString2Bytes("3231")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户密钥存储索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + return null + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4C48")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4C48") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOMA.kt b/src/main/java/racal/sunyard/main/dto/DTOMA.kt new file mode 100644 index 0000000..3b69209 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOMA.kt @@ -0,0 +1,1268 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOMA { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var businessKey : ByteArray? = null + private var alg : ByteArray? = null + private var keyType : ByteArray? = null + private var fullMode : ByteArray? = null + private var mACLen : ByteArray? = null + private var key : ByteArray? = null + private var mACData : ByteArray? = null + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPVDES(Util.hexString2Bytes("30")), +OPV3DES(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), +OPVAES(Util.hexString2Bytes("33")), +OPVIDEA(Util.hexString2Bytes("34")), +OPVSM1(Util.hexString2Bytes("35")), +OPV3DESX919(Util.hexString2Bytes("36")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "DES" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "3DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4" + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return "AES" + +} + + +if( "34".equals(Util.bytes2HexString(this.alg) ) ) { + + return "IDEA" + +} + + +if( "35".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM1" + +} + + +if( "36".equals(Util.bytes2HexString(this.alg) ) ) { + + return "3DESX919" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return 2 + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return 3 + +} + + +if( "34".equals(Util.bytes2HexString(this.alg) ) ) { + + return 4 + +} + + +if( "35".equals(Util.bytes2HexString(this.alg) ) ) { + + return 5 + +} + + +if( "36".equals(Util.bytes2HexString(this.alg) ) ) { + + return 6 + +} + + return null + } + + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + enum class KeyTypeOptions( val bin : ByteArray ) { + +OPVTAK(Util.hexString2Bytes("30")), +OPVZAK(Util.hexString2Bytes("31")), + } + + fun getKeyTypeCn( ) : String? { + + if( null == keyType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.keyType) ) ) { + + return "TAK" + +} + + +if( "31".equals(Util.bytes2HexString(this.keyType) ) ) { + + return "ZAK" + +} + + return null + } + + + + fun getKeyTypeOptionIndex( ) : Int? { + + if( null == keyType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.keyType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.keyType) ) ) { + + return 1 + +} + + return null + } + + + + fun getFullModeAsBin( ) : ByteArray? { + + return this.fullMode + } + + + + fun getFullModeAsStr( ) : String? { + + if( null == this.fullMode ) return null; + return String(fullMode!!) + } + + + + fun getFullModeAsHex( ) : String? { + + if( null == this.fullMode ) return null; + return Util.bytes2HexString(fullMode) + } + + + + fun setFullMode( bytes : ByteArray ) : Data { + + this.fullMode = bytes + return this + } + + + enum class FullModeOptions( val bin : ByteArray ) { + +OPV弱填充(Util.hexString2Bytes("30")), +OPV强填充(Util.hexString2Bytes("31")), + } + + fun getFullModeCn( ) : String? { + + if( null == fullMode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return "弱填充" + +} + + +if( "31".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return "强填充" + +} + + return null + } + + + + fun getFullModeOptionIndex( ) : Int? { + + if( null == fullMode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return 1 + +} + + return null + } + + + + fun getMACLenAsBin( ) : ByteArray? { + + return this.mACLen + } + + + + fun getMACLenAsStr( ) : String? { + + if( null == this.mACLen ) return null; + return String(mACLen!!) + } + + + + fun getMACLenAsHex( ) : String? { + + if( null == this.mACLen ) return null; + return Util.bytes2HexString(mACLen) + } + + + + fun setMACLen( bytes : ByteArray ) : Data { + + this.mACLen = bytes + return this + } + + + enum class MACLenOptions( val bin : ByteArray ) { + +OPV4(Util.hexString2Bytes("31")), +OPV8(Util.hexString2Bytes("32")), +OPV16(Util.hexString2Bytes("33")), + } + + fun getMACLenCn( ) : String? { + + if( null == mACLen ) { return null } + +if( "31".equals(Util.bytes2HexString(this.mACLen) ) ) { + + return "4" + +} + + +if( "32".equals(Util.bytes2HexString(this.mACLen) ) ) { + + return "8" + +} + + +if( "33".equals(Util.bytes2HexString(this.mACLen) ) ) { + + return "16" + +} + + return null + } + + + + fun getMACLenOptionIndex( ) : Int? { + + if( null == mACLen ) { return null } + +if( "31".equals(Util.bytes2HexString(this.mACLen) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.mACLen) ) ) { + + return 1 + +} + + +if( "33".equals(Util.bytes2HexString(this.mACLen) ) ) { + + return 2 + +} + + return null + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getMACDataAsBin( ) : ByteArray? { + + return this.mACData + } + + + + fun getMACDataAsStr( ) : String? { + + if( null == this.mACData ) return null; + return String(mACData!!) + } + + + + fun getMACDataAsHex( ) : String? { + + if( null == this.mACData ) return null; + return Util.bytes2HexString(mACData) + } + + + + fun setMACData( bytes : ByteArray ) : Data { + + this.mACData = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + soup.put("keyType\$option", getKeyTypeOptionIndex()!!) + } + +if( null != fullMode ){ + + + soup.put("fullMode", this.fullMode!!) + soup.put("fullMode\$option", getFullModeOptionIndex()!!) + } + +if( null != mACLen ){ + + + soup.put("MACLen", this.mACLen!!) + soup.put("MACLen\$option", getMACLenOptionIndex()!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != mACData ){ + + + soup.put("MACData", this.mACData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("fullMode") ){ + + + this.fullMode = (soup.get("fullMode") as PacketSection).bytes +} + + +if( soup.containsKey("MACLen") ){ + + + this.mACLen = (soup.get("MACLen") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("MACData") ){ + + + this.mACData = (soup.get("MACData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D41")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D41") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var mAC : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVTAK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "TAK奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + return null + } + + + + fun getMACAsBin( ) : ByteArray? { + + return this.mAC + } + + + + fun getMACAsStr( ) : String? { + + if( null == this.mAC ) return null; + return String(mAC!!) + } + + + + fun getMACAsHex( ) : String? { + + if( null == this.mAC ) return null; + return Util.bytes2HexString(mAC) + } + + + + fun setMAC( bytes : ByteArray ) : Data { + + this.mAC = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != mAC ){ + + + soup.put("MAC", this.mAC!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("MAC") ){ + + + this.mAC = (soup.get("MAC") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D42")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D42") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOMAXF.kt b/src/main/java/racal/sunyard/main/dto/DTOMAXF.kt new file mode 100644 index 0000000..ac03b7a --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOMAXF.kt @@ -0,0 +1,1072 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOMAXF { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var businessKey : ByteArray? = null + private var iVKey : ByteArray? = null + private var iV : ByteArray? = null + private var tAK : ByteArray? = null + private var mACData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getIVKeyAsBin( ) : ByteArray? { + + return this.iVKey + } + + + + fun getIVKeyAsStr( ) : String? { + + if( null == this.iVKey ) return null; + return String(iVKey!!) + } + + + + fun getIVKeyAsHex( ) : String? { + + if( null == this.iVKey ) return null; + return Util.bytes2HexString(iVKey) + } + + + + fun setIVKey( bytes : ByteArray ) : Data { + + this.iVKey = bytes + return this + } + + + + fun getIVAsBin( ) : ByteArray? { + + return this.iV + } + + + + fun getIVAsStr( ) : String? { + + if( null == this.iV ) return null; + return String(iV!!) + } + + + + fun getIVAsHex( ) : String? { + + if( null == this.iV ) return null; + return Util.bytes2HexString(iV) + } + + + + fun setIV( bytes : ByteArray ) : Data { + + this.iV = bytes + return this + } + + + + fun getTAKAsBin( ) : ByteArray? { + + return this.tAK + } + + + + fun getTAKAsStr( ) : String? { + + if( null == this.tAK ) return null; + return String(tAK!!) + } + + + + fun getTAKAsHex( ) : String? { + + if( null == this.tAK ) return null; + return Util.bytes2HexString(tAK) + } + + + + fun setTAK( bytes : ByteArray ) : Data { + + this.tAK = bytes + return this + } + + + + fun getMACDataAsBin( ) : ByteArray? { + + return this.mACData + } + + + + fun getMACDataAsStr( ) : String? { + + if( null == this.mACData ) return null; + return String(mACData!!) + } + + + + fun getMACDataAsHex( ) : String? { + + if( null == this.mACData ) return null; + return Util.bytes2HexString(mACData) + } + + + + fun setMACData( bytes : ByteArray ) : Data { + + this.mACData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != iVKey ){ + + + soup.put("IVKey", this.iVKey!!) + } + +if( null != iV ){ + + + soup.put("IV", this.iV!!) + } + +if( null != tAK ){ + + + soup.put("TAK", this.tAK!!) + } + +if( null != mACData ){ + + + soup.put("MACData", this.mACData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("IVKey") ){ + + + this.iVKey = (soup.get("IVKey") as PacketSection).bytes +} + + +if( soup.containsKey("IV") ){ + + + this.iV = (soup.get("IV") as PacketSection).bytes +} + + +if( soup.containsKey("TAK") ){ + + + this.tAK = (soup.get("TAK") as PacketSection).bytes +} + + +if( soup.containsKey("MACData") ){ + + + this.mACData = (soup.get("MACData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D41")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D41") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var mAC : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVTAK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "TAK奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + return null + } + + + + fun getMACAsBin( ) : ByteArray? { + + return this.mAC + } + + + + fun getMACAsStr( ) : String? { + + if( null == this.mAC ) return null; + return String(mAC!!) + } + + + + fun getMACAsHex( ) : String? { + + if( null == this.mAC ) return null; + return Util.bytes2HexString(mAC) + } + + + + fun setMAC( bytes : ByteArray ) : Data { + + this.mAC = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != mAC ){ + + + soup.put("MAC", this.mAC!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("MAC") ){ + + + this.mAC = (soup.get("MAC") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D42")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D42") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOMC.kt b/src/main/java/racal/sunyard/main/dto/DTOMC.kt new file mode 100644 index 0000000..ac2bcb6 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOMC.kt @@ -0,0 +1,1268 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOMC { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var businessKey : ByteArray? = null + private var alg : ByteArray? = null + private var keyType : ByteArray? = null + private var fullMode : ByteArray? = null + private var mACLen : ByteArray? = null + private var key : ByteArray? = null + private var mAC : ByteArray? = null + private var mACData : ByteArray? = null + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPVDES(Util.hexString2Bytes("30")), +OPV3DES(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), +OPVAES(Util.hexString2Bytes("33")), +OPVIDEA(Util.hexString2Bytes("34")), +OPVSM1(Util.hexString2Bytes("35")), +OPV3DESX919(Util.hexString2Bytes("36")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "DES" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "3DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4" + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return "AES" + +} + + +if( "34".equals(Util.bytes2HexString(this.alg) ) ) { + + return "IDEA" + +} + + +if( "35".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM1" + +} + + +if( "36".equals(Util.bytes2HexString(this.alg) ) ) { + + return "3DESX919" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return 2 + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return 3 + +} + + +if( "34".equals(Util.bytes2HexString(this.alg) ) ) { + + return 4 + +} + + +if( "35".equals(Util.bytes2HexString(this.alg) ) ) { + + return 5 + +} + + +if( "36".equals(Util.bytes2HexString(this.alg) ) ) { + + return 6 + +} + + return null + } + + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + enum class KeyTypeOptions( val bin : ByteArray ) { + +OPVTAK(Util.hexString2Bytes("30")), +OPVZAK(Util.hexString2Bytes("31")), + } + + fun getKeyTypeCn( ) : String? { + + if( null == keyType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.keyType) ) ) { + + return "TAK" + +} + + +if( "31".equals(Util.bytes2HexString(this.keyType) ) ) { + + return "ZAK" + +} + + return null + } + + + + fun getKeyTypeOptionIndex( ) : Int? { + + if( null == keyType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.keyType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.keyType) ) ) { + + return 1 + +} + + return null + } + + + + fun getFullModeAsBin( ) : ByteArray? { + + return this.fullMode + } + + + + fun getFullModeAsStr( ) : String? { + + if( null == this.fullMode ) return null; + return String(fullMode!!) + } + + + + fun getFullModeAsHex( ) : String? { + + if( null == this.fullMode ) return null; + return Util.bytes2HexString(fullMode) + } + + + + fun setFullMode( bytes : ByteArray ) : Data { + + this.fullMode = bytes + return this + } + + + enum class FullModeOptions( val bin : ByteArray ) { + +OPV弱填充(Util.hexString2Bytes("30")), +OPV强填充(Util.hexString2Bytes("31")), + } + + fun getFullModeCn( ) : String? { + + if( null == fullMode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return "弱填充" + +} + + +if( "31".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return "强填充" + +} + + return null + } + + + + fun getFullModeOptionIndex( ) : Int? { + + if( null == fullMode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return 1 + +} + + return null + } + + + + fun getMACLenAsBin( ) : ByteArray? { + + return this.mACLen + } + + + + fun getMACLenAsStr( ) : String? { + + if( null == this.mACLen ) return null; + return String(mACLen!!) + } + + + + fun getMACLenAsHex( ) : String? { + + if( null == this.mACLen ) return null; + return Util.bytes2HexString(mACLen) + } + + + + fun setMACLen( bytes : ByteArray ) : Data { + + this.mACLen = bytes + return this + } + + + enum class MACLenOptions( val bin : ByteArray ) { + +OPV4(Util.hexString2Bytes("31")), +OPV8(Util.hexString2Bytes("32")), +OPV16(Util.hexString2Bytes("33")), + } + + fun getMACLenCn( ) : String? { + + if( null == mACLen ) { return null } + +if( "31".equals(Util.bytes2HexString(this.mACLen) ) ) { + + return "4" + +} + + +if( "32".equals(Util.bytes2HexString(this.mACLen) ) ) { + + return "8" + +} + + +if( "33".equals(Util.bytes2HexString(this.mACLen) ) ) { + + return "16" + +} + + return null + } + + + + fun getMACLenOptionIndex( ) : Int? { + + if( null == mACLen ) { return null } + +if( "31".equals(Util.bytes2HexString(this.mACLen) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.mACLen) ) ) { + + return 1 + +} + + +if( "33".equals(Util.bytes2HexString(this.mACLen) ) ) { + + return 2 + +} + + return null + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getMACAsBin( ) : ByteArray? { + + return this.mAC + } + + + + fun getMACAsStr( ) : String? { + + if( null == this.mAC ) return null; + return String(mAC!!) + } + + + + fun getMACAsHex( ) : String? { + + if( null == this.mAC ) return null; + return Util.bytes2HexString(mAC) + } + + + + fun setMAC( bytes : ByteArray ) : Data { + + this.mAC = bytes + return this + } + + + + fun getMACDataAsBin( ) : ByteArray? { + + return this.mACData + } + + + + fun getMACDataAsStr( ) : String? { + + if( null == this.mACData ) return null; + return String(mACData!!) + } + + + + fun getMACDataAsHex( ) : String? { + + if( null == this.mACData ) return null; + return Util.bytes2HexString(mACData) + } + + + + fun setMACData( bytes : ByteArray ) : Data { + + this.mACData = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + soup.put("keyType\$option", getKeyTypeOptionIndex()!!) + } + +if( null != fullMode ){ + + + soup.put("fullMode", this.fullMode!!) + soup.put("fullMode\$option", getFullModeOptionIndex()!!) + } + +if( null != mACLen ){ + + + soup.put("MACLen", this.mACLen!!) + soup.put("MACLen\$option", getMACLenOptionIndex()!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != mAC ){ + + + soup.put("MAC", this.mAC!!) + } + +if( null != mACData ){ + + + soup.put("MACData", this.mACData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("fullMode") ){ + + + this.fullMode = (soup.get("fullMode") as PacketSection).bytes +} + + +if( soup.containsKey("MACLen") ){ + + + this.mACLen = (soup.get("MACLen") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("MAC") ){ + + + this.mAC = (soup.get("MAC") as PacketSection).bytes +} + + +if( soup.containsKey("MACData") ){ + + + this.mACData = (soup.get("MACData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D43")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D43") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVTAK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "TAK奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + return null + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D44")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D44") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOMF.kt b/src/main/java/racal/sunyard/main/dto/DTOMF.kt new file mode 100644 index 0000000..ff6c3ad --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOMF.kt @@ -0,0 +1,1267 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOMF { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var zmk : ByteArray? = null + private var tak : ByteArray? = null + private var businessKey : ByteArray? = null + private var separator : ByteArray? = null + private var zmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getTakAsBin( ) : ByteArray? { + + return this.tak + } + + + + fun getTakAsStr( ) : String? { + + if( null == this.tak ) return null; + return String(tak!!) + } + + + + fun getTakAsHex( ) : String? { + + if( null == this.tak ) return null; + return Util.bytes2HexString(tak) + } + + + + fun setTak( bytes : ByteArray ) : Data { + + this.tak = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getZmkSolutionAsBin( ) : ByteArray? { + + return this.zmkSolution + } + + + + fun getZmkSolutionAsStr( ) : String? { + + if( null == this.zmkSolution ) return null; + return String(zmkSolution!!) + } + + + + fun getZmkSolutionAsHex( ) : String? { + + if( null == this.zmkSolution ) return null; + return Util.bytes2HexString(zmkSolution) + } + + + + fun setZmkSolution( bytes : ByteArray ) : Data { + + this.zmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != tak ){ + + + soup.put("tak", this.tak!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != zmkSolution ){ + + + soup.put("zmkSolution", this.zmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("tak") ){ + + + this.tak = (soup.get("tak") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("zmkSolution") ){ + + + this.zmkSolution = (soup.get("zmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D46")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D46") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var takLmkHead : ByteArray? = null + private var takLmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPVTMKTPK或PVK奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "TMK、TPK 或 PVK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + return null + } + + + + fun getTakLmkHeadAsBin( ) : ByteArray? { + + return this.takLmkHead + } + + + + fun getTakLmkHeadAsStr( ) : String? { + + if( null == this.takLmkHead ) return null; + return String(takLmkHead!!) + } + + + + fun getTakLmkHeadAsHex( ) : String? { + + if( null == this.takLmkHead ) return null; + return Util.bytes2HexString(takLmkHead) + } + + + + fun setTakLmkHead( bytes : ByteArray ) : Data { + + this.takLmkHead = bytes + return this + } + + + + fun getTakLmkAsBin( ) : ByteArray? { + + return this.takLmk + } + + + + fun getTakLmkAsStr( ) : String? { + + if( null == this.takLmk ) return null; + return String(takLmk!!) + } + + + + fun getTakLmkAsHex( ) : String? { + + if( null == this.takLmk ) return null; + return Util.bytes2HexString(takLmk) + } + + + + fun setTakLmk( bytes : ByteArray ) : Data { + + this.takLmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != takLmkHead ){ + + + soup.put("takLmkHead", this.takLmkHead!!) + } + +if( null != takLmk ){ + + + soup.put("takLmk", this.takLmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("takLmkHead") ){ + + + this.takLmkHead = (soup.get("takLmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("takLmk") ){ + + + this.takLmk = (soup.get("takLmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D47")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D47") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOMG.kt b/src/main/java/racal/sunyard/main/dto/DTOMG.kt new file mode 100644 index 0000000..3662e15 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOMG.kt @@ -0,0 +1,1267 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOMG { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var zmk : ByteArray? = null + private var tak : ByteArray? = null + private var businessKey : ByteArray? = null + private var separator : ByteArray? = null + private var zmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getZmkAsBin( ) : ByteArray? { + + return this.zmk + } + + + + fun getZmkAsStr( ) : String? { + + if( null == this.zmk ) return null; + return String(zmk!!) + } + + + + fun getZmkAsHex( ) : String? { + + if( null == this.zmk ) return null; + return Util.bytes2HexString(zmk) + } + + + + fun setZmk( bytes : ByteArray ) : Data { + + this.zmk = bytes + return this + } + + + + fun getTakAsBin( ) : ByteArray? { + + return this.tak + } + + + + fun getTakAsStr( ) : String? { + + if( null == this.tak ) return null; + return String(tak!!) + } + + + + fun getTakAsHex( ) : String? { + + if( null == this.tak ) return null; + return Util.bytes2HexString(tak) + } + + + + fun setTak( bytes : ByteArray ) : Data { + + this.tak = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getSeparatorAsBin( ) : ByteArray? { + + return this.separator + } + + + + fun getSeparatorAsStr( ) : String? { + + if( null == this.separator ) return null; + return String(separator!!) + } + + + + fun getSeparatorAsHex( ) : String? { + + if( null == this.separator ) return null; + return Util.bytes2HexString(separator) + } + + + + fun setSeparator( bytes : ByteArray ) : Data { + + this.separator = bytes + return this + } + + + + fun getZmkSolutionAsBin( ) : ByteArray? { + + return this.zmkSolution + } + + + + fun getZmkSolutionAsStr( ) : String? { + + if( null == this.zmkSolution ) return null; + return String(zmkSolution!!) + } + + + + fun getZmkSolutionAsHex( ) : String? { + + if( null == this.zmkSolution ) return null; + return Util.bytes2HexString(zmkSolution) + } + + + + fun setZmkSolution( bytes : ByteArray ) : Data { + + this.zmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != zmk ){ + + + soup.put("zmk", this.zmk!!) + } + +if( null != tak ){ + + + soup.put("tak", this.tak!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != separator ){ + + + soup.put("separator", this.separator!!) + } + +if( null != zmkSolution ){ + + + soup.put("zmkSolution", this.zmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("zmk") ){ + + + this.zmk = (soup.get("zmk") as PacketSection).bytes +} + + +if( soup.containsKey("tak") ){ + + + this.tak = (soup.get("tak") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("separator") ){ + + + this.separator = (soup.get("separator") as PacketSection).bytes +} + + +if( soup.containsKey("zmkSolution") ){ + + + this.zmkSolution = (soup.get("zmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D47")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D47") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var takZmkHead : ByteArray? = null + private var takZmk : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPVTMKTPK或PVK奇偶校验错(Util.hexString2Bytes("3131")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return "TMK、TPK 或 PVK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3131".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + return null + } + + + + fun getTakZmkHeadAsBin( ) : ByteArray? { + + return this.takZmkHead + } + + + + fun getTakZmkHeadAsStr( ) : String? { + + if( null == this.takZmkHead ) return null; + return String(takZmkHead!!) + } + + + + fun getTakZmkHeadAsHex( ) : String? { + + if( null == this.takZmkHead ) return null; + return Util.bytes2HexString(takZmkHead) + } + + + + fun setTakZmkHead( bytes : ByteArray ) : Data { + + this.takZmkHead = bytes + return this + } + + + + fun getTakZmkAsBin( ) : ByteArray? { + + return this.takZmk + } + + + + fun getTakZmkAsStr( ) : String? { + + if( null == this.takZmk ) return null; + return String(takZmk!!) + } + + + + fun getTakZmkAsHex( ) : String? { + + if( null == this.takZmk ) return null; + return Util.bytes2HexString(takZmk) + } + + + + fun setTakZmk( bytes : ByteArray ) : Data { + + this.takZmk = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != takZmkHead ){ + + + soup.put("takZmkHead", this.takZmkHead!!) + } + +if( null != takZmk ){ + + + soup.put("takZmk", this.takZmk!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("takZmkHead") ){ + + + this.takZmkHead = (soup.get("takZmkHead") as PacketSection).bytes +} + + +if( soup.containsKey("takZmk") ){ + + + this.takZmk = (soup.get("takZmk") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D48")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D48") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOMS.kt b/src/main/java/racal/sunyard/main/dto/DTOMS.kt new file mode 100644 index 0000000..fb078c8 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOMS.kt @@ -0,0 +1,1527 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOMS { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var block : ByteArray? = null + private var keyType : ByteArray? = null + private var mode : ByteArray? = null + private var dataType : ByteArray? = null + private var key : ByteArray? = null + private var iv : ByteArray? = null + private var msgLen : ByteArray? = null + private var msg : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getBlockAsBin( ) : ByteArray? { + + return this.block + } + + + + fun getBlockAsStr( ) : String? { + + if( null == this.block ) return null; + return String(block!!) + } + + + + fun getBlockAsHex( ) : String? { + + if( null == this.block ) return null; + return Util.bytes2HexString(block) + } + + + + fun setBlock( bytes : ByteArray ) : Data { + + this.block = bytes + return this + } + + + enum class BlockOptions( val bin : ByteArray ) { + +OPV仅一块(Util.hexString2Bytes("30")), +OPV第一块(Util.hexString2Bytes("31")), +OPV中间块(Util.hexString2Bytes("32")), +OPV最后块(Util.hexString2Bytes("33")), + } + + fun getBlockCn( ) : String? { + + if( null == block ) { return null } + +if( "30".equals(Util.bytes2HexString(this.block) ) ) { + + return "仅一块" + +} + + +if( "31".equals(Util.bytes2HexString(this.block) ) ) { + + return "第一块" + +} + + +if( "32".equals(Util.bytes2HexString(this.block) ) ) { + + return "中间块" + +} + + +if( "33".equals(Util.bytes2HexString(this.block) ) ) { + + return "最后块" + +} + + return null + } + + + + fun getBlockOptionIndex( ) : Int? { + + if( null == block ) { return null } + +if( "30".equals(Util.bytes2HexString(this.block) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.block) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.block) ) ) { + + return 2 + +} + + +if( "33".equals(Util.bytes2HexString(this.block) ) ) { + + return 3 + +} + + return null + } + + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + enum class KeyTypeOptions( val bin : ByteArray ) { + +OPVTAK(Util.hexString2Bytes("30")), +OPVZAK(Util.hexString2Bytes("31")), + } + + fun getKeyTypeCn( ) : String? { + + if( null == keyType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.keyType) ) ) { + + return "TAK" + +} + + +if( "31".equals(Util.bytes2HexString(this.keyType) ) ) { + + return "ZAK" + +} + + return null + } + + + + fun getKeyTypeOptionIndex( ) : Int? { + + if( null == keyType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.keyType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.keyType) ) ) { + + return 1 + +} + + return null + } + + + + fun getModeAsBin( ) : ByteArray? { + + return this.mode + } + + + + fun getModeAsStr( ) : String? { + + if( null == this.mode ) return null; + return String(mode!!) + } + + + + fun getModeAsHex( ) : String? { + + if( null == this.mode ) return null; + return Util.bytes2HexString(mode) + } + + + + fun setMode( bytes : ByteArray ) : Data { + + this.mode = bytes + return this + } + + + enum class ModeOptions( val bin : ByteArray ) { + +OPV单倍长度DES密钥AnsiX99(Util.hexString2Bytes("30")), +OPV双倍长度DES密钥AnsiX919(Util.hexString2Bytes("31")), +OPVSM4CBC弱填充0x00银联(Util.hexString2Bytes("32")), +OPV3DESCBC弱填充0x00银联(Util.hexString2Bytes("33")), + } + + fun getModeCn( ) : String? { + + if( null == mode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.mode) ) ) { + + return "单倍长度DES密钥.Ansi X9.9" + +} + + +if( "31".equals(Util.bytes2HexString(this.mode) ) ) { + + return "双倍长度DES密钥,Ansi X9.19" + +} + + +if( "32".equals(Util.bytes2HexString(this.mode) ) ) { + + return " SM4-CBC,弱填充0x00,银联" + +} + + +if( "33".equals(Util.bytes2HexString(this.mode) ) ) { + + return "3DES-CBC, ,弱填充0x00,银联" + +} + + return null + } + + + + fun getModeOptionIndex( ) : Int? { + + if( null == mode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.mode) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.mode) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.mode) ) ) { + + return 2 + +} + + +if( "33".equals(Util.bytes2HexString(this.mode) ) ) { + + return 3 + +} + + return null + } + + + + fun getDataTypeAsBin( ) : ByteArray? { + + return this.dataType + } + + + + fun getDataTypeAsStr( ) : String? { + + if( null == this.dataType ) return null; + return String(dataType!!) + } + + + + fun getDataTypeAsHex( ) : String? { + + if( null == this.dataType ) return null; + return Util.bytes2HexString(dataType) + } + + + + fun setDataType( bytes : ByteArray ) : Data { + + this.dataType = bytes + return this + } + + + enum class DataTypeOptions( val bin : ByteArray ) { + +OPV二进制(Util.hexString2Bytes("30")), +OPV十六进制(Util.hexString2Bytes("31")), + } + + fun getDataTypeCn( ) : String? { + + if( null == dataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.dataType) ) ) { + + return "二进制" + +} + + +if( "31".equals(Util.bytes2HexString(this.dataType) ) ) { + + return "十六进制" + +} + + return null + } + + + + fun getDataTypeOptionIndex( ) : Int? { + + if( null == dataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.dataType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.dataType) ) ) { + + return 1 + +} + + return null + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getIvAsBin( ) : ByteArray? { + + return this.iv + } + + + + fun getIvAsStr( ) : String? { + + if( null == this.iv ) return null; + return String(iv!!) + } + + + + fun getIvAsHex( ) : String? { + + if( null == this.iv ) return null; + return Util.bytes2HexString(iv) + } + + + + fun setIv( bytes : ByteArray ) : Data { + + this.iv = bytes + return this + } + + + + fun getMsgLenAsBin( ) : ByteArray? { + + return this.msgLen + } + + + + fun getMsgLenAsStr( ) : String? { + + if( null == this.msgLen ) return null; + return String(msgLen!!) + } + + + + fun getMsgLenAsHex( ) : String? { + + if( null == this.msgLen ) return null; + return Util.bytes2HexString(msgLen) + } + + + + fun setMsgLen( bytes : ByteArray ) : Data { + + this.msgLen = bytes + return this + } + + + + fun getMsgAsBin( ) : ByteArray? { + + return this.msg + } + + + + fun getMsgAsStr( ) : String? { + + if( null == this.msg ) return null; + return String(msg!!) + } + + + + fun getMsgAsHex( ) : String? { + + if( null == this.msg ) return null; + return Util.bytes2HexString(msg) + } + + + + fun setMsg( bytes : ByteArray ) : Data { + + this.msg = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != block ){ + + + soup.put("block", this.block!!) + soup.put("block\$option", getBlockOptionIndex()!!) + } + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + soup.put("keyType\$option", getKeyTypeOptionIndex()!!) + } + +if( null != mode ){ + + + soup.put("mode", this.mode!!) + soup.put("mode\$option", getModeOptionIndex()!!) + } + +if( null != dataType ){ + + + soup.put("dataType", this.dataType!!) + soup.put("dataType\$option", getDataTypeOptionIndex()!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != iv ){ + + + soup.put("iv", this.iv!!) + } + +if( null != msgLen ){ + + + soup.put("msgLen", this.msgLen!!) + } + +if( null != msg ){ + + + soup.put("msg", this.msg!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("block") ){ + + + this.block = (soup.get("block") as PacketSection).bytes +} + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("mode") ){ + + + this.mode = (soup.get("mode") as PacketSection).bytes +} + + +if( soup.containsKey("dataType") ){ + + + this.dataType = (soup.get("dataType") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("iv") ){ + + + this.iv = (soup.get("iv") as PacketSection).bytes +} + + +if( soup.containsKey("msgLen") ){ + + + this.msgLen = (soup.get("msgLen") as PacketSection).bytes +} + + +if( soup.containsKey("msg") ){ + + + this.msg = (soup.get("msg") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D53")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D53") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var mAB : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效消息类型代码(Util.hexString2Bytes("3033")), +OPV无效密钥类型代码(Util.hexString2Bytes("3034")), +OPV无效消息块号(Util.hexString2Bytes("3035")), +OPV无效密钥长度代码(Util.hexString2Bytes("3036")), +OPVZAK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV无效密钥长度(Util.hexString2Bytes("3237")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效消息类型代码" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效密钥类型代码" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效消息块号" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效密钥长度代码" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZAK奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3237".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效密钥长度" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3237".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + return null + } + + + + fun getMABAsBin( ) : ByteArray? { + + return this.mAB + } + + + + fun getMABAsStr( ) : String? { + + if( null == this.mAB ) return null; + return String(mAB!!) + } + + + + fun getMABAsHex( ) : String? { + + if( null == this.mAB ) return null; + return Util.bytes2HexString(mAB) + } + + + + fun setMAB( bytes : ByteArray ) : Data { + + this.mAB = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != mAB ){ + + + soup.put("MAB", this.mAB!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("MAB") ){ + + + this.mAB = (soup.get("MAB") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D54")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D54") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOMU.kt b/src/main/java/racal/sunyard/main/dto/DTOMU.kt new file mode 100644 index 0000000..fac9d29 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOMU.kt @@ -0,0 +1,1188 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOMU { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var block : ByteArray? = null + private var keyType : ByteArray? = null + private var mode : ByteArray? = null + private var dataType : ByteArray? = null + private var key : ByteArray? = null + private var iv : ByteArray? = null + private var mACDataLen : ByteArray? = null + private var mACData : ByteArray? = null + + + fun getBlockAsBin( ) : ByteArray? { + + return this.block + } + + + + fun getBlockAsStr( ) : String? { + + if( null == this.block ) return null; + return String(block!!) + } + + + + fun getBlockAsHex( ) : String? { + + if( null == this.block ) return null; + return Util.bytes2HexString(block) + } + + + + fun setBlock( bytes : ByteArray ) : Data { + + this.block = bytes + return this + } + + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + enum class KeyTypeOptions( val bin : ByteArray ) { + +OPVTAK(Util.hexString2Bytes("30")), +OPVZAK(Util.hexString2Bytes("31")), + } + + fun getKeyTypeCn( ) : String? { + + if( null == keyType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.keyType) ) ) { + + return "TAK" + +} + + +if( "31".equals(Util.bytes2HexString(this.keyType) ) ) { + + return "ZAK" + +} + + return null + } + + + + fun getKeyTypeOptionIndex( ) : Int? { + + if( null == keyType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.keyType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.keyType) ) ) { + + return 1 + +} + + return null + } + + + + fun getModeAsBin( ) : ByteArray? { + + return this.mode + } + + + + fun getModeAsStr( ) : String? { + + if( null == this.mode ) return null; + return String(mode!!) + } + + + + fun getModeAsHex( ) : String? { + + if( null == this.mode ) return null; + return Util.bytes2HexString(mode) + } + + + + fun setMode( bytes : ByteArray ) : Data { + + this.mode = bytes + return this + } + + + enum class ModeOptions( val bin : ByteArray ) { + +OPVDES(Util.hexString2Bytes("30")), +OPVDES3(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getModeCn( ) : String? { + + if( null == mode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.mode) ) ) { + + return "DES" + +} + + +if( "31".equals(Util.bytes2HexString(this.mode) ) ) { + + return "DES3" + +} + + +if( "32".equals(Util.bytes2HexString(this.mode) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getModeOptionIndex( ) : Int? { + + if( null == mode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.mode) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.mode) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.mode) ) ) { + + return 2 + +} + + return null + } + + + + fun getDataTypeAsBin( ) : ByteArray? { + + return this.dataType + } + + + + fun getDataTypeAsStr( ) : String? { + + if( null == this.dataType ) return null; + return String(dataType!!) + } + + + + fun getDataTypeAsHex( ) : String? { + + if( null == this.dataType ) return null; + return Util.bytes2HexString(dataType) + } + + + + fun setDataType( bytes : ByteArray ) : Data { + + this.dataType = bytes + return this + } + + + enum class DataTypeOptions( val bin : ByteArray ) { + +OPV二进制(Util.hexString2Bytes("30")), +OPV十六进制(Util.hexString2Bytes("31")), + } + + fun getDataTypeCn( ) : String? { + + if( null == dataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.dataType) ) ) { + + return "二进制" + +} + + +if( "31".equals(Util.bytes2HexString(this.dataType) ) ) { + + return "十六进制" + +} + + return null + } + + + + fun getDataTypeOptionIndex( ) : Int? { + + if( null == dataType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.dataType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.dataType) ) ) { + + return 1 + +} + + return null + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getIvAsBin( ) : ByteArray? { + + return this.iv + } + + + + fun getIvAsStr( ) : String? { + + if( null == this.iv ) return null; + return String(iv!!) + } + + + + fun getIvAsHex( ) : String? { + + if( null == this.iv ) return null; + return Util.bytes2HexString(iv) + } + + + + fun setIv( bytes : ByteArray ) : Data { + + this.iv = bytes + return this + } + + + + fun getMACDataLenAsBin( ) : ByteArray? { + + return this.mACDataLen + } + + + + fun getMACDataLenAsStr( ) : String? { + + if( null == this.mACDataLen ) return null; + return String(mACDataLen!!) + } + + + + fun getMACDataLenAsHex( ) : String? { + + if( null == this.mACDataLen ) return null; + return Util.bytes2HexString(mACDataLen) + } + + + + fun setMACDataLen( bytes : ByteArray ) : Data { + + this.mACDataLen = bytes + return this + } + + + + fun getMACDataAsBin( ) : ByteArray? { + + return this.mACData + } + + + + fun getMACDataAsStr( ) : String? { + + if( null == this.mACData ) return null; + return String(mACData!!) + } + + + + fun getMACDataAsHex( ) : String? { + + if( null == this.mACData ) return null; + return Util.bytes2HexString(mACData) + } + + + + fun setMACData( bytes : ByteArray ) : Data { + + this.mACData = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != block ){ + + + soup.put("block", this.block!!) + } + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + soup.put("keyType\$option", getKeyTypeOptionIndex()!!) + } + +if( null != mode ){ + + + soup.put("mode", this.mode!!) + soup.put("mode\$option", getModeOptionIndex()!!) + } + +if( null != dataType ){ + + + soup.put("dataType", this.dataType!!) + soup.put("dataType\$option", getDataTypeOptionIndex()!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != iv ){ + + + soup.put("iv", this.iv!!) + } + +if( null != mACDataLen ){ + + + soup.put("MACDataLen", this.mACDataLen!!) + } + +if( null != mACData ){ + + + soup.put("MACData", this.mACData!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("block") ){ + + + this.block = (soup.get("block") as PacketSection).bytes +} + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("mode") ){ + + + this.mode = (soup.get("mode") as PacketSection).bytes +} + + +if( soup.containsKey("dataType") ){ + + + this.dataType = (soup.get("dataType") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("iv") ){ + + + this.iv = (soup.get("iv") as PacketSection).bytes +} + + +if( soup.containsKey("MACDataLen") ){ + + + this.mACDataLen = (soup.get("MACDataLen") as PacketSection).bytes +} + + +if( soup.containsKey("MACData") ){ + + + this.mACData = (soup.get("MACData") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D55")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D55") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var mAC : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVTAK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的用户存储索引(Util.hexString2Bytes("3231")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "TAK奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的用户存储索引" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + return null + } + + + + fun getMACAsBin( ) : ByteArray? { + + return this.mAC + } + + + + fun getMACAsStr( ) : String? { + + if( null == this.mAC ) return null; + return String(mAC!!) + } + + + + fun getMACAsHex( ) : String? { + + if( null == this.mAC ) return null; + return Util.bytes2HexString(mAC) + } + + + + fun setMAC( bytes : ByteArray ) : Data { + + this.mAC = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != mAC ){ + + + soup.put("MAC", this.mAC!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("MAC") ){ + + + this.mAC = (soup.get("MAC") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4D56")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4D56") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTONE.kt b/src/main/java/racal/sunyard/main/dto/DTONE.kt new file mode 100644 index 0000000..6e3f9eb --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTONE.kt @@ -0,0 +1,1162 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTONE { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var keyType : ByteArray? = null + private var solution : ByteArray? = null + private var flag : ByteArray? = null + private var print : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + + fun getSolutionAsBin( ) : ByteArray? { + + return this.solution + } + + + + fun getSolutionAsStr( ) : String? { + + if( null == this.solution ) return null; + return String(solution!!) + } + + + + fun getSolutionAsHex( ) : String? { + + if( null == this.solution ) return null; + return Util.bytes2HexString(solution) + } + + + + fun setSolution( bytes : ByteArray ) : Data { + + this.solution = bytes + return this + } + + + + fun getFlagAsBin( ) : ByteArray? { + + return this.flag + } + + + + fun getFlagAsStr( ) : String? { + + if( null == this.flag ) return null; + return String(flag!!) + } + + + + fun getFlagAsHex( ) : String? { + + if( null == this.flag ) return null; + return Util.bytes2HexString(flag) + } + + + + fun setFlag( bytes : ByteArray ) : Data { + + this.flag = bytes + return this + } + + + + fun getPrintAsBin( ) : ByteArray? { + + return this.print + } + + + + fun getPrintAsStr( ) : String? { + + if( null == this.print ) return null; + return String(print!!) + } + + + + fun getPrintAsHex( ) : String? { + + if( null == this.print ) return null; + return Util.bytes2HexString(print) + } + + + + fun setPrint( bytes : ByteArray ) : Data { + + this.print = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + } + +if( null != solution ){ + + + soup.put("solution", this.solution!!) + } + +if( null != flag ){ + + + soup.put("flag", this.flag!!) + } + +if( null != print ){ + + + soup.put("print", this.print!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("solution") ){ + + + this.solution = (soup.get("solution") as PacketSection).bytes +} + + +if( soup.containsKey("flag") ){ + + + this.flag = (soup.get("flag") as PacketSection).bytes +} + + +if( soup.containsKey("print") ){ + + + this.print = (soup.get("print") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4E45")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4E45") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var keyHead : ByteArray? = null + private var key : ByteArray? = null + private var keyCheck : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV密钥奇偶校验错(Util.hexString2Bytes("3031")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV无效的密钥类型(Util.hexString2Bytes("3238")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥类型" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getKeyHeadAsBin( ) : ByteArray? { + + return this.keyHead + } + + + + fun getKeyHeadAsStr( ) : String? { + + if( null == this.keyHead ) return null; + return String(keyHead!!) + } + + + + fun getKeyHeadAsHex( ) : String? { + + if( null == this.keyHead ) return null; + return Util.bytes2HexString(keyHead) + } + + + + fun setKeyHead( bytes : ByteArray ) : Data { + + this.keyHead = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getKeyCheckAsBin( ) : ByteArray? { + + return this.keyCheck + } + + + + fun getKeyCheckAsStr( ) : String? { + + if( null == this.keyCheck ) return null; + return String(keyCheck!!) + } + + + + fun getKeyCheckAsHex( ) : String? { + + if( null == this.keyCheck ) return null; + return Util.bytes2HexString(keyCheck) + } + + + + fun setKeyCheck( bytes : ByteArray ) : Data { + + this.keyCheck = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != keyHead ){ + + + soup.put("keyHead", this.keyHead!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != keyCheck ){ + + + soup.put("keyCheck", this.keyCheck!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("keyHead") ){ + + + this.keyHead = (soup.get("keyHead") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheck") ){ + + + this.keyCheck = (soup.get("keyCheck") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4E46")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4E46") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTONG.kt b/src/main/java/racal/sunyard/main/dto/DTONG.kt new file mode 100644 index 0000000..f9e533a --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTONG.kt @@ -0,0 +1,987 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTONG { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var alg : ByteArray? = null + private var pINBLOCK : ByteArray? = null + private var account : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPV3DES(Util.hexString2Bytes("30")), +OPVSM4(Util.hexString2Bytes("31")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return "3DES" + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + return null + } + + + + fun getPINBLOCKAsBin( ) : ByteArray? { + + return this.pINBLOCK + } + + + + fun getPINBLOCKAsStr( ) : String? { + + if( null == this.pINBLOCK ) return null; + return String(pINBLOCK!!) + } + + + + fun getPINBLOCKAsHex( ) : String? { + + if( null == this.pINBLOCK ) return null; + return Util.bytes2HexString(pINBLOCK) + } + + + + fun setPINBLOCK( bytes : ByteArray ) : Data { + + this.pINBLOCK = bytes + return this + } + + + + fun getAccountAsBin( ) : ByteArray? { + + return this.account + } + + + + fun getAccountAsStr( ) : String? { + + if( null == this.account ) return null; + return String(account!!) + } + + + + fun getAccountAsHex( ) : String? { + + if( null == this.account ) return null; + return Util.bytes2HexString(account) + } + + + + fun setAccount( bytes : ByteArray ) : Data { + + this.account = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != pINBLOCK ){ + + + soup.put("PINBLOCK", this.pINBLOCK!!) + } + +if( null != account ){ + + + soup.put("account", this.account!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("PINBLOCK") ){ + + + this.pINBLOCK = (soup.get("PINBLOCK") as PacketSection).bytes +} + + +if( soup.containsKey("account") ){ + + + this.account = (soup.get("account") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4E47")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4E47") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var pIN : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV加密PIN错误(Util.hexString2Bytes("3134")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3134".equals(Util.bytes2HexString(this.error) ) ) { + + return "加密PIN错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3134".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + return null + } + + + + fun getPINAsBin( ) : ByteArray? { + + return this.pIN + } + + + + fun getPINAsStr( ) : String? { + + if( null == this.pIN ) return null; + return String(pIN!!) + } + + + + fun getPINAsHex( ) : String? { + + if( null == this.pIN ) return null; + return Util.bytes2HexString(pIN) + } + + + + fun setPIN( bytes : ByteArray ) : Data { + + this.pIN = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != pIN ){ + + + soup.put("PIN", this.pIN!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("PIN") ){ + + + this.pIN = (soup.get("PIN") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4E48")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4E48") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOOC.kt b/src/main/java/racal/sunyard/main/dto/DTOOC.kt new file mode 100644 index 0000000..b7583e2 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOOC.kt @@ -0,0 +1,1162 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOOC { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var print : ByteArray? = null + private var delimiter : ByteArray? = null + private var zmkSolution : ByteArray? = null + private var lmkSolution : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var businessKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getPrintAsBin( ) : ByteArray? { + + return this.print + } + + + + fun getPrintAsStr( ) : String? { + + if( null == this.print ) return null; + return String(print!!) + } + + + + fun getPrintAsHex( ) : String? { + + if( null == this.print ) return null; + return Util.bytes2HexString(print) + } + + + + fun setPrint( bytes : ByteArray ) : Data { + + this.print = bytes + return this + } + + + + fun getDelimiterAsBin( ) : ByteArray? { + + return this.delimiter + } + + + + fun getDelimiterAsStr( ) : String? { + + if( null == this.delimiter ) return null; + return String(delimiter!!) + } + + + + fun getDelimiterAsHex( ) : String? { + + if( null == this.delimiter ) return null; + return Util.bytes2HexString(delimiter) + } + + + + fun setDelimiter( bytes : ByteArray ) : Data { + + this.delimiter = bytes + return this + } + + + + fun getZmkSolutionAsBin( ) : ByteArray? { + + return this.zmkSolution + } + + + + fun getZmkSolutionAsStr( ) : String? { + + if( null == this.zmkSolution ) return null; + return String(zmkSolution!!) + } + + + + fun getZmkSolutionAsHex( ) : String? { + + if( null == this.zmkSolution ) return null; + return Util.bytes2HexString(zmkSolution) + } + + + + fun setZmkSolution( bytes : ByteArray ) : Data { + + this.zmkSolution = bytes + return this + } + + + + fun getLmkSolutionAsBin( ) : ByteArray? { + + return this.lmkSolution + } + + + + fun getLmkSolutionAsStr( ) : String? { + + if( null == this.lmkSolution ) return null; + return String(lmkSolution!!) + } + + + + fun getLmkSolutionAsHex( ) : String? { + + if( null == this.lmkSolution ) return null; + return Util.bytes2HexString(lmkSolution) + } + + + + fun setLmkSolution( bytes : ByteArray ) : Data { + + this.lmkSolution = bytes + return this + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != print ){ + + + soup.put("print", this.print!!) + } + +if( null != delimiter ){ + + + soup.put("delimiter", this.delimiter!!) + } + +if( null != zmkSolution ){ + + + soup.put("zmkSolution", this.zmkSolution!!) + } + +if( null != lmkSolution ){ + + + soup.put("lmkSolution", this.lmkSolution!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("print") ){ + + + this.print = (soup.get("print") as PacketSection).bytes +} + + +if( soup.containsKey("delimiter") ){ + + + this.delimiter = (soup.get("delimiter") as PacketSection).bytes +} + + +if( soup.containsKey("zmkSolution") ){ + + + this.zmkSolution = (soup.get("zmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("lmkSolution") ){ + + + this.lmkSolution = (soup.get("lmkSolution") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4F43")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4F43") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var keyHead : ByteArray? = null + private var key : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV密钥奇偶校验错(Util.hexString2Bytes("3031")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV打印机没有准备好(Util.hexString2Bytes("3136")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV没有装载格式定义(Util.hexString2Bytes("3138")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3136".equals(Util.bytes2HexString(this.error) ) ) { + + return "打印机没有准备好" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3138".equals(Util.bytes2HexString(this.error) ) ) { + + return "没有装载格式定义" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3136".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3138".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + return null + } + + + + fun getKeyHeadAsBin( ) : ByteArray? { + + return this.keyHead + } + + + + fun getKeyHeadAsStr( ) : String? { + + if( null == this.keyHead ) return null; + return String(keyHead!!) + } + + + + fun getKeyHeadAsHex( ) : String? { + + if( null == this.keyHead ) return null; + return Util.bytes2HexString(keyHead) + } + + + + fun setKeyHead( bytes : ByteArray ) : Data { + + this.keyHead = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != keyHead ){ + + + soup.put("keyHead", this.keyHead!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("keyHead") ){ + + + this.keyHead = (soup.get("keyHead") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("4F44")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("4F44") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOPA.kt b/src/main/java/racal/sunyard/main/dto/DTOPA.kt new file mode 100644 index 0000000..7b50669 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOPA.kt @@ -0,0 +1,877 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOPA { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var format : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getFormatAsBin( ) : ByteArray? { + + return this.format + } + + + + fun getFormatAsStr( ) : String? { + + if( null == this.format ) return null; + return String(format!!) + } + + + + fun getFormatAsHex( ) : String? { + + if( null == this.format ) return null; + return Util.bytes2HexString(format) + } + + + + fun setFormat( bytes : ByteArray ) : Data { + + this.format = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != format ){ + + + soup.put("format", this.format!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("format") ){ + + + this.format = (soup.get("format") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5041")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5041") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV公钥不符合编码规则(Util.hexString2Bytes("3034")), +OPV无效的加密标识(Util.hexString2Bytes("3036")), +OPV无效的附加模式标识(Util.hexString2Bytes("3037")), +OPV密钥奇偶校验错误(Util.hexString2Bytes("3130")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV密钥块长度错误(Util.hexString2Bytes("3736")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥不符合编码规则" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的加密标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加模式标识" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥块长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5042")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5042") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOPE.kt b/src/main/java/racal/sunyard/main/dto/DTOPE.kt new file mode 100644 index 0000000..74f568e --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOPE.kt @@ -0,0 +1,1212 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOPE { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var fileType : ByteArray? = null + private var account : ByteArray? = null + private var algorithmKey : ByteArray? = null + private var encryptionAlg : ByteArray? = null + private var pinBlock : ByteArray? = null + private var pinLen : ByteArray? = null + private var print : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getFileTypeAsBin( ) : ByteArray? { + + return this.fileType + } + + + + fun getFileTypeAsStr( ) : String? { + + if( null == this.fileType ) return null; + return String(fileType!!) + } + + + + fun getFileTypeAsHex( ) : String? { + + if( null == this.fileType ) return null; + return Util.bytes2HexString(fileType) + } + + + + fun setFileType( bytes : ByteArray ) : Data { + + this.fileType = bytes + return this + } + + + + fun getAccountAsBin( ) : ByteArray? { + + return this.account + } + + + + fun getAccountAsStr( ) : String? { + + if( null == this.account ) return null; + return String(account!!) + } + + + + fun getAccountAsHex( ) : String? { + + if( null == this.account ) return null; + return Util.bytes2HexString(account) + } + + + + fun setAccount( bytes : ByteArray ) : Data { + + this.account = bytes + return this + } + + + + fun getAlgorithmKeyAsBin( ) : ByteArray? { + + return this.algorithmKey + } + + + + fun getAlgorithmKeyAsStr( ) : String? { + + if( null == this.algorithmKey ) return null; + return String(algorithmKey!!) + } + + + + fun getAlgorithmKeyAsHex( ) : String? { + + if( null == this.algorithmKey ) return null; + return Util.bytes2HexString(algorithmKey) + } + + + + fun setAlgorithmKey( bytes : ByteArray ) : Data { + + this.algorithmKey = bytes + return this + } + + + + fun getEncryptionAlgAsBin( ) : ByteArray? { + + return this.encryptionAlg + } + + + + fun getEncryptionAlgAsStr( ) : String? { + + if( null == this.encryptionAlg ) return null; + return String(encryptionAlg!!) + } + + + + fun getEncryptionAlgAsHex( ) : String? { + + if( null == this.encryptionAlg ) return null; + return Util.bytes2HexString(encryptionAlg) + } + + + + fun setEncryptionAlg( bytes : ByteArray ) : Data { + + this.encryptionAlg = bytes + return this + } + + + enum class EncryptionAlgOptions( val bin : ByteArray ) { + +OPVDES(Util.hexString2Bytes("30")), +OPV3DES默认(Util.hexString2Bytes("31")), +OPVSM4(Util.hexString2Bytes("32")), + } + + fun getEncryptionAlgCn( ) : String? { + + if( null == encryptionAlg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.encryptionAlg) ) ) { + + return "DES" + +} + + +if( "31".equals(Util.bytes2HexString(this.encryptionAlg) ) ) { + + return "3DES(默认)" + +} + + +if( "32".equals(Util.bytes2HexString(this.encryptionAlg) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getEncryptionAlgOptionIndex( ) : Int? { + + if( null == encryptionAlg ) { return null } + +if( "30".equals(Util.bytes2HexString(this.encryptionAlg) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.encryptionAlg) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.encryptionAlg) ) ) { + + return 2 + +} + + return null + } + + + + fun getPinBlockAsBin( ) : ByteArray? { + + return this.pinBlock + } + + + + fun getPinBlockAsStr( ) : String? { + + if( null == this.pinBlock ) return null; + return String(pinBlock!!) + } + + + + fun getPinBlockAsHex( ) : String? { + + if( null == this.pinBlock ) return null; + return Util.bytes2HexString(pinBlock) + } + + + + fun setPinBlock( bytes : ByteArray ) : Data { + + this.pinBlock = bytes + return this + } + + + + fun getPinLenAsBin( ) : ByteArray? { + + return this.pinLen + } + + + + fun getPinLenAsStr( ) : String? { + + if( null == this.pinLen ) return null; + return String(pinLen!!) + } + + + + fun getPinLenAsHex( ) : String? { + + if( null == this.pinLen ) return null; + return Util.bytes2HexString(pinLen) + } + + + + fun setPinLen( bytes : ByteArray ) : Data { + + this.pinLen = bytes + return this + } + + + + fun getPrintAsBin( ) : ByteArray? { + + return this.print + } + + + + fun getPrintAsStr( ) : String? { + + if( null == this.print ) return null; + return String(print!!) + } + + + + fun getPrintAsHex( ) : String? { + + if( null == this.print ) return null; + return Util.bytes2HexString(print) + } + + + + fun setPrint( bytes : ByteArray ) : Data { + + this.print = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != fileType ){ + + + soup.put("fileType", this.fileType!!) + } + +if( null != account ){ + + + soup.put("account", this.account!!) + } + +if( null != algorithmKey ){ + + + soup.put("algorithmKey", this.algorithmKey!!) + } + +if( null != encryptionAlg ){ + + + soup.put("encryptionAlg", this.encryptionAlg!!) + soup.put("encryptionAlg\$option", getEncryptionAlgOptionIndex()!!) + } + +if( null != pinBlock ){ + + + soup.put("pinBlock", this.pinBlock!!) + } + +if( null != pinLen ){ + + + soup.put("pinLen", this.pinLen!!) + } + +if( null != print ){ + + + soup.put("print", this.print!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("fileType") ){ + + + this.fileType = (soup.get("fileType") as PacketSection).bytes +} + + +if( soup.containsKey("account") ){ + + + this.account = (soup.get("account") as PacketSection).bytes +} + + +if( soup.containsKey("algorithmKey") ){ + + + this.algorithmKey = (soup.get("algorithmKey") as PacketSection).bytes +} + + +if( soup.containsKey("encryptionAlg") ){ + + + this.encryptionAlg = (soup.get("encryptionAlg") as PacketSection).bytes +} + + +if( soup.containsKey("pinBlock") ){ + + + this.pinBlock = (soup.get("pinBlock") as PacketSection).bytes +} + + +if( soup.containsKey("pinLen") ){ + + + this.pinLen = (soup.get("pinLen") as PacketSection).bytes +} + + +if( soup.containsKey("print") ){ + + + this.print = (soup.get("print") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5045")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5045") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV来自主机的PIN错误(Util.hexString2Bytes("3134")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV打印机没有准备好没有连接上(Util.hexString2Bytes("3136")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV没有装载格式定义(Util.hexString2Bytes("3138")), +OPVPIN块错误(Util.hexString2Bytes("3230")), +OPV无效的账号(Util.hexString2Bytes("3232")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3134".equals(Util.bytes2HexString(this.error) ) ) { + + return "来自主机的PIN错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3136".equals(Util.bytes2HexString(this.error) ) ) { + + return "打印机没有准备好,没有连接上" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3138".equals(Util.bytes2HexString(this.error) ) ) { + + return "没有装载格式定义" + +} + + +if( "3230".equals(Util.bytes2HexString(this.error) ) ) { + + return "PIN块错误" + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的账号" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3134".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3136".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3138".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3230".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3232".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + return null + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5046")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5046") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOQ1.kt b/src/main/java/racal/sunyard/main/dto/DTOQ1.kt new file mode 100644 index 0000000..548701c --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOQ1.kt @@ -0,0 +1,1507 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOQ1 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var alg : ByteArray? = null + private var roundModel : ByteArray? = null + private var fullMode : ByteArray? = null + private var dEK : ByteArray? = null + private var businessKey : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var vectorLength : ByteArray? = null + private var vector : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPVDES(Util.hexString2Bytes("31")), +OPV3DES(Util.hexString2Bytes("32")), +OPVIDEA(Util.hexString2Bytes("33")), +OPVSM1(Util.hexString2Bytes("34")), +OPVAES(Util.hexString2Bytes("35")), +OPVSM4(Util.hexString2Bytes("36")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return "3DES" + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return "IDEA" + +} + + +if( "34".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM1" + +} + + +if( "35".equals(Util.bytes2HexString(this.alg) ) ) { + + return "AES" + +} + + +if( "36".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return 2 + +} + + +if( "34".equals(Util.bytes2HexString(this.alg) ) ) { + + return 3 + +} + + +if( "35".equals(Util.bytes2HexString(this.alg) ) ) { + + return 4 + +} + + +if( "36".equals(Util.bytes2HexString(this.alg) ) ) { + + return 5 + +} + + return null + } + + + + fun getRoundModelAsBin( ) : ByteArray? { + + return this.roundModel + } + + + + fun getRoundModelAsStr( ) : String? { + + if( null == this.roundModel ) return null; + return String(roundModel!!) + } + + + + fun getRoundModelAsHex( ) : String? { + + if( null == this.roundModel ) return null; + return Util.bytes2HexString(roundModel) + } + + + + fun setRoundModel( bytes : ByteArray ) : Data { + + this.roundModel = bytes + return this + } + + + enum class RoundModelOptions( val bin : ByteArray ) { + +OPVECB(Util.hexString2Bytes("31")), +OPVCBC(Util.hexString2Bytes("32")), +OPVCFB(Util.hexString2Bytes("33")), +OPVOFB(Util.hexString2Bytes("34")), + } + + fun getRoundModelCn( ) : String? { + + if( null == roundModel ) { return null } + +if( "31".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "ECB" + +} + + +if( "32".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "CBC" + +} + + +if( "33".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "CFB" + +} + + +if( "34".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "OFB" + +} + + return null + } + + + + fun getRoundModelOptionIndex( ) : Int? { + + if( null == roundModel ) { return null } + +if( "31".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 1 + +} + + +if( "33".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 2 + +} + + +if( "34".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 3 + +} + + return null + } + + + + fun getFullModeAsBin( ) : ByteArray? { + + return this.fullMode + } + + + + fun getFullModeAsStr( ) : String? { + + if( null == this.fullMode ) return null; + return String(fullMode!!) + } + + + + fun getFullModeAsHex( ) : String? { + + if( null == this.fullMode ) return null; + return Util.bytes2HexString(fullMode) + } + + + + fun setFullMode( bytes : ByteArray ) : Data { + + this.fullMode = bytes + return this + } + + + enum class FullModeOptions( val bin : ByteArray ) { + +OPV0(Util.hexString2Bytes("30")), +OPV1(Util.hexString2Bytes("31")), +OPV2(Util.hexString2Bytes("32")), + } + + fun getFullModeCn( ) : String? { + + if( null == fullMode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return "0" + +} + + +if( "31".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return "1" + +} + + +if( "32".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return "2" + +} + + return null + } + + + + fun getFullModeOptionIndex( ) : Int? { + + if( null == fullMode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return 2 + +} + + return null + } + + + + fun getDEKAsBin( ) : ByteArray? { + + return this.dEK + } + + + + fun getDEKAsStr( ) : String? { + + if( null == this.dEK ) return null; + return String(dEK!!) + } + + + + fun getDEKAsHex( ) : String? { + + if( null == this.dEK ) return null; + return Util.bytes2HexString(dEK) + } + + + + fun setDEK( bytes : ByteArray ) : Data { + + this.dEK = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getVectorLengthAsBin( ) : ByteArray? { + + return this.vectorLength + } + + + + fun getVectorLengthAsStr( ) : String? { + + if( null == this.vectorLength ) return null; + return String(vectorLength!!) + } + + + + fun getVectorLengthAsHex( ) : String? { + + if( null == this.vectorLength ) return null; + return Util.bytes2HexString(vectorLength) + } + + + + fun setVectorLength( bytes : ByteArray ) : Data { + + this.vectorLength = bytes + return this + } + + + + fun getVectorAsBin( ) : ByteArray? { + + return this.vector + } + + + + fun getVectorAsStr( ) : String? { + + if( null == this.vector ) return null; + return String(vector!!) + } + + + + fun getVectorAsHex( ) : String? { + + if( null == this.vector ) return null; + return Util.bytes2HexString(vector) + } + + + + fun setVector( bytes : ByteArray ) : Data { + + this.vector = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != roundModel ){ + + + soup.put("roundModel", this.roundModel!!) + soup.put("roundModel\$option", getRoundModelOptionIndex()!!) + } + +if( null != fullMode ){ + + + soup.put("fullMode", this.fullMode!!) + soup.put("fullMode\$option", getFullModeOptionIndex()!!) + } + +if( null != dEK ){ + + + soup.put("DEK", this.dEK!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + +if( null != vectorLength ){ + + + soup.put("vectorLength", this.vectorLength!!) + } + +if( null != vector ){ + + + soup.put("vector", this.vector!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("roundModel") ){ + + + this.roundModel = (soup.get("roundModel") as PacketSection).bytes +} + + +if( soup.containsKey("fullMode") ){ + + + this.fullMode = (soup.get("fullMode") as PacketSection).bytes +} + + +if( soup.containsKey("DEK") ){ + + + this.dEK = (soup.get("DEK") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + +if( soup.containsKey("vectorLength") ){ + + + this.vectorLength = (soup.get("vectorLength") as PacketSection).bytes +} + + +if( soup.containsKey("vector") ){ + + + this.vector = (soup.get("vector") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5131")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5131") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + return null + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5132")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5132") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOQ2.kt b/src/main/java/racal/sunyard/main/dto/DTOQ2.kt new file mode 100644 index 0000000..ed71757 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOQ2.kt @@ -0,0 +1,1507 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOQ2 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var alg : ByteArray? = null + private var roundModel : ByteArray? = null + private var fullMode : ByteArray? = null + private var dEK : ByteArray? = null + private var businessKey : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var vectorLength : ByteArray? = null + private var vector : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getAlgAsBin( ) : ByteArray? { + + return this.alg + } + + + + fun getAlgAsStr( ) : String? { + + if( null == this.alg ) return null; + return String(alg!!) + } + + + + fun getAlgAsHex( ) : String? { + + if( null == this.alg ) return null; + return Util.bytes2HexString(alg) + } + + + + fun setAlg( bytes : ByteArray ) : Data { + + this.alg = bytes + return this + } + + + enum class AlgOptions( val bin : ByteArray ) { + +OPVDES(Util.hexString2Bytes("31")), +OPV3DES(Util.hexString2Bytes("32")), +OPVIDEA(Util.hexString2Bytes("33")), +OPVSM1(Util.hexString2Bytes("34")), +OPVAES(Util.hexString2Bytes("35")), +OPVSM4(Util.hexString2Bytes("36")), + } + + fun getAlgCn( ) : String? { + + if( null == alg ) { return null } + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return "DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return "3DES" + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return "IDEA" + +} + + +if( "34".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM1" + +} + + +if( "35".equals(Util.bytes2HexString(this.alg) ) ) { + + return "AES" + +} + + +if( "36".equals(Util.bytes2HexString(this.alg) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getAlgOptionIndex( ) : Int? { + + if( null == alg ) { return null } + +if( "31".equals(Util.bytes2HexString(this.alg) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.alg) ) ) { + + return 1 + +} + + +if( "33".equals(Util.bytes2HexString(this.alg) ) ) { + + return 2 + +} + + +if( "34".equals(Util.bytes2HexString(this.alg) ) ) { + + return 3 + +} + + +if( "35".equals(Util.bytes2HexString(this.alg) ) ) { + + return 4 + +} + + +if( "36".equals(Util.bytes2HexString(this.alg) ) ) { + + return 5 + +} + + return null + } + + + + fun getRoundModelAsBin( ) : ByteArray? { + + return this.roundModel + } + + + + fun getRoundModelAsStr( ) : String? { + + if( null == this.roundModel ) return null; + return String(roundModel!!) + } + + + + fun getRoundModelAsHex( ) : String? { + + if( null == this.roundModel ) return null; + return Util.bytes2HexString(roundModel) + } + + + + fun setRoundModel( bytes : ByteArray ) : Data { + + this.roundModel = bytes + return this + } + + + enum class RoundModelOptions( val bin : ByteArray ) { + +OPVECB(Util.hexString2Bytes("31")), +OPVCBC(Util.hexString2Bytes("32")), +OPVCFB(Util.hexString2Bytes("33")), +OPVOFB(Util.hexString2Bytes("34")), + } + + fun getRoundModelCn( ) : String? { + + if( null == roundModel ) { return null } + +if( "31".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "ECB" + +} + + +if( "32".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "CBC" + +} + + +if( "33".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "CFB" + +} + + +if( "34".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "OFB" + +} + + return null + } + + + + fun getRoundModelOptionIndex( ) : Int? { + + if( null == roundModel ) { return null } + +if( "31".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 1 + +} + + +if( "33".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 2 + +} + + +if( "34".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 3 + +} + + return null + } + + + + fun getFullModeAsBin( ) : ByteArray? { + + return this.fullMode + } + + + + fun getFullModeAsStr( ) : String? { + + if( null == this.fullMode ) return null; + return String(fullMode!!) + } + + + + fun getFullModeAsHex( ) : String? { + + if( null == this.fullMode ) return null; + return Util.bytes2HexString(fullMode) + } + + + + fun setFullMode( bytes : ByteArray ) : Data { + + this.fullMode = bytes + return this + } + + + enum class FullModeOptions( val bin : ByteArray ) { + +OPV0(Util.hexString2Bytes("30")), +OPV1(Util.hexString2Bytes("31")), +OPV2(Util.hexString2Bytes("32")), + } + + fun getFullModeCn( ) : String? { + + if( null == fullMode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return "0" + +} + + +if( "31".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return "1" + +} + + +if( "32".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return "2" + +} + + return null + } + + + + fun getFullModeOptionIndex( ) : Int? { + + if( null == fullMode ) { return null } + +if( "30".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return 1 + +} + + +if( "32".equals(Util.bytes2HexString(this.fullMode) ) ) { + + return 2 + +} + + return null + } + + + + fun getDEKAsBin( ) : ByteArray? { + + return this.dEK + } + + + + fun getDEKAsStr( ) : String? { + + if( null == this.dEK ) return null; + return String(dEK!!) + } + + + + fun getDEKAsHex( ) : String? { + + if( null == this.dEK ) return null; + return Util.bytes2HexString(dEK) + } + + + + fun setDEK( bytes : ByteArray ) : Data { + + this.dEK = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getVectorLengthAsBin( ) : ByteArray? { + + return this.vectorLength + } + + + + fun getVectorLengthAsStr( ) : String? { + + if( null == this.vectorLength ) return null; + return String(vectorLength!!) + } + + + + fun getVectorLengthAsHex( ) : String? { + + if( null == this.vectorLength ) return null; + return Util.bytes2HexString(vectorLength) + } + + + + fun setVectorLength( bytes : ByteArray ) : Data { + + this.vectorLength = bytes + return this + } + + + + fun getVectorAsBin( ) : ByteArray? { + + return this.vector + } + + + + fun getVectorAsStr( ) : String? { + + if( null == this.vector ) return null; + return String(vector!!) + } + + + + fun getVectorAsHex( ) : String? { + + if( null == this.vector ) return null; + return Util.bytes2HexString(vector) + } + + + + fun setVector( bytes : ByteArray ) : Data { + + this.vector = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != alg ){ + + + soup.put("alg", this.alg!!) + soup.put("alg\$option", getAlgOptionIndex()!!) + } + +if( null != roundModel ){ + + + soup.put("roundModel", this.roundModel!!) + soup.put("roundModel\$option", getRoundModelOptionIndex()!!) + } + +if( null != fullMode ){ + + + soup.put("fullMode", this.fullMode!!) + soup.put("fullMode\$option", getFullModeOptionIndex()!!) + } + +if( null != dEK ){ + + + soup.put("DEK", this.dEK!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + +if( null != vectorLength ){ + + + soup.put("vectorLength", this.vectorLength!!) + } + +if( null != vector ){ + + + soup.put("vector", this.vector!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("alg") ){ + + + this.alg = (soup.get("alg") as PacketSection).bytes +} + + +if( soup.containsKey("roundModel") ){ + + + this.roundModel = (soup.get("roundModel") as PacketSection).bytes +} + + +if( soup.containsKey("fullMode") ){ + + + this.fullMode = (soup.get("fullMode") as PacketSection).bytes +} + + +if( soup.containsKey("DEK") ){ + + + this.dEK = (soup.get("DEK") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + +if( soup.containsKey("vectorLength") ){ + + + this.vectorLength = (soup.get("vectorLength") as PacketSection).bytes +} + + +if( soup.containsKey("vector") ){ + + + this.vector = (soup.get("vector") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5132")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5132") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + return null + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5133")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5133") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOQN.kt b/src/main/java/racal/sunyard/main/dto/DTOQN.kt new file mode 100644 index 0000000..e59dd1e --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOQN.kt @@ -0,0 +1,845 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOQN { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var keyLen : ByteArray? = null + private var sk : ByteArray? = null + private var startTime : ByteArray? = null + private var endTime : ByteArray? = null + + + fun getKeyLenAsBin( ) : ByteArray? { + + return this.keyLen + } + + + + fun getKeyLenAsStr( ) : String? { + + if( null == this.keyLen ) return null; + return String(keyLen!!) + } + + + + fun getKeyLenAsHex( ) : String? { + + if( null == this.keyLen ) return null; + return Util.bytes2HexString(keyLen) + } + + + + fun setKeyLen( bytes : ByteArray ) : Data { + + this.keyLen = bytes + return this + } + + + + fun getSkAsBin( ) : ByteArray? { + + return this.sk + } + + + + fun getSkAsStr( ) : String? { + + if( null == this.sk ) return null; + return String(sk!!) + } + + + + fun getSkAsHex( ) : String? { + + if( null == this.sk ) return null; + return Util.bytes2HexString(sk) + } + + + + fun setSk( bytes : ByteArray ) : Data { + + this.sk = bytes + return this + } + + + + fun getStartTimeAsBin( ) : ByteArray? { + + return this.startTime + } + + + + fun getStartTimeAsStr( ) : String? { + + if( null == this.startTime ) return null; + return String(startTime!!) + } + + + + fun getStartTimeAsHex( ) : String? { + + if( null == this.startTime ) return null; + return Util.bytes2HexString(startTime) + } + + + + fun setStartTime( bytes : ByteArray ) : Data { + + this.startTime = bytes + return this + } + + + + fun getEndTimeAsBin( ) : ByteArray? { + + return this.endTime + } + + + + fun getEndTimeAsStr( ) : String? { + + if( null == this.endTime ) return null; + return String(endTime!!) + } + + + + fun getEndTimeAsHex( ) : String? { + + if( null == this.endTime ) return null; + return Util.bytes2HexString(endTime) + } + + + + fun setEndTime( bytes : ByteArray ) : Data { + + this.endTime = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + soup.put("keyLen", Util.hexString2Bytes("30323536")) + +if( null != keyLen ){ + + + soup.put("keyLen", this.keyLen!!) + } + +if( null != sk ){ + + + soup.put("sk", this.sk!!) + } + +if( null != startTime ){ + + + soup.put("startTime", this.startTime!!) + } + +if( null != endTime ){ + + + soup.put("endTime", this.endTime!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + this.keyLen = Util.hexString2Bytes("30323536") + +if( soup.containsKey("keyLen") ){ + + + this.keyLen = (soup.get("keyLen") as PacketSection).bytes +} + + +if( soup.containsKey("sk") ){ + + + this.sk = (soup.get("sk") as PacketSection).bytes +} + + +if( soup.containsKey("startTime") ){ + + + this.startTime = (soup.get("startTime") as PacketSection).bytes +} + + +if( soup.containsKey("endTime") ){ + + + this.endTime = (soup.get("endTime") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("514E")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("514E") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var pk : ByteArray? = null + private var sk : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效的哈希标识(Util.hexString2Bytes("3035")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的哈希标识" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + return null + } + + + + fun getPkAsBin( ) : ByteArray? { + + return this.pk + } + + + + fun getPkAsStr( ) : String? { + + if( null == this.pk ) return null; + return String(pk!!) + } + + + + fun getPkAsHex( ) : String? { + + if( null == this.pk ) return null; + return Util.bytes2HexString(pk) + } + + + + fun setPk( bytes : ByteArray ) : Data { + + this.pk = bytes + return this + } + + + + fun getSkAsBin( ) : ByteArray? { + + return this.sk + } + + + + fun getSkAsStr( ) : String? { + + if( null == this.sk ) return null; + return String(sk!!) + } + + + + fun getSkAsHex( ) : String? { + + if( null == this.sk ) return null; + return Util.bytes2HexString(sk) + } + + + + fun setSk( bytes : ByteArray ) : Data { + + this.sk = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != pk ){ + + + soup.put("pk", this.pk!!) + } + +if( null != sk ){ + + + soup.put("sk", this.sk!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("pk") ){ + + + this.pk = (soup.get("pk") as PacketSection).bytes +} + + +if( soup.containsKey("sk") ){ + + + this.sk = (soup.get("sk") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("514F")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("514F") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOQQ.kt b/src/main/java/racal/sunyard/main/dto/DTOQQ.kt new file mode 100644 index 0000000..2cbc017 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOQQ.kt @@ -0,0 +1,935 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOQQ { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var privateKeyTag : ByteArray? = null + + + fun getPrivateKeyTagAsBin( ) : ByteArray? { + + return this.privateKeyTag + } + + + + fun getPrivateKeyTagAsStr( ) : String? { + + if( null == this.privateKeyTag ) return null; + return String(privateKeyTag!!) + } + + + + fun getPrivateKeyTagAsHex( ) : String? { + + if( null == this.privateKeyTag ) return null; + return Util.bytes2HexString(privateKeyTag) + } + + + + fun setPrivateKeyTag( bytes : ByteArray ) : Data { + + this.privateKeyTag = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != privateKeyTag ){ + + + soup.put("privateKeyTag", this.privateKeyTag!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("privateKeyTag") ){ + + + this.privateKeyTag = (soup.get("privateKeyTag") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5151")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5151") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var publicLen : ByteArray? = null + private var publicKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效的私钥类型(Util.hexString2Bytes("3033")), +OPV无效私钥标记(Util.hexString2Bytes("3034")), +OPV无效的哈希标识(Util.hexString2Bytes("3035")), +OPV无效的签名标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV无效摘要信息语法仅仅无哈希模式(Util.hexString2Bytes("3734")), +OPV公钥长度错误(Util.hexString2Bytes("3736")), +OPV私钥长度错误(Util.hexString2Bytes("3738")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的私钥类型" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效私钥标记" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的哈希标识" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的签名标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效摘要信息语法(仅仅无哈希模式)" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥长度错误" + +} + + +if( "3738".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + +if( "3738".equals(Util.bytes2HexString(this.error) ) ) { + + return 12 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 13 + +} + + return null + } + + + + fun getPublicLenAsBin( ) : ByteArray? { + + return this.publicLen + } + + + + fun getPublicLenAsStr( ) : String? { + + if( null == this.publicLen ) return null; + return String(publicLen!!) + } + + + + fun getPublicLenAsHex( ) : String? { + + if( null == this.publicLen ) return null; + return Util.bytes2HexString(publicLen) + } + + + + fun setPublicLen( bytes : ByteArray ) : Data { + + this.publicLen = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != publicLen ){ + + + soup.put("publicLen", this.publicLen!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("publicLen") ){ + + + this.publicLen = (soup.get("publicLen") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5152")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5152") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOQX.kt b/src/main/java/racal/sunyard/main/dto/DTOQX.kt new file mode 100644 index 0000000..71ac2a9 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOQX.kt @@ -0,0 +1,935 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOQX { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var privateKeyTag : ByteArray? = null + + + fun getPrivateKeyTagAsBin( ) : ByteArray? { + + return this.privateKeyTag + } + + + + fun getPrivateKeyTagAsStr( ) : String? { + + if( null == this.privateKeyTag ) return null; + return String(privateKeyTag!!) + } + + + + fun getPrivateKeyTagAsHex( ) : String? { + + if( null == this.privateKeyTag ) return null; + return Util.bytes2HexString(privateKeyTag) + } + + + + fun setPrivateKeyTag( bytes : ByteArray ) : Data { + + this.privateKeyTag = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != privateKeyTag ){ + + + soup.put("privateKeyTag", this.privateKeyTag!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("privateKeyTag") ){ + + + this.privateKeyTag = (soup.get("privateKeyTag") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5158")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5158") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var publicLen : ByteArray? = null + private var publicKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效的私钥类型(Util.hexString2Bytes("3033")), +OPV无效私钥标记(Util.hexString2Bytes("3034")), +OPV无效的哈希标识(Util.hexString2Bytes("3035")), +OPV无效的签名标识(Util.hexString2Bytes("3036")), +OPV无效的附加标识(Util.hexString2Bytes("3037")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPVDSP错误(Util.hexString2Bytes("3437")), +OPV私钥错误(Util.hexString2Bytes("3439")), +OPV无效摘要信息语法仅仅无哈希模式(Util.hexString2Bytes("3734")), +OPV公钥长度错误(Util.hexString2Bytes("3736")), +OPV私钥长度错误(Util.hexString2Bytes("3738")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的私钥类型" + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效私钥标记" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的哈希标识" + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的签名标识" + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的附加标识" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP 错误" + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥错误" + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效摘要信息语法(仅仅无哈希模式)" + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return "公钥长度错误" + +} + + +if( "3738".equals(Util.bytes2HexString(this.error) ) ) { + + return "私钥长度错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3033".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3034".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3036".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3037".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3439".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3734".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + +if( "3736".equals(Util.bytes2HexString(this.error) ) ) { + + return 11 + +} + + +if( "3738".equals(Util.bytes2HexString(this.error) ) ) { + + return 12 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 13 + +} + + return null + } + + + + fun getPublicLenAsBin( ) : ByteArray? { + + return this.publicLen + } + + + + fun getPublicLenAsStr( ) : String? { + + if( null == this.publicLen ) return null; + return String(publicLen!!) + } + + + + fun getPublicLenAsHex( ) : String? { + + if( null == this.publicLen ) return null; + return Util.bytes2HexString(publicLen) + } + + + + fun setPublicLen( bytes : ByteArray ) : Data { + + this.publicLen = bytes + return this + } + + + + fun getPublicKeyAsBin( ) : ByteArray? { + + return this.publicKey + } + + + + fun getPublicKeyAsStr( ) : String? { + + if( null == this.publicKey ) return null; + return String(publicKey!!) + } + + + + fun getPublicKeyAsHex( ) : String? { + + if( null == this.publicKey ) return null; + return Util.bytes2HexString(publicKey) + } + + + + fun setPublicKey( bytes : ByteArray ) : Data { + + this.publicKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != publicLen ){ + + + soup.put("publicLen", this.publicLen!!) + } + +if( null != publicKey ){ + + + soup.put("publicKey", this.publicKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("publicLen") ){ + + + this.publicLen = (soup.get("publicLen") as PacketSection).bytes +} + + +if( soup.containsKey("publicKey") ){ + + + this.publicKey = (soup.get("publicKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5159")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5159") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOTC.kt b/src/main/java/racal/sunyard/main/dto/DTOTC.kt new file mode 100644 index 0000000..6766254 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOTC.kt @@ -0,0 +1,982 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOTC { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var type : ByteArray? = null + private var key : ByteArray? = null + private var print : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getTypeAsBin( ) : ByteArray? { + + return this.type + } + + + + fun getTypeAsStr( ) : String? { + + if( null == this.type ) return null; + return String(type!!) + } + + + + fun getTypeAsHex( ) : String? { + + if( null == this.type ) return null; + return Util.bytes2HexString(type) + } + + + + fun setType( bytes : ByteArray ) : Data { + + this.type = bytes + return this + } + + + + fun getKeyAsBin( ) : ByteArray? { + + return this.key + } + + + + fun getKeyAsStr( ) : String? { + + if( null == this.key ) return null; + return String(key!!) + } + + + + fun getKeyAsHex( ) : String? { + + if( null == this.key ) return null; + return Util.bytes2HexString(key) + } + + + + fun setKey( bytes : ByteArray ) : Data { + + this.key = bytes + return this + } + + + + fun getPrintAsBin( ) : ByteArray? { + + return this.print + } + + + + fun getPrintAsStr( ) : String? { + + if( null == this.print ) return null; + return String(print!!) + } + + + + fun getPrintAsHex( ) : String? { + + if( null == this.print ) return null; + return Util.bytes2HexString(print) + } + + + + fun setPrint( bytes : ByteArray ) : Data { + + this.print = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != type ){ + + + soup.put("type", this.type!!) + } + +if( null != key ){ + + + soup.put("key", this.key!!) + } + +if( null != print ){ + + + soup.put("print", this.print!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("type") ){ + + + this.type = (soup.get("type") as PacketSection).bytes +} + + +if( soup.containsKey("key") ){ + + + this.key = (soup.get("key") as PacketSection).bytes +} + + +if( soup.containsKey("print") ){ + + + this.print = (soup.get("print") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5443")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5443") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV密钥奇偶校验错(Util.hexString2Bytes("3031")), +OPVZMK奇偶校验错(Util.hexString2Bytes("3130")), +OPV用户存储区中没有装载密钥(Util.hexString2Bytes("3132")), +OPVLMK错误(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV不在授权状态(Util.hexString2Bytes("3137")), +OPV无效用户存储区索引(Util.hexString2Bytes("3231")), +OPV无效的密钥类型(Util.hexString2Bytes("3238")), +OPV无效的密钥方案(Util.hexString2Bytes("3236")), +OPV输入数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥奇偶校验错" + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return "ZMK 奇偶校验错" + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return "用户存储区中没有装载密钥" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK 错误" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return "不在授权状态" + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效用户存储区索引" + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥类型" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥方案" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3031".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3130".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3132".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 5 + +} + + +if( "3137".equals(Util.bytes2HexString(this.error) ) ) { + + return 6 + +} + + +if( "3231".equals(Util.bytes2HexString(this.error) ) ) { + + return 7 + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return 8 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 9 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 10 + +} + + return null + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5444")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5444") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOY0.kt b/src/main/java/racal/sunyard/main/dto/DTOY0.kt new file mode 100644 index 0000000..1204a9d --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOY0.kt @@ -0,0 +1,1644 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOY0 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var srcKeyType : ByteArray? = null + private var sca : ByteArray? = null + private var desKeyType : ByteArray? = null + private var dca : ByteArray? = null + private var roundModel : ByteArray? = null + private var sDEK : ByteArray? = null + private var dDEK : ByteArray? = null + private var dataLength : ByteArray? = null + private var infoData : ByteArray? = null + private var vectorLength : ByteArray? = null + private var vector : ByteArray? = null + private var businessKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getSrcKeyTypeAsBin( ) : ByteArray? { + + return this.srcKeyType + } + + + + fun getSrcKeyTypeAsStr( ) : String? { + + if( null == this.srcKeyType ) return null; + return String(srcKeyType!!) + } + + + + fun getSrcKeyTypeAsHex( ) : String? { + + if( null == this.srcKeyType ) return null; + return Util.bytes2HexString(srcKeyType) + } + + + + fun setSrcKeyType( bytes : ByteArray ) : Data { + + this.srcKeyType = bytes + return this + } + + + + fun getScaAsBin( ) : ByteArray? { + + return this.sca + } + + + + fun getScaAsStr( ) : String? { + + if( null == this.sca ) return null; + return String(sca!!) + } + + + + fun getScaAsHex( ) : String? { + + if( null == this.sca ) return null; + return Util.bytes2HexString(sca) + } + + + + fun setSca( bytes : ByteArray ) : Data { + + this.sca = bytes + return this + } + + + enum class ScaOptions( val bin : ByteArray ) { + +OPVDES(Util.hexString2Bytes("31")), +OPV3DES(Util.hexString2Bytes("32")), +OPVIDEA(Util.hexString2Bytes("33")), +OPVSM1(Util.hexString2Bytes("34")), +OPVAES(Util.hexString2Bytes("35")), +OPVSM4(Util.hexString2Bytes("36")), + } + + fun getScaCn( ) : String? { + + if( null == sca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.sca) ) ) { + + return "DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.sca) ) ) { + + return "3DES" + +} + + +if( "33".equals(Util.bytes2HexString(this.sca) ) ) { + + return "IDEA" + +} + + +if( "34".equals(Util.bytes2HexString(this.sca) ) ) { + + return "SM1" + +} + + +if( "35".equals(Util.bytes2HexString(this.sca) ) ) { + + return "AES" + +} + + +if( "36".equals(Util.bytes2HexString(this.sca) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getScaOptionIndex( ) : Int? { + + if( null == sca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.sca) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.sca) ) ) { + + return 1 + +} + + +if( "33".equals(Util.bytes2HexString(this.sca) ) ) { + + return 2 + +} + + +if( "34".equals(Util.bytes2HexString(this.sca) ) ) { + + return 3 + +} + + +if( "35".equals(Util.bytes2HexString(this.sca) ) ) { + + return 4 + +} + + +if( "36".equals(Util.bytes2HexString(this.sca) ) ) { + + return 5 + +} + + return null + } + + + + fun getDesKeyTypeAsBin( ) : ByteArray? { + + return this.desKeyType + } + + + + fun getDesKeyTypeAsStr( ) : String? { + + if( null == this.desKeyType ) return null; + return String(desKeyType!!) + } + + + + fun getDesKeyTypeAsHex( ) : String? { + + if( null == this.desKeyType ) return null; + return Util.bytes2HexString(desKeyType) + } + + + + fun setDesKeyType( bytes : ByteArray ) : Data { + + this.desKeyType = bytes + return this + } + + + + fun getDcaAsBin( ) : ByteArray? { + + return this.dca + } + + + + fun getDcaAsStr( ) : String? { + + if( null == this.dca ) return null; + return String(dca!!) + } + + + + fun getDcaAsHex( ) : String? { + + if( null == this.dca ) return null; + return Util.bytes2HexString(dca) + } + + + + fun setDca( bytes : ByteArray ) : Data { + + this.dca = bytes + return this + } + + + enum class DcaOptions( val bin : ByteArray ) { + +OPVDES(Util.hexString2Bytes("31")), +OPV3DES(Util.hexString2Bytes("32")), +OPVIDEA(Util.hexString2Bytes("33")), +OPVSM1(Util.hexString2Bytes("34")), +OPVAES(Util.hexString2Bytes("35")), +OPVSM4(Util.hexString2Bytes("36")), + } + + fun getDcaCn( ) : String? { + + if( null == dca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.dca) ) ) { + + return "DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.dca) ) ) { + + return "3DES" + +} + + +if( "33".equals(Util.bytes2HexString(this.dca) ) ) { + + return "IDEA" + +} + + +if( "34".equals(Util.bytes2HexString(this.dca) ) ) { + + return "SM1" + +} + + +if( "35".equals(Util.bytes2HexString(this.dca) ) ) { + + return "AES" + +} + + +if( "36".equals(Util.bytes2HexString(this.dca) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getDcaOptionIndex( ) : Int? { + + if( null == dca ) { return null } + +if( "31".equals(Util.bytes2HexString(this.dca) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.dca) ) ) { + + return 1 + +} + + +if( "33".equals(Util.bytes2HexString(this.dca) ) ) { + + return 2 + +} + + +if( "34".equals(Util.bytes2HexString(this.dca) ) ) { + + return 3 + +} + + +if( "35".equals(Util.bytes2HexString(this.dca) ) ) { + + return 4 + +} + + +if( "36".equals(Util.bytes2HexString(this.dca) ) ) { + + return 5 + +} + + return null + } + + + + fun getRoundModelAsBin( ) : ByteArray? { + + return this.roundModel + } + + + + fun getRoundModelAsStr( ) : String? { + + if( null == this.roundModel ) return null; + return String(roundModel!!) + } + + + + fun getRoundModelAsHex( ) : String? { + + if( null == this.roundModel ) return null; + return Util.bytes2HexString(roundModel) + } + + + + fun setRoundModel( bytes : ByteArray ) : Data { + + this.roundModel = bytes + return this + } + + + enum class RoundModelOptions( val bin : ByteArray ) { + +OPVECB(Util.hexString2Bytes("31")), +OPVCBC(Util.hexString2Bytes("32")), +OPVCFB(Util.hexString2Bytes("33")), +OPVOFB(Util.hexString2Bytes("34")), + } + + fun getRoundModelCn( ) : String? { + + if( null == roundModel ) { return null } + +if( "31".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "ECB" + +} + + +if( "32".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "CBC" + +} + + +if( "33".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "CFB" + +} + + +if( "34".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return "OFB" + +} + + return null + } + + + + fun getRoundModelOptionIndex( ) : Int? { + + if( null == roundModel ) { return null } + +if( "31".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 1 + +} + + +if( "33".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 2 + +} + + +if( "34".equals(Util.bytes2HexString(this.roundModel) ) ) { + + return 3 + +} + + return null + } + + + + fun getSDEKAsBin( ) : ByteArray? { + + return this.sDEK + } + + + + fun getSDEKAsStr( ) : String? { + + if( null == this.sDEK ) return null; + return String(sDEK!!) + } + + + + fun getSDEKAsHex( ) : String? { + + if( null == this.sDEK ) return null; + return Util.bytes2HexString(sDEK) + } + + + + fun setSDEK( bytes : ByteArray ) : Data { + + this.sDEK = bytes + return this + } + + + + fun getDDEKAsBin( ) : ByteArray? { + + return this.dDEK + } + + + + fun getDDEKAsStr( ) : String? { + + if( null == this.dDEK ) return null; + return String(dDEK!!) + } + + + + fun getDDEKAsHex( ) : String? { + + if( null == this.dDEK ) return null; + return Util.bytes2HexString(dDEK) + } + + + + fun setDDEK( bytes : ByteArray ) : Data { + + this.dDEK = bytes + return this + } + + + + fun getDataLengthAsBin( ) : ByteArray? { + + return this.dataLength + } + + + + fun getDataLengthAsStr( ) : String? { + + if( null == this.dataLength ) return null; + return String(dataLength!!) + } + + + + fun getDataLengthAsHex( ) : String? { + + if( null == this.dataLength ) return null; + return Util.bytes2HexString(dataLength) + } + + + + fun setDataLength( bytes : ByteArray ) : Data { + + this.dataLength = bytes + return this + } + + + + fun getInfoDataAsBin( ) : ByteArray? { + + return this.infoData + } + + + + fun getInfoDataAsStr( ) : String? { + + if( null == this.infoData ) return null; + return String(infoData!!) + } + + + + fun getInfoDataAsHex( ) : String? { + + if( null == this.infoData ) return null; + return Util.bytes2HexString(infoData) + } + + + + fun setInfoData( bytes : ByteArray ) : Data { + + this.infoData = bytes + return this + } + + + + fun getVectorLengthAsBin( ) : ByteArray? { + + return this.vectorLength + } + + + + fun getVectorLengthAsStr( ) : String? { + + if( null == this.vectorLength ) return null; + return String(vectorLength!!) + } + + + + fun getVectorLengthAsHex( ) : String? { + + if( null == this.vectorLength ) return null; + return Util.bytes2HexString(vectorLength) + } + + + + fun setVectorLength( bytes : ByteArray ) : Data { + + this.vectorLength = bytes + return this + } + + + + fun getVectorAsBin( ) : ByteArray? { + + return this.vector + } + + + + fun getVectorAsStr( ) : String? { + + if( null == this.vector ) return null; + return String(vector!!) + } + + + + fun getVectorAsHex( ) : String? { + + if( null == this.vector ) return null; + return Util.bytes2HexString(vector) + } + + + + fun setVector( bytes : ByteArray ) : Data { + + this.vector = bytes + return this + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != srcKeyType ){ + + + soup.put("srcKeyType", this.srcKeyType!!) + } + +if( null != sca ){ + + + soup.put("sca", this.sca!!) + soup.put("sca\$option", getScaOptionIndex()!!) + } + +if( null != desKeyType ){ + + + soup.put("desKeyType", this.desKeyType!!) + } + +if( null != dca ){ + + + soup.put("dca", this.dca!!) + soup.put("dca\$option", getDcaOptionIndex()!!) + } + +if( null != roundModel ){ + + + soup.put("roundModel", this.roundModel!!) + soup.put("roundModel\$option", getRoundModelOptionIndex()!!) + } + +if( null != sDEK ){ + + + soup.put("sDEK", this.sDEK!!) + } + +if( null != dDEK ){ + + + soup.put("dDEK", this.dDEK!!) + } + +if( null != dataLength ){ + + + soup.put("dataLength", this.dataLength!!) + } + +if( null != infoData ){ + + + soup.put("infoData", this.infoData!!) + } + +if( null != vectorLength ){ + + + soup.put("vectorLength", this.vectorLength!!) + } + +if( null != vector ){ + + + soup.put("vector", this.vector!!) + } + soup.put("businessKey", Util.hexString2Bytes("4E")) + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("srcKeyType") ){ + + + this.srcKeyType = (soup.get("srcKeyType") as PacketSection).bytes +} + + +if( soup.containsKey("sca") ){ + + + this.sca = (soup.get("sca") as PacketSection).bytes +} + + +if( soup.containsKey("desKeyType") ){ + + + this.desKeyType = (soup.get("desKeyType") as PacketSection).bytes +} + + +if( soup.containsKey("dca") ){ + + + this.dca = (soup.get("dca") as PacketSection).bytes +} + + +if( soup.containsKey("roundModel") ){ + + + this.roundModel = (soup.get("roundModel") as PacketSection).bytes +} + + +if( soup.containsKey("sDEK") ){ + + + this.sDEK = (soup.get("sDEK") as PacketSection).bytes +} + + +if( soup.containsKey("dDEK") ){ + + + this.dDEK = (soup.get("dDEK") as PacketSection).bytes +} + + +if( soup.containsKey("dataLength") ){ + + + this.dataLength = (soup.get("dataLength") as PacketSection).bytes +} + + +if( soup.containsKey("infoData") ){ + + + this.infoData = (soup.get("infoData") as PacketSection).bytes +} + + +if( soup.containsKey("vectorLength") ){ + + + this.vectorLength = (soup.get("vectorLength") as PacketSection).bytes +} + + +if( soup.containsKey("vector") ){ + + + this.vector = (soup.get("vector") as PacketSection).bytes +} + + this.businessKey = Util.hexString2Bytes("4E") + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5930")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5930") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var cipherData : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV输入数据有误(Util.hexString2Bytes("3135")), +OPV密钥方案错误(Util.hexString2Bytes("3236")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据有误" + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return "密钥方案错误" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3236".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + return null + } + + + + fun getCipherDataAsBin( ) : ByteArray? { + + return this.cipherData + } + + + + fun getCipherDataAsStr( ) : String? { + + if( null == this.cipherData ) return null; + return String(cipherData!!) + } + + + + fun getCipherDataAsHex( ) : String? { + + if( null == this.cipherData ) return null; + return Util.bytes2HexString(cipherData) + } + + + + fun setCipherData( bytes : ByteArray ) : Data { + + this.cipherData = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != cipherData ){ + + + soup.put("cipherData", this.cipherData!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("cipherData") ){ + + + this.cipherData = (soup.get("cipherData") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5931")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5931") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOY8.kt b/src/main/java/racal/sunyard/main/dto/DTOY8.kt new file mode 100644 index 0000000..ff60a1b --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOY8.kt @@ -0,0 +1,847 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOY8 { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var nRandomSize : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getNRandomSizeAsBin( ) : ByteArray? { + + return this.nRandomSize + } + + + + fun getNRandomSizeAsStr( ) : String? { + + if( null == this.nRandomSize ) return null; + return String(nRandomSize!!) + } + + + + fun getNRandomSizeAsHex( ) : String? { + + if( null == this.nRandomSize ) return null; + return Util.bytes2HexString(nRandomSize) + } + + + + fun setNRandomSize( bytes : ByteArray ) : Data { + + this.nRandomSize = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != nRandomSize ){ + + + soup.put("nRandomSize", this.nRandomSize!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("nRandomSize") ){ + + + this.nRandomSize = (soup.get("nRandomSize") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5938")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5938") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var random : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPV无效的哈希标识(Util.hexString2Bytes("3035")), +OPV输入数据有误(Util.hexString2Bytes("3135")), +OPVDSP错误报告给管理员(Util.hexString2Bytes("3437")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的哈希标识" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据有误" + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return "DSP:错误,报告给管理员" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3035".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3437".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + return null + } + + + + fun getRandomAsBin( ) : ByteArray? { + + return this.random + } + + + + fun getRandomAsStr( ) : String? { + + if( null == this.random ) return null; + return String(random!!) + } + + + + fun getRandomAsHex( ) : String? { + + if( null == this.random ) return null; + return Util.bytes2HexString(random) + } + + + + fun setRandom( bytes : ByteArray ) : Data { + + this.random = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != random ){ + + + soup.put("random", this.random!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("random") ){ + + + this.random = (soup.get("random") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5939")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5939") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/main/java/racal/sunyard/main/dto/DTOYA.kt b/src/main/java/racal/sunyard/main/dto/DTOYA.kt new file mode 100644 index 0000000..0478c46 --- /dev/null +++ b/src/main/java/racal/sunyard/main/dto/DTOYA.kt @@ -0,0 +1,1280 @@ +package racal.sunyard.main.dto + +import java.nio.ByteBuffer; +import racal.sunyard.main.script.*; +import com.sunyard.proto.section.*; +import com.sunyard.proto.*; +import com.sunyard.*; + +class DTOYA { + public class Req { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Req) { + private var mainKey : ByteArray? = null + private var keyType : ByteArray? = null + private var disperseNum : ByteArray? = null + private var data : ByteArray? = null + private var disperseAlg : ByteArray? = null + private var keyCheckType : ByteArray? = null + private var businessKey : ByteArray? = null + private var tailSep : ByteArray? = null + private var tail : ByteArray? = null + + + fun getMainKeyAsBin( ) : ByteArray? { + + return this.mainKey + } + + + + fun getMainKeyAsStr( ) : String? { + + if( null == this.mainKey ) return null; + return String(mainKey!!) + } + + + + fun getMainKeyAsHex( ) : String? { + + if( null == this.mainKey ) return null; + return Util.bytes2HexString(mainKey) + } + + + + fun setMainKey( bytes : ByteArray ) : Data { + + this.mainKey = bytes + return this + } + + + + fun getKeyTypeAsBin( ) : ByteArray? { + + return this.keyType + } + + + + fun getKeyTypeAsStr( ) : String? { + + if( null == this.keyType ) return null; + return String(keyType!!) + } + + + + fun getKeyTypeAsHex( ) : String? { + + if( null == this.keyType ) return null; + return Util.bytes2HexString(keyType) + } + + + + fun setKeyType( bytes : ByteArray ) : Data { + + this.keyType = bytes + return this + } + + + enum class KeyTypeOptions( val bin : ByteArray ) { + +OPVDEK(Util.hexString2Bytes("303130")), +OPVTAK(Util.hexString2Bytes("303033")), + } + + fun getKeyTypeCn( ) : String? { + + if( null == keyType ) { return null } + +if( "303130".equals(Util.bytes2HexString(this.keyType) ) ) { + + return "DEK" + +} + + +if( "303033".equals(Util.bytes2HexString(this.keyType) ) ) { + + return "TAK" + +} + + return null + } + + + + fun getKeyTypeOptionIndex( ) : Int? { + + if( null == keyType ) { return null } + +if( "303130".equals(Util.bytes2HexString(this.keyType) ) ) { + + return 0 + +} + + +if( "303033".equals(Util.bytes2HexString(this.keyType) ) ) { + + return 1 + +} + + return null + } + + + + fun getDisperseNumAsBin( ) : ByteArray? { + + return this.disperseNum + } + + + + fun getDisperseNumAsStr( ) : String? { + + if( null == this.disperseNum ) return null; + return String(disperseNum!!) + } + + + + fun getDisperseNumAsHex( ) : String? { + + if( null == this.disperseNum ) return null; + return Util.bytes2HexString(disperseNum) + } + + + + fun setDisperseNum( bytes : ByteArray ) : Data { + + this.disperseNum = bytes + return this + } + + + + fun getDataAsBin( ) : ByteArray? { + + return this.data + } + + + + fun getDataAsStr( ) : String? { + + if( null == this.data ) return null; + return String(data!!) + } + + + + fun getDataAsHex( ) : String? { + + if( null == this.data ) return null; + return Util.bytes2HexString(data) + } + + + + fun setData( bytes : ByteArray ) : Data { + + this.data = bytes + return this + } + + + + fun getDisperseAlgAsBin( ) : ByteArray? { + + return this.disperseAlg + } + + + + fun getDisperseAlgAsStr( ) : String? { + + if( null == this.disperseAlg ) return null; + return String(disperseAlg!!) + } + + + + fun getDisperseAlgAsHex( ) : String? { + + if( null == this.disperseAlg ) return null; + return Util.bytes2HexString(disperseAlg) + } + + + + fun setDisperseAlg( bytes : ByteArray ) : Data { + + this.disperseAlg = bytes + return this + } + + + enum class DisperseAlgOptions( val bin : ByteArray ) { + +OPVDES(Util.hexString2Bytes("31")), +OPV3DES(Util.hexString2Bytes("32")), +OPVIDEA(Util.hexString2Bytes("33")), +OPVSM1(Util.hexString2Bytes("34")), +OPVAES(Util.hexString2Bytes("35")), +OPVSM4(Util.hexString2Bytes("36")), + } + + fun getDisperseAlgCn( ) : String? { + + if( null == disperseAlg ) { return null } + +if( "31".equals(Util.bytes2HexString(this.disperseAlg) ) ) { + + return "DES" + +} + + +if( "32".equals(Util.bytes2HexString(this.disperseAlg) ) ) { + + return "3DES" + +} + + +if( "33".equals(Util.bytes2HexString(this.disperseAlg) ) ) { + + return "IDEA" + +} + + +if( "34".equals(Util.bytes2HexString(this.disperseAlg) ) ) { + + return "SM1" + +} + + +if( "35".equals(Util.bytes2HexString(this.disperseAlg) ) ) { + + return "AES" + +} + + +if( "36".equals(Util.bytes2HexString(this.disperseAlg) ) ) { + + return "SM4" + +} + + return null + } + + + + fun getDisperseAlgOptionIndex( ) : Int? { + + if( null == disperseAlg ) { return null } + +if( "31".equals(Util.bytes2HexString(this.disperseAlg) ) ) { + + return 0 + +} + + +if( "32".equals(Util.bytes2HexString(this.disperseAlg) ) ) { + + return 1 + +} + + +if( "33".equals(Util.bytes2HexString(this.disperseAlg) ) ) { + + return 2 + +} + + +if( "34".equals(Util.bytes2HexString(this.disperseAlg) ) ) { + + return 3 + +} + + +if( "35".equals(Util.bytes2HexString(this.disperseAlg) ) ) { + + return 4 + +} + + +if( "36".equals(Util.bytes2HexString(this.disperseAlg) ) ) { + + return 5 + +} + + return null + } + + + + fun getKeyCheckTypeAsBin( ) : ByteArray? { + + return this.keyCheckType + } + + + + fun getKeyCheckTypeAsStr( ) : String? { + + if( null == this.keyCheckType ) return null; + return String(keyCheckType!!) + } + + + + fun getKeyCheckTypeAsHex( ) : String? { + + if( null == this.keyCheckType ) return null; + return Util.bytes2HexString(keyCheckType) + } + + + + fun setKeyCheckType( bytes : ByteArray ) : Data { + + this.keyCheckType = bytes + return this + } + + + enum class KeyCheckTypeOptions( val bin : ByteArray ) { + +OPVKCV向后兼容(Util.hexString2Bytes("30")), +OPVKCV6H(Util.hexString2Bytes("31")), + } + + fun getKeyCheckTypeCn( ) : String? { + + if( null == keyCheckType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.keyCheckType) ) ) { + + return "KCV 向后兼容" + +} + + +if( "31".equals(Util.bytes2HexString(this.keyCheckType) ) ) { + + return "KCV 6H" + +} + + return null + } + + + + fun getKeyCheckTypeOptionIndex( ) : Int? { + + if( null == keyCheckType ) { return null } + +if( "30".equals(Util.bytes2HexString(this.keyCheckType) ) ) { + + return 0 + +} + + +if( "31".equals(Util.bytes2HexString(this.keyCheckType) ) ) { + + return 1 + +} + + return null + } + + + + fun getBusinessKeyAsBin( ) : ByteArray? { + + return this.businessKey + } + + + + fun getBusinessKeyAsStr( ) : String? { + + if( null == this.businessKey ) return null; + return String(businessKey!!) + } + + + + fun getBusinessKeyAsHex( ) : String? { + + if( null == this.businessKey ) return null; + return Util.bytes2HexString(businessKey) + } + + + + fun setBusinessKey( bytes : ByteArray ) : Data { + + this.businessKey = bytes + return this + } + + + + fun getTailSepAsBin( ) : ByteArray? { + + return this.tailSep + } + + + + fun getTailSepAsStr( ) : String? { + + if( null == this.tailSep ) return null; + return String(tailSep!!) + } + + + + fun getTailSepAsHex( ) : String? { + + if( null == this.tailSep ) return null; + return Util.bytes2HexString(tailSep) + } + + + + fun setTailSep( bytes : ByteArray ) : Data { + + this.tailSep = bytes + return this + } + + + + fun getTailAsBin( ) : ByteArray? { + + return this.tail + } + + + + fun getTailAsStr( ) : String? { + + if( null == this.tail ) return null; + return String(tail!!) + } + + + + fun getTailAsHex( ) : String? { + + if( null == this.tail ) return null; + return Util.bytes2HexString(tail) + } + + + + fun setTail( bytes : ByteArray ) : Data { + + this.tail = bytes + return this + } + + + + fun closeBuilding( ) : Req { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != mainKey ){ + + + soup.put("mainKey", this.mainKey!!) + } + +if( null != keyType ){ + + + soup.put("keyType", this.keyType!!) + soup.put("keyType\$option", getKeyTypeOptionIndex()!!) + } + +if( null != disperseNum ){ + + + soup.put("disperseNum", this.disperseNum!!) + } + +if( null != data ){ + + + soup.put("data", this.data!!) + } + +if( null != disperseAlg ){ + + + soup.put("disperseAlg", this.disperseAlg!!) + soup.put("disperseAlg\$option", getDisperseAlgOptionIndex()!!) + } + +if( null != keyCheckType ){ + + + soup.put("keyCheckType", this.keyCheckType!!) + soup.put("keyCheckType\$option", getKeyCheckTypeOptionIndex()!!) + } + +if( null != businessKey ){ + + + soup.put("businessKey", this.businessKey!!) + } + soup.put("tailSep", Util.hexString2Bytes("3139")) + +if( null != tailSep ){ + + + soup.put("tailSep", this.tailSep!!) + } + +if( null != tail ){ + + + soup.put("tail", this.tail!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("mainKey") ){ + + + this.mainKey = (soup.get("mainKey") as PacketSection).bytes +} + + +if( soup.containsKey("keyType") ){ + + + this.keyType = (soup.get("keyType") as PacketSection).bytes +} + + +if( soup.containsKey("disperseNum") ){ + + + this.disperseNum = (soup.get("disperseNum") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + + + this.data = (soup.get("data") as PacketSection).bytes +} + + +if( soup.containsKey("disperseAlg") ){ + + + this.disperseAlg = (soup.get("disperseAlg") as PacketSection).bytes +} + + +if( soup.containsKey("keyCheckType") ){ + + + this.keyCheckType = (soup.get("keyCheckType") as PacketSection).bytes +} + + +if( soup.containsKey("businessKey") ){ + + + this.businessKey = (soup.get("businessKey") as PacketSection).bytes +} + + this.tailSep = Util.hexString2Bytes("3139") + +if( soup.containsKey("tailSep") ){ + + + this.tailSep = (soup.get("tailSep") as PacketSection).bytes +} + + +if( soup.containsKey("tail") ){ + + + this.tail = (soup.get("tail") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Req { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Req { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Req { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5941")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Req { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5941") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } public class Res { + private var length : ByteArray? = null + private var header : ByteArray? = null + private var command : ByteArray? = null + private var data : Data? = null + public class Data (private val wrapper : Res) { + private var error : ByteArray? = null + private var lmk : ByteArray? = null + private var keySign : ByteArray? = null + + + fun getErrorAsBin( ) : ByteArray? { + + return this.error + } + + + + fun getErrorAsStr( ) : String? { + + if( null == this.error ) return null; + return String(error!!) + } + + + + fun getErrorAsHex( ) : String? { + + if( null == this.error ) return null; + return Util.bytes2HexString(error) + } + + + + fun setError( bytes : ByteArray ) : Data { + + this.error = bytes + return this + } + + + enum class ErrorOptions( val bin : ByteArray ) { + +OPV无错误(Util.hexString2Bytes("3030")), +OPVLMK错误报告给管理员(Util.hexString2Bytes("3133")), +OPV输入数据错(Util.hexString2Bytes("3135")), +OPV无效的密钥类型(Util.hexString2Bytes("3238")), +OPV数据长度错误(Util.hexString2Bytes("3830")), + } + + fun getErrorCn( ) : String? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return "无错误" + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return "LMK错误;报告给管理员" + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return "输入数据错" + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return "无效的密钥类型" + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return "数据长度错误" + +} + + return null + } + + + + fun getErrorOptionIndex( ) : Int? { + + if( null == error ) { return null } + +if( "3030".equals(Util.bytes2HexString(this.error) ) ) { + + return 0 + +} + + +if( "3133".equals(Util.bytes2HexString(this.error) ) ) { + + return 1 + +} + + +if( "3135".equals(Util.bytes2HexString(this.error) ) ) { + + return 2 + +} + + +if( "3238".equals(Util.bytes2HexString(this.error) ) ) { + + return 3 + +} + + +if( "3830".equals(Util.bytes2HexString(this.error) ) ) { + + return 4 + +} + + return null + } + + + + fun getLmkAsBin( ) : ByteArray? { + + return this.lmk + } + + + + fun getLmkAsStr( ) : String? { + + if( null == this.lmk ) return null; + return String(lmk!!) + } + + + + fun getLmkAsHex( ) : String? { + + if( null == this.lmk ) return null; + return Util.bytes2HexString(lmk) + } + + + + fun setLmk( bytes : ByteArray ) : Data { + + this.lmk = bytes + return this + } + + + + fun getKeySignAsBin( ) : ByteArray? { + + return this.keySign + } + + + + fun getKeySignAsStr( ) : String? { + + if( null == this.keySign ) return null; + return String(keySign!!) + } + + + + fun getKeySignAsHex( ) : String? { + + if( null == this.keySign ) return null; + return Util.bytes2HexString(keySign) + } + + + + fun setKeySign( bytes : ByteArray ) : Data { + + this.keySign = bytes + return this + } + + + + fun closeBuilding( ) : Res { + + return this.wrapper + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != error ){ + + + soup.put("error", this.error!!) + soup.put("error\$option", getErrorOptionIndex()!!) + } + +if( null != lmk ){ + + + soup.put("lmk", this.lmk!!) + } + +if( null != keySign ){ + + + soup.put("keySign", this.keySign!!) + } + return soup + } + + + + fun fullFromSoup( soup : Map ) : Data { + + +if( soup.containsKey("error") ){ + + + this.error = (soup.get("error") as PacketSection).bytes +} + + +if( soup.containsKey("lmk") ){ + + + this.lmk = (soup.get("lmk") as PacketSection).bytes +} + + +if( soup.containsKey("keySign") ){ + + + this.keySign = (soup.get("keySign") as PacketSection).bytes +} + + return this + } + + + } + + fun getLengthAsBin( ) : ByteArray? { + + return this.length + } + + + + fun getLengthAsStr( ) : String? { + + if( null == this.length ) return null; + return String(length!!) + } + + + + fun getLengthAsHex( ) : String? { + + if( null == this.length ) return null; + return Util.bytes2HexString(length) + } + + + + fun setLength( bytes : ByteArray ) : Res { + + this.length = bytes + return this + } + + + + fun getHeaderAsBin( ) : ByteArray? { + + return this.header + } + + + + fun getHeaderAsStr( ) : String? { + + if( null == this.header ) return null; + return String(header!!) + } + + + + fun getHeaderAsHex( ) : String? { + + if( null == this.header ) return null; + return Util.bytes2HexString(header) + } + + + + fun setHeader( bytes : ByteArray ) : Res { + + this.header = bytes + return this + } + + + + fun getCommandAsBin( ) : ByteArray? { + + return this.command + } + + + + fun getCommandAsStr( ) : String? { + + if( null == this.command ) return null; + return String(command!!) + } + + + + fun getCommandAsHex( ) : String? { + + if( null == this.command ) return null; + return Util.bytes2HexString(command) + } + + + + fun setCommand( bytes : ByteArray ) : Res { + + this.command = bytes + return this + } + + + + fun buildData( ) : Data { + + this.data = Data(this) + return this.data!! + } + + + + fun newDataBuilder( ) : Data { + + return Data(this) + } + + + + fun getData( ) : Data? { + + return this.data + } + + + + fun toSoup( ) : Map { + + val soup = mutableMapOf() + +if( null != length ){ + + + soup.put("length", this.length!!) + } + +if( null != header ){ + + + soup.put("header", this.header!!) + } + soup.put("command", Util.hexString2Bytes("5942")) + +if( null != command ){ + + + soup.put("command", this.command!!) + } + +if( null != data ){ + soup.put("data", this.data!!.toSoup() ) +} + + return soup + } + + + + fun fullFromSoup( soup : Map ) : Res { + + +if( soup.containsKey("length") ){ + + + this.length = (soup.get("length") as PacketSection).bytes +} + + +if( soup.containsKey("header") ){ + + + this.header = (soup.get("header") as PacketSection).bytes +} + + this.command = Util.hexString2Bytes("5942") + +if( soup.containsKey("command") ){ + + + this.command = (soup.get("command") as PacketSection).bytes +} + + +if( soup.containsKey("data") ){ + this.data = Data( this ).fullFromSoup( soup.get("data") as Map ) +} + + return this + } + + + } +} \ No newline at end of file diff --git a/src/test/java/com/sunyard/sydapi/sample/ASYMEnDeTest.java b/src/test/java/com/sunyard/sydapi/sample/ASYMEnDeTest.java new file mode 100644 index 0000000..c8ce083 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/sample/ASYMEnDeTest.java @@ -0,0 +1,86 @@ +package com.sunyard.sydapi.sample; + +import com.sunyard.RetWrap; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; +import racal.sunyard.main.SydApiBuilder; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + +public class ASYMEnDeTest { + + public static void main(String[] args) throws UnsupportedEncodingException { + + System.out.println("非对称密钥加解密"); + byte[] testData = new byte[100]; + Arrays.fill(testData, (byte) 0x88); + + SydApi4j api = (SydApi4j) new SydApiBuilder() + .setIp("172.16.17.161") + .useDebugMode() + .build(); + + + RetWrap ret; + try { + + String rsaPk = "308189028181009AF6135A23B634E6DFE6AC1BC5E18FAAC5A4287D433C81CB520615DBD386822A20328EF064D16D4AA0ED97056BF6F387D2922834C9DAFF3BFDC5666F280EF187102A47A2CDB45E5BBE66E1F28E88335B880A7BBC5E56FCA9F460C4F2EE034393ED5258D801DC252268FE0A7A36DDFA823C133148D634E560FA3C526E18093B3D0203010001"; + String rsaSk = "0004000096E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D6429CED6878A26E7DA37C6D6E3CC99DF92CFB6208B239A6F6D452F70961413C86ABABBB97905F4D8416125D6705006E0CBBE2A55C21C5021D6D4BA6357574DAEA872F744343497FC301A0072DCB5AFFADE4E38618CF193B417465D51F55E7A05143EF22ED52B15C3D7EAB07A83442F7AA0FE0864D6FA656D35A3F8F78EE76E0623396E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D6424759813A8629F2E496E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D6429C90258F09582794C56F6F811DD07E128A0D8EF28DD2A159CBC0F638D0D1ED316BF916A04BC5AB62B95826F2387D1342EA33779526A1909FCAEB67DB6C8F1BB8550544087407462997852081DDAA22AB072EBB204A911654DC8EE988BCDAA8D36433320A1FCBB1E02932119CD6B77FFD2459B1EF170FF35FF38BA957259FBB5396E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D642F13FEACF9F953255F45DB33FFA13DABC74A15EFDC5BB956C94590170BB2473B1F381564524E001284FF13325E0E123E68C5ACC3ACF396B15DFF3CF22C24D719696E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D642E8A95E58CBA24739343ECA89FDAB1C0D16C5353ECD90C364667B1B7E3B3D8698F3E0EE4874004D7100AA57E7F2778C76DE4D0E2F79B337C06DD2E407B80351DC96E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D642ECA9E92F835FAEA4AE5B73605852635FBE67D5F472BA7BE41DF94C44F472D49FAE23C3649A842C685B5CC1A5D475D8D3B46854FD28EBE9BD72921388A98BF2F196E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D642DE755DEFD7ABBDC9A95A90262084CA8E9C69123CEBF24BFC9A82114EB8E62673EA2A2BD72D321F795A2A22A4ADB5BAA42D55FC561F09D6BB0AA3518EE7BC0B8C96E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D642487F135CC93AA0E8A97C1DA44B6706EBA95A3CCB24D9EB2E643D6B339FF7DE3983DC16C03AF3C4A22878EF976D9D2AF4549D1D9933EAC824CB32801CC4136EDF"; + + String sm2Pk = "03420004571DE0574BACC945BE003FBA94EB3FF4000BD2C64C5D81D4463099177A5E387E583DEEF7087E988E5C84E4FE19B24566A9A130D7159CE13DC8527B8341CEA3F3"; + + String sm2Sk = "00010000EBCA3A20376AAEDA2A0B607F14ADD89CE62DFF26A115FB4C987FDDDE75E78CBB0000000000000000000000000000000000000000000000000000000000000000"; + +// ret = api.SM2OrRSAGenKeyPair(1, "", 1024); +// +// System.out.println( ret ); +// System.out.println( Util.bytes2HexString((byte[]) ret.get("PrivateKey")) ); +// System.out.println( Util.bytes2HexString((byte[]) ret.get("PublicKey")) ); + + + byte[] enData1 = api.encryptByPk(1, sm2Pk, testData); + System.out.println( new String(enData1) ); + + byte[] deData1 = api.decryptBySk(1, sm2Sk, enData1); + + // deData == testData + assert Arrays.equals( enData1, deData1 ); + System.out.println("SM2 公钥加密/私钥解密 测试通过"); +// +// +// byte[] enData = api.encryptByPk(0, rsaPk, testData); +// byte[] deData = api.decryptBySk(0, rsaSk, enData); +// +// // deData == testData +// assert Arrays.equals( enData, deData ); +// System.out.println("RSA 公钥加密/私钥解密 测试通过"); + + + +// byte[] enData1 = api.encryptBySk(1, sm2Sk, testData); +// System.out.println( new String(enData1) ); +// +// byte[] deData1 = api.decryptByPk(1, sm2Pk, enData1); +// +// // deData == testData +// assert Arrays.equals( enData1, deData1 ); +// System.out.println("SM2 私钥加密/公钥解密 测试通过"); +// +// +// byte[] enData = api.encryptBySk(0, rsaSk, testData); +// byte[] deData = api.decryptByPk(0, rsaPk, enData); +// +// // deData == testData +// assert Arrays.equals( enData, deData ); +// System.out.println("RSA 私钥加密/公钥解密 测试通过"); + + + } finally { + api.disconnect(); + } + + } + + +} diff --git a/src/test/java/com/sunyard/sydapi/sample/Build.java b/src/test/java/com/sunyard/sydapi/sample/Build.java new file mode 100644 index 0000000..d68cdf4 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/sample/Build.java @@ -0,0 +1,7 @@ +package com.sunyard.sydapi.sample; + +public class Build { + public static void main(String[] args) { + + } +} diff --git a/src/test/java/com/sunyard/sydapi/sample/InputOutputKeyTest.java b/src/test/java/com/sunyard/sydapi/sample/InputOutputKeyTest.java new file mode 100644 index 0000000..2f07b72 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/sample/InputOutputKeyTest.java @@ -0,0 +1,76 @@ +package com.sunyard.sydapi.sample; + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.cert.X509; +import racal.sunyard.main.SydApiBuilder; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + + +/** + * 密钥导入导出功能测试 + * 其实就是做 lmk2zmk(A8) 转加密和 zmk2lmk(A6) 转加密 + */ +public class InputOutputKeyTest +{ + + public static void main(String[] args) throws UnsupportedEncodingException { + + System.out.println("密钥导入导出功能测试"); + + + SydApi api = new SydApiBuilder() + .setIp("172.16.17.161") +// .useDebugMode() +// .useEBCDMode() +// .useETEncrypt() + .build(); + + try { + + String keyType = "000"; + char sydSln = 'X'; + + + // 生成一个测试用的 zmk + RetWrap ret = api.genSymmetricKey( + "000", + 'Z' + ); + + String zmk = new String((byte[]) ret.get("lmkKey")); + System.out.println( "zmk=" + zmk); + + + // 生成一个测试用的 key + ret = api.genSymmetricKey( + keyType, + sydSln + ); + + String key = new String((byte[]) ret.get("lmkKey")); + System.out.println( "lmkKek=" + key); + + + // 将 key 转加密输出 + ret = api.outputKey(keyType, sydSln, zmk, key); + String key2 = new String((byte[]) ret.get("key")); + System.out.println( "zmkKek=" + key2); + + + // 将 key 重新导入 + ret = api.inputKey(keyType, sydSln, zmk, key2); + String key3 = new String((byte[]) ret.get("key")); + System.out.println( "*lmkKek=" + key3); + + + }finally { + api.disconnect(); + } + + } + + +} diff --git a/src/test/java/com/sunyard/sydapi/sample/MACTest.java b/src/test/java/com/sunyard/sydapi/sample/MACTest.java new file mode 100644 index 0000000..41beede --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/sample/MACTest.java @@ -0,0 +1,25 @@ +package com.sunyard.sydapi.sample; + +import com.sunyard.SydApi; +import racal.sunyard.main.SydApiBuilder; + +public class MACTest { + + public static void main(String[] args) { + + SydApi api = new SydApiBuilder() + .setIp("172.16.17.162") +// .useEBCDMode() + .useDebugMode() +// .useETEncrypt() + .build(); + + + byte[] data = new byte[10]; + byte[] mac = api.MACCalc(0, 1, 0, 2, "X12345678123456781234567812345678", data); + + System.out.println( new String( mac ) ); + + + } +} diff --git a/src/test/java/com/sunyard/sydapi/sample/RSAP1SignVerify.java b/src/test/java/com/sunyard/sydapi/sample/RSAP1SignVerify.java new file mode 100644 index 0000000..27373a8 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/sample/RSAP1SignVerify.java @@ -0,0 +1,156 @@ +package com.sunyard.sydapi.sample; + +import com.sunyard.cert.X509; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; +import racal.sunyard.main.SydApiBuilder; +import sun.misc.BASE64Encoder; +import sun.security.provider.X509Factory; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; + +public class RSAP1SignVerify { + private static byte[] createBlock(byte type, byte[] in) { + if (2 == type && (255 & in[0]) >= 128) { + byte[] nin = new byte[in.length + 1]; + nin[0] = 0; + System.arraycopy(in, 0, nin, 1, in.length); + in = nin; + } + + int len = in.length; + ByteBuffer bb; + if (len > 128) { + int lenLen = len / 256 + 1; + bb = ByteBuffer.allocate(len + 1 + 1 + lenLen); + bb.put(type); + bb.put((byte) (128 + lenLen)); + + for (int i = 0; i < lenLen; ++i) { + bb.put((byte) (255 & len >>> 8 * (lenLen - 1 - i))); + } + } else { + bb = ByteBuffer.allocate(len + 1 + 1); + bb.put(type); + bb.put((byte) (255 & len)); + } + + bb.put(in); + return bb.array(); + } + + + public static void main(String[] args) { + SydApi4j api = (SydApi4j) new SydApiBuilder() + .setIp("192.168.1.226") + .useDebugMode() + .build(); + + + try { + //model 0:通过证书序列号去签名,以及验签 + //model 1:通过证书DN去签名,以及验签 + //model 2:通过证书实体的机构号获取到公钥,通过机构号以及公钥去签名,公钥去验签 + byte model = 2; + switch (model) { + case 2: { + String cert = "-----BEGIN CERTIFICATE-----\n" + + "MIIEQjCCAyqgAwIBAgIFQAeZAyIwDQYJKoZIhvcNAQELBQAwXTELMAkGA1UEBhMC\n" + + "Q04xMDAuBgNVBAoMJ0NoaW5hIEZpbmFuY2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhv\n" + + "cml0eTEcMBoGA1UEAwwTQ0ZDQSBBQ1MgVEVTVCBPQ0EzMTAeFw0xOTEwMjgwODU4\n" + + "NTRaFw0yNDEwMjgwODU4NTRaMGsxCzAJBgNVBAYTAkNOMRYwFAYDVQQKDA1DRkNB\n" + + "IE9DQTMxIENBMQ4wDAYDVQQLDAVneW5zaDEZMBcGA1UECwwQT3JnYW5pemF0aW9u\n" + + "YWwtMzEZMBcGA1UEAwwQZ3luc2g5ODEwMDAwMTE1MDCCASIwDQYJKoZIhvcNAQEB\n" + + "BQADggEPADCCAQoCggEBANZhyVUufcUclty+zfbbrCsjePrTRlvvXjL0gprrSK6U\n" + + "ynyzs4h76+s3MBewAvmDcemOopddC+uvX/zfKgTzyEeyrmnee936xKXHyv1SHblW\n" + + "a4oMPR458X2o/Ej3hHzEXqj/WdUEZdx83HeaYcdhCgoHNaKcEpiqkpIjhXtIU4Ah\n" + + "L3ciTF7Y+0NWTi17dDI17i0C681Tjya5p0Srpw4pRy1Rb0dx6zkTGGq52RLCQk4g\n" + + "GVWvYEn4ST4DhWZXcgTOkVBMPMNS+qXxHNy6KLi3ky6x9U+10ldg1rqG7jOtWn1E\n" + + "HqlzcIxqdqr7iO95h5a/K0bFKiVywEq/YdlxgAbH/KUCAwEAAaOB+jCB9zA/Bggr\n" + + "BgEFBQcBAQQzMDEwLwYIKwYBBQUHMAGGI2h0dHA6Ly9vY3NwdGVzdC5jZmNhLmNv\n" + + "bS5jbjo4MC9vY3NwMB8GA1UdIwQYMBaAFJo9tK5lWPvOWgV4JqBtKwSGusbsMAwG\n" + + "A1UdEwEB/wQCMAAwNwYDVR0fBDAwLjAsoCqgKIYmaHR0cDovLzIxMC43NC40Mi4z\n" + + "L09DQTMxL1JTQS9jcmw2NC5jcmwwDgYDVR0PAQH/BAQDAgbAMB0GA1UdDgQWBBTa\n" + + "pk33a/mKcAoX27Prs1miHQgqPTAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUH\n" + + "AwQwDQYJKoZIhvcNAQELBQADggEBAK7B11CFYLThIEEIIWG4A3BDvMiQhkeJ2jDd\n" + + "xvc/pIH6SmIRJyOTWYxKhkBrI1AaKhOYfzsU973sK2gyLURjkatg1pTxg5v37sIo\n" + + "BGqMe05aUF1MQlXsx+R+mes1GJcurPXeZ+Ho3DCBPo/O1uU5QHy5OU4iVOwErrOK\n" + + "ExslrbDPFizZSes7I+y/dQcl4WkhjcSA37G/Zay6RsQuiPkHpt7dHzUGnMqF9CvW\n" + + "6SiEvhdtSRTyqvjbJFL2bP3prUBwDD6Yi3oe5uclm/iPwy/7HLbG1oGBz0sHn+80\n" + + "ac8jKPehg78CEgMaq1FKcl2zvorIixrjoLGYOSVthz6oABZ5MHk=\n" + + "-----END CERTIFICATE-----"; + + + String signCert = "MIID6DCCAtCgAwIBAgIFJnVRuPUwDQYJKoZIhvcNAQELBQAwPTELMAkGA1UEBhMCQ04xFDAS\n" + + "BgNVBAoMC05YWTIwNDhURVNUMRgwFgYDVQQDDA9OWFkyMDQ4Uk9PVFRFU1QwHhcNMTkwNTMw\n" + + "MDAxNjI2WhcNMjQwNTI4MDAxNjI2WjB6MQswCQYDVQQGEwJDTjE3MDUGA1UECgwuUnVyYWwg\n" + + "Q3JlZGl0IEJhbmtzIEZ1bmRzIENsZWFyaW5nIENlbnRlcihURVNUKTEUMBIGA1UECwwLRW50\n" + + "ZXJwcmlzZXMxHDAaBgNVBAMMEzA2M0A2NzMzMjcwOTk5OTkwMDQwggEiMA0GCSqGSIb3DQEB\n" + + "AQUAA4IBDwAwggEKAoIBAQCEEMIed7o5R2ZCPKKZrJjQ7x7hIYsAaBd5vhAhj+HyXyCPF6O6\n" + + "3N9znR8uv+BlG2va4jIdye/rLgTGnBuuRZPEYNGvJvoTy01lFtixuInkNW1VkgEQ1CDlwW47\n" + + "TOC5dFPYHENkSMMSiDM0BLBQsZH1p4oQzSyGVtAs9YTWQhb/nWSSXgpiz5+qmlvSrsEU+Ffy\n" + + "1fYsN6RadZWL2Pegk8NTS/KTfbo9NCgE6jKFoPNzJ20fdK5aUR5ePI5JdnzxfrabkI9F9964\n" + + "tlsynsOaoWY60FMmfB+HcvJoSgSI65iNRFRwkzic8mtnmdq9EIIcPgZVz7GCEp9v3Vk30T9e\n" + + "M2/ZAgMBAAGjgbEwga4wHwYDVR0jBBgwFoAUZaX9myCvxP1gs80NCsJZtGtypMEwCQYDVR0T\n" + + "BAIwADBUBgNVHR8ETTBLMEmgR6BFpEMwQTEOMAwGA1UEAwwFY3JsMjExDDAKBgNVBAsMA2Ny\n" + + "bDEUMBIGA1UECgwLTlhZMjA0OFRFU1QxCzAJBgNVBAYTAkNOMAsGA1UdDwQEAwIHgDAdBgNV\n" + + "HQ4EFgQUdhrTivJUnKI5oZ0T2OZkSEaDkIUwDQYJKoZIhvcNAQELBQADggEBACgf34fsfPvN\n" + + "ln1Ch2Cid7jrJEw5o1AQlahxWtnJH4fzxgYldqgNpoZD3p9XOmFEIvTBHAt8wANQoCQEFJj2\n" + + "3PZvwG4T6VXwRn05/u25fMDF4R7Z9IYlNVY5hpxtisC7u8aq7VCqHwzXsjaItuCPQbOkhTCb\n" + + "2m4TVGbaMYXVWhEJiss31XrNZgAbKfrFEAmG6+KO5cRdfjXHooaY44sgeEd+Mi5aPyY+QNR1\n" + + "uio39G+ur/BjHqOCIujUEI8f3g8wAQaIFyA97rAjJW1W/BVZispRg4niG0mLQ356cTGj+kkJ\n" + + "imdxvNyhfwmMNweP6fIUnajMOtJiMomjSAdIuqdxDIw="; + String source = "操作员:800000783001CifNo800000783LoginId800000783001LoginTypeCtransactioneibs.login"; + String signatureBase64 = "CC0uWxM/YqFrPzRKqvpEDBKz5AZC2+Hp2eEWhgR+z0XR9nirrtovb8e61ahLeYywsZ5bBZgCL5lKI/YJ/mI2Nh3ntWQCXSAf8DpOD3GWkHRMfDgeiGj0F3qyTOJi7iY+wAZOFBLiOEe2P2YFCl0Luny6dfRFoBkvoxVbrrKui+8d5pusciuuwQcL+P7K0FeIPb2yjdZfm+oz+FMlq4dvSHJrnDZ3tUcS7ZzfXSHYwAm1aA5SAWNIS6ixP1pT4nwLM0W+tUdvtP1yx6q7UyZPeDaWDsTqZbLvd3Ond38jQIrPutK/ACBsg92VS2SmQDVj0C+ZrJkvjbXbRj87dn0CGw=="; + byte[] bSource = source.getBytes(); + + byte[] derCert = Util.decodeBase64(signCert); + BASE64Encoder encoder = new BASE64Encoder(); + cert = X509Factory.BEGIN_CERT + "\n" + encoder.encodeBuffer(derCert) + X509Factory.END_CERT; + X509 X509Cert = api.GetX509CertInfo(cert); + + byte[] signature = Util.decodeBase64(signatureBase64); + byte[] signatureDer = createBlock((byte) 4, signature); + + + // 通过传入公钥P1验签 + Boolean bRet = api.RSAVerify(0, api.DATA_ORIGIN, X509Cert.getPubKey(), bSource, signatureDer); + System.out.println("P1验签结果:" + bRet); + + +/* + + String userID = "2"; + byte[] testData = {1,2,3,45,1,2,3,45}; + // 机构号获取公钥 + String pk=api.RSAGetPublicKeyC(userID,0); + System.out.println("PK: " + pk); + + // 通过机构号获取私钥P1签名 + byte[] sign = api.RSASignC(userID,1,api.DATA_ORIGIN,testData); + System.out.println( "P1签名结果: " + Util.bytes2HexString(sign) ); + + // 通过传入公钥P1验签 + boolean bRet = api.RSAVerify(1,api.DATA_ORIGIN,Util.hexString2Bytes(pk),testData, sign ); + System.out.println("P1验签结果:"+bRet);*/ + } + break; + default: + break; + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + + if (null != api) { + api.disconnect(); + } + + } + + + } + +} diff --git a/src/test/java/com/sunyard/sydapi/sample/Test.java b/src/test/java/com/sunyard/sydapi/sample/Test.java new file mode 100644 index 0000000..1e5ac55 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/sample/Test.java @@ -0,0 +1,71 @@ +package com.sunyard.sydapi.sample; + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.cert.X509; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApiBuilder; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + + +public class Test +{ + + public static void main(String[] args) throws UnsupportedEncodingException { + + System.out.println("工银亚洲测试功能测试"); + byte[] testData = new byte[17000]; + Arrays.fill(testData, (byte) 0x88); + + SydApi api = new SydApiBuilder() + .setIp("192.168.1.226") +// .useEBCDMode() + .useDebugMode() +// .useETEncrypt() + .build(); + +// SydApi api = new SydApi4j().connect("192.168.0.222", 8889, null, 3000); + + try { + + //RetWrap ret = api.genComposeKey(new String[]{"D5B45BA5E80B4520", "187B1BFB7629DCD7"}); + //RetWrap ret = api.genSymmetricKey("000", 'X'); + //System.out.println( ret ); + + String cert2 = "-----BEGIN CERTIFICATE-----\n" + + "MIID6DCCAtCgAwIBAgIFJnVRuPUwDQYJKoZIhvcNAQELBQAwPTELMAkGA1UEBhMCQ04xFDAS\n" + + "BgNVBAoMC05YWTIwNDhURVNUMRgwFgYDVQQDDA9OWFkyMDQ4Uk9PVFRFU1QwHhcNMTkwNTMw\n" + + "MDAxNjI2WhcNMjQwNTI4MDAxNjI2WjB6MQswCQYDVQQGEwJDTjE3MDUGA1UECgwuUnVyYWwg\n" + + "Q3JlZGl0IEJhbmtzIEZ1bmRzIENsZWFyaW5nIENlbnRlcihURVNUKTEUMBIGA1UECwwLRW50\n" + + "ZXJwcmlzZXMxHDAaBgNVBAMMEzA2M0A2NzMzMjcwOTk5OTkwMDQwggEiMA0GCSqGSIb3DQEB\n" + + "AQUAA4IBDwAwggEKAoIBAQCEEMIed7o5R2ZCPKKZrJjQ7x7hIYsAaBd5vhAhj+HyXyCPF6O6\n" + + "3N9znR8uv+BlG2va4jIdye/rLgTGnBuuRZPEYNGvJvoTy01lFtixuInkNW1VkgEQ1CDlwW47\n" + + "TOC5dFPYHENkSMMSiDM0BLBQsZH1p4oQzSyGVtAs9YTWQhb/nWSSXgpiz5+qmlvSrsEU+Ffy\n" + + "1fYsN6RadZWL2Pegk8NTS/KTfbo9NCgE6jKFoPNzJ20fdK5aUR5ePI5JdnzxfrabkI9F9964\n" + + "tlsynsOaoWY60FMmfB+HcvJoSgSI65iNRFRwkzic8mtnmdq9EIIcPgZVz7GCEp9v3Vk30T9e\n" + + "M2/ZAgMBAAGjgbEwga4wHwYDVR0jBBgwFoAUZaX9myCvxP1gs80NCsJZtGtypMEwCQYDVR0T\n" + + "BAIwADBUBgNVHR8ETTBLMEmgR6BFpEMwQTEOMAwGA1UEAwwFY3JsMjExDDAKBgNVBAsMA2Ny\n" + + "bDEUMBIGA1UECgwLTlhZMjA0OFRFU1QxCzAJBgNVBAYTAkNOMAsGA1UdDwQEAwIHgDAdBgNV\n" + + "HQ4EFgQUdhrTivJUnKI5oZ0T2OZkSEaDkIUwDQYJKoZIhvcNAQELBQADggEBACgf34fsfPvN\n" + + "ln1Ch2Cid7jrJEw5o1AQlahxWtnJH4fzxgYldqgNpoZD3p9XOmFEIvTBHAt8wANQoCQEFJj2\n" + + "3PZvwG4T6VXwRn05/u25fMDF4R7Z9IYlNVY5hpxtisC7u8aq7VCqHwzXsjaItuCPQbOkhTCb\n" + + "2m4TVGbaMYXVWhEJiss31XrNZgAbKfrFEAmG6+KO5cRdfjXHooaY44sgeEd+Mi5aPyY+QNR1\n" + + "uio39G+ur/BjHqOCIujUEI8f3g8wAQaIFyA97rAjJW1W/BVZispRg4niG0mLQ356cTGj+kkJ\n" + + "imdxvNyhfwmMNweP6fIUnajMOtJiMomjSAdIuqdxDIw=\n" + + "-----END CERTIFICATE-----\n"; + + X509 x509 = api.GetX509CertInfo( cert2 ); + + System.out.println( x509 ); + + + }finally { + api.disconnect(); + } + + } + + +} diff --git a/src/test/java/com/sunyard/sydapi/sample/Test2.java b/src/test/java/com/sunyard/sydapi/sample/Test2.java new file mode 100644 index 0000000..0773e61 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/sample/Test2.java @@ -0,0 +1,126 @@ +package com.sunyard.sydapi.sample; + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import racal.sunyard.main.SydApiBuilder; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + + +// S +// key=53353745304145303232443638383236 +// kcv=3641364533414331353746454631303730314132374139334446303246313938 +// s1 = 4AD6F3FCC606182A +// s2 = 2F47B4C75439C0F0 + + +/** + * S + * 53433030443432444141433331394234 + * 3031463646374141334331453532333945443237423031434136333735383530 + *

+ *

+ *

+ * 554233453843413345304545453331374130333744353832434544454433363138 + * 334138463043 + *

+ *

+ *

+ * SA035CDE407F5249 + * D99CABFAE8D110CD9269FB34B8CAD265 + *

+ *

+ * X55D9B6452E7B89BB7B266E2D02042780 + * 7AD5FB + *

+ * X7B266E2D0204278055D9B6452E7B89BB + * 5A2ABC60CEFCC568 + */ +// U + +/** + 554233453843413345304545453331374130333744353832434544454433363138 + 334138463043 + */ + +// T + +/** + * + * + * SA035CDE407F5249 + * D99CABFAE8D110CD9269FB34B8CAD265 + * + */ + + +/** + * X55D9B6452E7B89BB7B266E2D02042780 + * 7AD5FB + */ + + +/** + * X7B266E2D0204278055D9B6452E7B89BB + * 5A2ABC60CEFCC568 + */ + + +/** + * X1C7B9DF464C039F2D031E0465E8F89B9 + * 10093C + */ +public class Test2 { + + public static void main(String[] args) throws UnsupportedEncodingException { + + System.out.println("工银亚洲测试功能测试"); + byte[] testData = new byte[17000]; + Arrays.fill(testData, (byte) 0x88); + + SydApi api = new SydApiBuilder() + .setIp("172.16.17.162") + .useDebugMode() + .build(); + +// SydApi api = new SydApi4j().connect("192.168.0.222", 8889, null, 3000); + + + RetWrap ret; + try { +// ret = api.genAndPrintSplit( +// "000", +// 'X' +// ); +// +// +// System.out.println( Util.bytes2HexString((byte[]) ret.get("lmkKey")) ); +// System.out.println( Util.bytes2HexString((byte[]) ret.get("keyCheck")) ); + + String[] splits = new String[]{"45A2863406F82135", "2314C1B6C97DF5B8"}; +// byte[] p1 = Util.hexString2Bytes( splits[0] ); +// byte[] p2 = Util.hexString2Bytes( splits[1] ); +// byte[] keybytes = new byte[p1.length + p2.length]; + +// for ( int i = 0; i < keybytes.length ; i++ ){ +// keybytes[i] = (byte) (p1[i] ^ p2[i]); +// } + +// System.arraycopy( p1, 0, keybytes, 0, p1.length ); +// System.arraycopy( p2, 0, keybytes, p1.length, p2.length ); +// + ret = api.genComposeKey("000", 'X', splits[0] + splits[1]); + + System.out.println(ret); + System.out.println(new String((byte[]) ret.get("lmkKey"))); + System.out.println(new String((byte[]) ret.get("keyCheck"))); + + } finally { + api.disconnect(); + } + + } + + +} diff --git a/src/test/java/com/sunyard/sydapi/sample/TestKeyPair.java b/src/test/java/com/sunyard/sydapi/sample/TestKeyPair.java new file mode 100644 index 0000000..41c0018 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/sample/TestKeyPair.java @@ -0,0 +1,50 @@ +package com.sunyard.sydapi.sample; + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApiBuilder; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + +public class TestKeyPair +{ + + public static void main(String[] args) throws UnsupportedEncodingException { + + System.out.println("非对称密钥生成"); + byte[] testData = new byte[17000]; + Arrays.fill(testData, (byte) 0x88); + + SydApi api = new SydApiBuilder() + .setIp("172.16.17.161") + .useDebugMode() + .build(); + + RetWrap ret; + try { + + // SM2 + ret = api.SM2OrRSAGenKeyPair(1, "", 0); + + System.out.println( ret ); + System.out.println( Util.bytes2HexString((byte[]) ret.get("PrivateKey")) ); + System.out.println( Util.bytes2HexString((byte[]) ret.get("PublicKey")) ); + + + // RSA + ret = api.SM2OrRSAGenKeyPair(0, "", 1152); + + System.out.println( ret ); + System.out.println( Util.bytes2HexString((byte[]) ret.get("PrivateKey")) ); + System.out.println( Util.bytes2HexString((byte[]) ret.get("PublicKey")) ); + + }finally { + api.disconnect(); + } + + } + + +} diff --git a/src/test/java/com/sunyard/sydapi/test/AESEnDeApi.java b/src/test/java/com/sunyard/sydapi/test/AESEnDeApi.java new file mode 100644 index 0000000..c9db1d5 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/AESEnDeApi.java @@ -0,0 +1,90 @@ +package com.sunyard.sydapi.test; + + +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; + +/** + * SydApi AES256 + * 调用方法参考如下,加密机需要相应的设置。 + */ +public class AESEnDeApi { + + public static void write(String file, String content) { + write(file, content.getBytes()); + } + + public static void write(String file, byte[] content) { + try { + File f = new File(file); + if (!f.exists()) { + f.createNewFile(); + } + FileOutputStream fos = new FileOutputStream(f); + fos.write(content); + } catch (Exception e) { + System.out.println("写入文件 " + file + " 异常"); + } + } + + public static String read(String file) { + try { + File f = new File(file); + if (!f.exists()) { + return null; + } + FileInputStream fis = new FileInputStream(f); + byte[] buff = new byte[5024]; + int len = fis.read(buff); + return new String(buff, 0, len); + } catch (Exception e) { + return null; + } + } + + public static void main(String[] args) { + + // 连接加密机 + SydApi4j api = (SydApi4j) new SydApi4j().connect("61.164.40.82", 8889, null, 1000); + + + try { + + + byte[] testData = "".getBytes(); + + // 生成密钥 + // 注意 'L' 表示 AES 所用的密钥 + String seesionKey = "L" + api.GenerateRandom(64); + + + System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 CBC -----"); + + byte[] enDataCBC = api.SYMEncryptDataCBC(SydApi.NALG_AES, seesionKey, testData); + System.out.print("密文 : "); + System.out.println(Util.bytes2HexString(enDataCBC)); + write("./EnData.bin", enDataCBC); + + + System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 CBC -----"); + byte[] deDataCBC = api.SYMDecryptDataCBC(SydApi.NALG_AES, seesionKey, enDataCBC); + System.out.print("解密 : "); + System.out.println(Util.bytes2HexString(deDataCBC)); + write("./DeData.bin", deDataCBC); + + // 原始报文是字符串,还原原始报文 + System.out.println(new String(testData)); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + api.disconnect(); + } + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/App.java b/src/test/java/com/sunyard/sydapi/test/App.java new file mode 100644 index 0000000..8fdf747 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/App.java @@ -0,0 +1,121 @@ +package com.sunyard.sydapi.test; + + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + +public class App { + public static void main(String[] args) throws UnsupportedEncodingException { + + + SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.17.162", 8889 , 1000); + + SydApi4j api = (SydApi4j) new SydApi4j();//.connect("wuyong.fullstack.club" , 8889, null,1000); + + + RetWrap r = api.SYD_SM2GenKeyPair(); + System.out.println( r.get("publicKey") ); + System.out.println( r.get("privateKey") ); + +// System.out.println("\n\n----- 获取公钥 () -----"); +// String pk = api.SYD_SM2_Get_Id_PublicKey_HA("1234", 0); +// System.out.print("\r\n公钥 : "); +// System.out.println( pk ); +// +// +//// pk = api.SYD_SM2_Get_Dn_PublicKey_HA("C=CN,O=Sunyard,OU=8001,CN=8001".getBytes("GBK"), 0); +//// System.out.print("\r\n公钥 : "); +//// System.out.println( pk ); +// +// +// // 签名 + String data="MainBody>1015570000408702018091900000000012018-09-19T10:13:391015570000408702015970000397542018-09-1900000001123456,测试"; + final String testPubKey = "0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"; +// System.out.println("\n\n----- SM2 算法签名 (原始数据) -----"); +// String sign = api.SYD_SM2_Sign_HA( +// "1234", +// SydApi.DATA_ORIGIN, +// Util.hexString2Bytes(testPubKey), +// data.getBytes() +// ); +// System.out.print("\n\n----- SM2 算法签名 结果: "); +// System.out.println( sign ); +// +// +// +// +// +// System.out.println("\n\n----- SM2 算法验签 (原始数据) -----"); +// boolean SM2VerifyRet = api.SYD_SM2_Verify_HA( +// SydApi.DATA_ORIGIN, +// Util.hexString2Bytes(testPubKey), data.getBytes() , sign); +// if (SM2VerifyRet){ +// System.out.println("验签通过"); +// }else{ +// System.err.println("验签失败"); +// throw new RuntimeException("验签失败"); +// } + + + +// // 签名验签 2 +// System.out.println("\n\n----- 签名验签 2 -----"); +// String sign2 = api.SYD_SM2_DetachedSign_HA( data.getBytes() , "C=CN,O=Sunyard,OU=8001,CN=8001"); +// System.out.println( sign2 ); + + +// String sign2 = "MIICpQYKKoEcz1UGAQQCAqCCApUwggKRAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIIByTCCAcUwggFooAMCAQICCDyTAAAAAAAlMAwGCCqBHM9VAYN1BQAwJjELMAkGA1UEBhMCQ04xFzAVBgNVBAMMDlN1bnlhcmRTTTJSb290MB4XDTE3MDUxNzAyNTI0NFoXDTIyMDcyNTAyNTI0NFowPTELMAkGA1UEBhMCQ04xEDAOBgNVBAoMB1N1bnlhcmQxDTALBgNVBAsMBDgwMDExDTALBgNVBAMMBDgwMDEwWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAAQ+2joQe3zDXMAFx/vwu05rQ6B+4U42BgPSLsoqYAstD6AwVdQA0SQDAPVGSLhJ0T9QszD/FDUbVkWxNoaCCmW7o2cwZTAOBgNVHQ8BAf8EBAMCAMAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwHwYDVR0jBBgwFoAU93/arv8hxtk6eq2g+6z+AqVO1cEwHQYDVR0OBBYEFAMWZaY2AwaQTNiFLpsa0dyCzBZ6MAwGCCqBHM9VAYN1BQADSQAwRgIhAIl2ZHGfln5hedcousARzZ2yeUjUbxSFMmhMmr5t6Q6nAiEAvqYX/KpIcvnPyB/Yiil+oq6DFdVM6P3vDxBhU/8taXExgaAwgZ0CAQEwMjAmMQswCQYDVQQGEwJDTjEXMBUGA1UEAwwOU3VueWFyZFNNMlJvb3QCCDyTAAAAAAAlMAwGCCqBHM9VAYMRBQAwDQYJKoEcz1UBgi0BBQAERzBFAiATwLIYiylt7xHmBkH6EclrchClxzLlKWC5guxxzkr58gIhANSw+owu8cyypdJtHGrGqjSiB1BVzGva+irUHelx/GbC"; +// sign2 = "MIID7gYKKoEcz1UGAQQCAqCCA94wggPaAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIIC2jCCAtYwggJ6oAMCAQICBUACgAF0MAwGCCqBHM9VAYN1BQAwYTELMAkGA1UEBhMCQ04xMDAuBgNVBAoMJ0NoaW5hIEZpbmFuY2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEgMB4GA1UEAwwXQ0ZDQSBBQ1MgVEVTVCBTTTIgT0NBMzEwHhcNMTcxMTE2MDY1NDQ1WhcNMjIxMTE2MDY1NDQ1WjCBgzELMAkGA1UEBhMCQ04xHDAaBgNVBAoME0NGQ0EgVEVTVCBTTTIgT0NBMzExDjAMBgNVBAsMBVNIQ1BFMRkwFwYDVQQLDBBPcmdhbml6YXRpb25hbC0xMSswKQYDVQQDDCIwNTFA5LiK5rW356Wo5o2u5Lqk5piT5omAQEFBQUFBQUA4MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEYPA9UQRL/ZaThEN0nc3SwkOHw4hPDXG9hZeKiBnNdhgPy1EtX4My2bpNFpYMmQ0nvkJUM4qpJrF7MSqEws6rLaOB+TCB9jA/BggrBgEFBQcBAQQzMDEwLwYIKwYBBQUHMAGGI2h0dHA6Ly9vY3NwdGVzdC5jZmNhLmNvbS5jbjo4MC9vY3NwMB8GA1UdIwQYMBaAFATHvPlZAWk+jDQ2IGIYPN68tbsMMAwGA1UdEwEB/wQCMAAwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovLzIxMC43NC40Mi4zL09DQTMxL1NNMi9jcmwxLmNybDAOBgNVHQ8BAf8EBAMCBsAwHQYDVR0OBBYEFKJnS7XYRDWG9eqXtSzUZXK+De2/MB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDBDAMBggqgRzPVQGDdQUAA0gAMEUCIGaSRoaUSpoH4lW3at1ABluiNwFDH21jHesHmy0F5gjqAiEA0sUykW9E36F3qQ91YDvasQg8EnOMp1idhgt6pq/NUAYxgdgwgdUCAQEwajBhMQswCQYDVQQGEwJDTjEwMC4GA1UECgwnQ2hpbmEgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MSAwHgYDVQQDDBdDRkNBIEFDUyBURVNUIFNNMiBPQ0EzMQIFQAKAAXQwDAYIKoEcz1UBgxEFADANBgkqgRzPVQGCLQEFAARHMEUCIQDH3ePzq4nYJ8pAodJyqPKqCQuQwmOpyj/rWcDILzFj2gIgUW5c9W6jD7u91opMcDwaw4aNEvEtGX6ks5XDIMIkUjI="; +// +// +// +// boolean pass = api.SYD_SM2_DetachedVerify_HA( "0000000000000002018091810000086272018-09-17T19:06:39CC00".getBytes(), sign2 ); +// System.out.println( pass ); +// +// // 获取公钥 +// X509 x = api.SYD_Get_X509_CertInfo_HA( "0000000000000002018091810000086272018-09-17T19:06:39CC00".getBytes(), sign2 ); +// System.out.println( Util.bytes2HexString( x.getPubKey() ) ); + + byte[]ttt = new byte[40960]; + Arrays.fill(ttt, (byte) 0x88); + String sign2 = api.SYD_SM2_Sign_HA( + "1234", + SydApi.DATA_HASH, + Util.hexString2Bytes("0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"), + ttt + ); + System.out.print("\n\n----- SM2 算法签名 结果: "); + System.out.println( sign2 ); + + System.out.println( api.SYD_SM2_Verify_HA( + SydApi.DATA_HASH, + Util.hexString2Bytes("0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"), + ttt , + sign2 + ) ); + + + + String sign3 = api.SYD_SM2_Sign_HA( + "1234", + SydApi.DATA_ORIGIN, + Util.hexString2Bytes("0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"), + "1015570000408702018091900000000012018-09-19T10:13:391015570000408702015970000397542018-09-1900000001123456,测试".getBytes() + ); + System.out.print("\n\n----- SM2 算法签名 结果: "); + System.out.println( sign3 ); + + System.out.println( api.SYD_SM2_Verify_HA( + SydApi.DATA_ORIGIN, + Util.hexString2Bytes("0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"), + "1015570000408702018091900000000012018-09-19T10:13:391015570000408702015970000397542018-09-1900000001123456,测试".getBytes() , + sign3 + ) ); + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/DerBase64.java b/src/test/java/com/sunyard/sydapi/test/DerBase64.java new file mode 100644 index 0000000..bd4656e --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/DerBase64.java @@ -0,0 +1,38 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.proto.Util; +import com.sunyard.util.SYMUtil; + +public class DerBase64 { + public static void main(String[] args) { + +// String s = "W+O1ul8sVkWa071M8VFCJenstGxNa0HQ3P0WFzQ10KEo68A5nB0b4Ywx20H98lKdKduUGFFXkqOgaKq5OphrIg=="; +// byte[] c = SYMUtil.base64Sign2DerSign(s); +// String ss = SYMUtil.derSign2Base64Sign(c); +// +// +// System.out.println(s); +// System.out.println(ss); +// +// c = SYMUtil.base64Sign2DerSign(ss); +// ss = SYMUtil.derSign2Base64Sign(c); +// +// +// System.out.println(s); +// System.out.println(ss); + + + String s = "Q7SUNKlzHJ7IMUDrwTsp3qEtJG6WK68r0SgQzbRvaZMBEuW+3zQmWwa59TLxKslmPt+/rba8A0DAozUa9ULPyuzkDi6VIKU+NybHy5SsWWzaPdcFFuTGn1gKx+ZEJnisooD1+hINERBveggO5lNE82yYUgo8saD7dR3VpXj3LCsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="; + System.out.println(s); + byte[] c = SYMUtil.base64EnData2DerEnData(s); + + System.out.println( Util.bytes2HexString(c) ); + +// s = SYMUtil.derEnData2Base64EnData(c); +// +// System.out.println(s); + + + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/EBCDTest.java b/src/test/java/com/sunyard/sydapi/test/EBCDTest.java new file mode 100644 index 0000000..3570ec5 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/EBCDTest.java @@ -0,0 +1,9 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.util.CoderUtil; + +public class EBCDTest { + public static void main(String[] args) { + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/ErrorCode.kt b/src/test/java/com/sunyard/sydapi/test/ErrorCode.kt new file mode 100644 index 0000000..d768f11 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/ErrorCode.kt @@ -0,0 +1,11 @@ +package com.sunyard.sydapi.test + +fun main(args: Array) { + + var code = 32774 + + println( String.format("%X", code) ) + + System.setProperty("com.sunyard.sydapi4j.debug", "true") + +} \ No newline at end of file diff --git a/src/test/java/com/sunyard/sydapi/test/HEX.java b/src/test/java/com/sunyard/sydapi/test/HEX.java new file mode 100644 index 0000000..769d880 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/HEX.java @@ -0,0 +1,17 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.proto.Util; + +public class HEX { + + public static void main(String[] args) { + + int a = 123; + System.out.println( a & 0xFF ); + System.out.println( a >> 8 & 0xFF ); + + + System.out.println(Util.bytes2HexString( "MA".getBytes() ) ); + } + +} diff --git a/src/test/java/com/sunyard/sydapi/test/JsonTest.java b/src/test/java/com/sunyard/sydapi/test/JsonTest.java new file mode 100644 index 0000000..f7e894c --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/JsonTest.java @@ -0,0 +1,9 @@ +package com.sunyard.sydapi.test; + +public class JsonTest { + public static void main(String[] args) { + + System.out.println(String.format("%03X", 10)); + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/LoaderTest.java b/src/test/java/com/sunyard/sydapi/test/LoaderTest.java new file mode 100644 index 0000000..2aad297 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/LoaderTest.java @@ -0,0 +1,18 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.proto.ProtocolRender; +import com.sunyard.proto.ProtocolSet; +import com.sunyard.proto.loader.Loader; +import com.sunyard.proto.loader.ResourceLoader; +import com.sunyard.trans.PacketSN; + +import java.util.HashMap; + +public class LoaderTest { + + public static void main(String[] args) { + + + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/MACTest.java b/src/test/java/com/sunyard/sydapi/test/MACTest.java new file mode 100644 index 0000000..734b4b9 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/MACTest.java @@ -0,0 +1,54 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.RetWrap; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; +import racal.sunyard.main.SydApiBuilder; + +import java.util.Arrays; + +public class MACTest { + public static void main(String[] args) { + + + System.out.println("MAC 测试"); + byte[] testData = new byte[ 2 * 1024]; + SydApi4j api = (SydApi4j) new SydApiBuilder() + .setIp("172.16.17.162") + .useDebugMode() + .build(); + + + RetWrap ret; + try { + + String mac = api.MACCalc(2, 1, "X3E95C24E03921CFA8CB8BA02DC76E22B", 1, testData, 2); + System.out.println( mac ); + api.MACCheck( 2, 1, "X3E95C24E03921CFA8CB8BA02DC76E22B", 1, testData, mac ); + + + + mac = api.MACCalc(0, 0, "7DEB4320CE659D56", 1, testData, 2); + System.out.println( mac ); + api.MACCheck( 0, 0, "7DEB4320CE659D56", 1, testData, mac ); + + + mac = api.MACCalc(0, 0, "1234567812345678", 0, testData, 1); + System.out.println( mac ); + api.MACCheck( 0, 0, "1234567812345678", 0, testData, mac ); + + + mac = api.MACCalc(2, 0, "X12345678123456781234567812345678", 0, testData, 2); + System.out.println( mac ); + api.MACCheck( 2, 0, "X12345678123456781234567812345678", 0, testData, mac ); + + mac = api.MACCalc(2, 0, "X12345678123456781234567812345678", 0, testData, 3); + System.out.println( mac ); + api.MACCheck( 2, 0, "X12345678123456781234567812345678", 0, testData, mac ); + + } finally { + api.disconnect(); + } + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/NetTest.java b/src/test/java/com/sunyard/sydapi/test/NetTest.java new file mode 100644 index 0000000..7621bd5 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/NetTest.java @@ -0,0 +1,60 @@ +package com.sunyard.sydapi.test; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; + +public class NetTest { + + /* + * 字符转换为字节 + */ + private static byte charToByte(char c) { + return (byte) "0123456789ABCDEF".indexOf(c); + } + /* + * 16进制字符串转字节数组 + */ + public static byte[] hexString2Bytes(String hex) { + + if ((hex == null) || (hex.equals(""))){ + return null; + } + else if (hex.length()%2 != 0){ + return null; + } + else{ + hex = hex.toUpperCase(); + int len = hex.length()/2; + byte[] b = new byte[len]; + char[] hc = hex.toCharArray(); + for (int i=0; iL>003^0>033^4>L>003^1>023^P>033^5>053^Q>L>003^2>033^6>003^3>033^7>L>003THANK YOU>033>THANK YOU 中文>L>F".getBytes("UTF-8") , "GB2312")); + +// String r1 = api.GenerateRandom(1); +// System.out.println( r1 ); + + api.genAndPrintSplit("000", 'X'); + + } finally { + ((SydApi) api).disconnect(); + } + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/ScriptTest.java b/src/test/java/com/sunyard/sydapi/test/ScriptTest.java new file mode 100644 index 0000000..a79b56a --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/ScriptTest.java @@ -0,0 +1,24 @@ +package com.sunyard.sydapi.test; + +import javax.script.*; + +public class ScriptTest { + private static final ScriptEngineManager factory = new ScriptEngineManager(); + + public static void main(String[] args) throws ScriptException { + ScriptEngine gvEngine = factory.getEngineByName("groovy"); + gvEngine.eval("def signatureLen() {\n" + + " return println(\"123\")\n" + + "}"); + + Bindings bindings = new SimpleBindings(); + bindings.put("dd", 321); + + + Bindings bindings2 = new SimpleBindings(); + bindings.put("aa", "aa"); + + gvEngine.eval(" \n\n signatureLen()", bindings); + gvEngine.eval(" \n\n println(dd)"); + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/Status.java b/src/test/java/com/sunyard/sydapi/test/Status.java new file mode 100644 index 0000000..29be315 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/Status.java @@ -0,0 +1,25 @@ +package com.sunyard.sydapi.test; + + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + +public class Status { + public static void main(String[] args) throws UnsupportedEncodingException { + System.setProperty("com.sunyard.sydapi4j.debug", "true"); + SydApi4j api = (SydApi4j) new SydApi4j();//.connect("wuyong.fullstack.club" , 8889, null,1000); + api.connect("172.16.17.162", 8889, null, 5000); + + RetWrap r = api.getStatus(); + System.out.println( r.get("CPU") ); + System.out.println( r.get("MEM") ); + System.out.println( r.get("DISK") ); + + api.disconnect(); + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/Test74.java b/src/test/java/com/sunyard/sydapi/test/Test74.java new file mode 100644 index 0000000..887e871 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/Test74.java @@ -0,0 +1,42 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.SydApi; +import com.sunyard.cert.X509; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +public class Test74 { + + public static void main(String[] args) { + SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.17.162", 8889, 1000); + + SydApi4j api = (SydApi4j) new SydApi4j(); + + + String pk = "03420004C9FD0B37230DF91621F6880C8123A445CB14FFB1B1342D0AC9449374876A4B1E00A15B9E8DF307EE538526883F093568C5B70C5A61BEF5F880C827DDC90366B5"; + String sk = "00010000C530EFBC1971D6526BDAB640370EE9197BFB0D78F88417C1ED49981FFEF226980000000000000000000000000000000000000000000000000000000000000000"; + byte[] skByte = Util.hexString2Bytes(sk); + byte[] pkByte = Util.hexString2Bytes(pk); + + String data = "MainBody>1015570000408702018091900000000012018-09-19T10:13:391015570000408702015970000397542018-09-1900000001123456,测试"; + + + String sign3 = api.SYD_SM2_Sign_HA( + SydApi.DATA_ORIGIN, + skByte, + pkByte, + data.getBytes() + ); + System.out.print("\n\n----- SM2 算法签名 结果: "); + System.out.println(sign3); + + + System.out.println(api.SYD_SM2_Verify_HA( + SydApi.DATA_ORIGIN, + pkByte, + data.getBytes(), + sign3 + )); + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestAESEnDeApi.java b/src/test/java/com/sunyard/sydapi/test/TestAESEnDeApi.java new file mode 100644 index 0000000..a7397f7 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestAESEnDeApi.java @@ -0,0 +1,94 @@ +package com.sunyard.sydapi.test; + + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.Arrays; + +import static com.sunyard.SydApi.ALG_AES; + +/** + * SydApi AES256 + * 调用方法参考如下,加密机需要相应的设置。 + */ +public class TestAESEnDeApi { + + public static void write(String file, String content) { + write(file, content.getBytes()); + } + + public static void write(String file, byte[] content) { + try { + File f = new File(file); + if (!f.exists()) { + f.createNewFile(); + } + FileOutputStream fos = new FileOutputStream(f); + fos.write(content); + } catch (Exception e) { + System.out.println("写入文件 " + file + " 异常"); + } + } + + public static String read(String file) { + try { + File f = new File(file); + if (!f.exists()) { + return null; + } + FileInputStream fis = new FileInputStream(f); + byte[] buff = new byte[5024]; + int len = fis.read(buff); + return new String(buff, 0, len); + } catch (Exception e) { + return null; + } + } + + public static void main(String[] args) { + + // 连接加密机 + SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.18.99", 8889, null, 1000); + + + try { + + + byte[] testData = "".getBytes(); + + // 生成密钥 + // 注意 'L' 表示 AES 所用的密钥 + String seesionKey = "L" + api.GenerateRandom(64 ); + + + System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 CBC -----"); + + byte[] enDataCBC = api.SYMEncryptDataCBC(SydApi.NALG_AES, seesionKey, testData); + System.out.print("密文 : "); + System.out.println(Util.bytes2HexString(enDataCBC)); + write("./EnData.bin", enDataCBC); + + + System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 CBC -----"); + byte[] deDataCBC = api.SYMDecryptDataCBC(SydApi.NALG_AES, seesionKey, enDataCBC); + System.out.print("解密 : "); + System.out.println(Util.bytes2HexString(deDataCBC)); + write("./DeData.bin", deDataCBC); + + // 原始报文是字符串,还原原始报文 + System.out.println( new String(testData) ); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + api.disconnect(); + } + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestBB.java b/src/test/java/com/sunyard/sydapi/test/TestBB.java new file mode 100644 index 0000000..6b7336d --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestBB.java @@ -0,0 +1,17 @@ +package com.sunyard.sydapi.test; + +import java.nio.ByteBuffer; + +public class TestBB { + + public static void main(String[] args) { + + + byte[] d = new byte[ 1024 ]; + ByteBuffer bb = ByteBuffer.wrap( d ); + + bb.position( d.length ); + bb.flip(); + bb.get(); + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestByteBuffer.java b/src/test/java/com/sunyard/sydapi/test/TestByteBuffer.java new file mode 100644 index 0000000..0a00000 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestByteBuffer.java @@ -0,0 +1,13 @@ +package com.sunyard.sydapi.test; + +import java.nio.ByteBuffer; +import java.util.Arrays; + +public class TestByteBuffer { + public static void main(String[] args) { + ByteBuffer bb = ByteBuffer.allocate(2); + bb.put(0, (byte) 1); + bb.put(0, (byte) 2); + System.out.println(Arrays.toString(bb.array())); + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestCB.java b/src/test/java/com/sunyard/sydapi/test/TestCB.java new file mode 100644 index 0000000..9e7a26e --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestCB.java @@ -0,0 +1,42 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.inf.SydPledge; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; +import racal.sunyard.main.SydApiBuilder; + +import java.io.UnsupportedEncodingException; + + +public class TestCB +{ + + public static void main(String[] args) throws UnsupportedEncodingException { + + System.out.println("SydApi 测试程序启动"); + + SydApi key = new SydApiBuilder() + .setIp("192.168.0.222") + //.useEBCDMode() + .build(); + + + + String srcKey = "303030303030303030303030303030323030413030303030303030"; + String desKey = "583234364637434543324546303941374138463034373543364231434534423035"; + String sPin = "3244454345364241344134413345453531413130423034313945393539354339"; + String primaryAccount = "313233343536373839303132"; + + RetWrap retWrap = key.generateDE("100", (byte) 1); + String seesionKey = (String) retWrap.get("SessionKey"); + byte[] bytePin = key.transPinFrOneKeyToAno( "XK" + srcKey, desKey, 2, sPin, primaryAccount); + + System.out.println("执行结束\n\n" ); + key.disconnect(); + + } + + +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestChar.java b/src/test/java/com/sunyard/sydapi/test/TestChar.java new file mode 100644 index 0000000..847902f --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestChar.java @@ -0,0 +1,40 @@ +package com.sunyard.sydapi.test; + +public class TestChar { + + public static void main(String[] args) { + + String s="headername"; + String[] a=s.split("\\."); + System.out.println(a.length); + + + +//25CFC2EC2EB59D63836E20BBB2CB36C12699A22D4857B694B43F14A4B51A1B3BC44192F927BAE721FC223D27E9FE42EB61C43BD9D1853E32AAC03476BEB67419F6166167E93D087708649F582EA8E6B7FA3168B87BE793201BC49F43E058467781492348 + +//0383 = 899 +//0000000000000000 +//8017 +//0000 +//02EB = 747 +//8303330373034303134370000883033343230303034333632393745393446433332314536343637453346314330353632344142384336424230304139364237303137303532313737384637374633373732433931374145344232344233323546313443393145433638454433333839433442444330463236333330463239433238313131413335434244314645413843333141313830433D434E2C4F3D4368696E612046696E616E6369616C2043657274696669636174696F6E20417574686F726974792C434E3D43464341205445535420534D32204F4341310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003130303432383234353100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000433D434E2C4F3D43464341204F4341312C4F553D594343412C4F553D496E646976696475616C2D322C434E3D5943434140BBC6BDF0BDBBD2D7CBF9405A6875616E676A4031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032303137303330373034303134370032303137559323476553030794C324E79624445774F44457559334A734D41344741315564447745422F775145417749477744416442674E56485134450A46675155517044723068616D52584250334750786C744E784A5578516B714177485159445652306C42425977464159494B7759424251554841774947434373470A4151554642774D454D41774743430000 + + + //System.out.println( '0' == "1230".charAt(3)); + +// ByteBuffer bb = ByteBuffer.allocate(10); +// bb.put((byte) 1); +// bb.put(new byte[3]); +// bb.put((byte) 1); +// System.out.println(Arrays.toString(bb.array()));038300000000000000008017000002EB433D434E2C4F3D4368696E612046696E616E6369616C2043657274696669636174696F6E20417574686F726974792C434E3D43464341205445535420534D32204F4341310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003130303432383234353100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000433D434E2C4F3D43464341204F4341312C4F553D594343412C4F553D496E646976696475616C2D322C434E3D5943434140BBC6BDF0BDBBD2D7CBF9405A6875616E676A40310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000323031373033303730343031343700323031383033303730343031343700008830333432303030343336323937453934464333323145363436374533463143303536323441423843364242303041393642373031373035323137373846373746333737324339313741453442323442333235463134433931454336384544333338394334424443304632363333304632394332383131314133354342443146454138433331413138307559323476553030794C324E79624445774F44457559334A734D41344741315564447745422F775145417749477744416442674E56485134450A46675155517044723068616D52584250334750786C744E784A5578516B714177485159445652306C42425977464159494B7759424251554841774947434373470A4151554642774D454D41774743430000 + + + //System.out.println(Integer.valueOf(3) == Integer.valueOf(3)); + +// System.out.println(Util.bytes2HexString("time".getBytes())); +// System.out.println(Util.bytes2HexString("ping".getBytes())); +// System.out.println(Util.bytes2HexString("pong".getBytes())); + + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestDecryptDataWithFile.java b/src/test/java/com/sunyard/sydapi/test/TestDecryptDataWithFile.java new file mode 100644 index 0000000..fd18a11 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestDecryptDataWithFile.java @@ -0,0 +1,46 @@ +package com.sunyard.sydapi.test; + + +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +import java.io.*; + + +public class TestDecryptDataWithFile +{ + + public static void main(String[] args) throws Exception { + + System.out.println("SydApi 测试程序启动"); + SydApi key = new SydApi4j().connect("172.16.18.74",8889,null,10000); + System.out.println("连接成功"); + + long startTime = System.currentTimeMillis(); //获取开始时间 + + byte[] bytes = Util.hexString2Bytes("CBB5DF1ECDB7564EFDA62076632F459BD8F618DC060A5AC368848C5A1D78A85CAFA26F8228F446E2ABA5AEA8F32CF91B606CFD2125766DD3A4E47F4DD22D3A198C2000E9C6F1B73FA33BFE13A00D3612DC9D7C2811A7C1ABAEDBAEEBE8E18D9A2CD670A2526E98C50C4F9205FDE32162E7C8583154D5DDEF2D1B71C6C1636F684BCF865A8EC852C389DEB381728806AC5659E7980651528C0B6F86A47881A66F2C21317D778253786765D60EAA73BC7C6C4CE658BB5231A4FE7282646B0DC774E0B56E38DA29FBA654DB6973661BC65227751E98AB2DD1EBB8076E32D1DB8712"); + + + String inputPath = "c:\\Users\\MrYang\\Desktop\\dataEncrypt.txt"; + String outputPath = "c:\\Users\\MrYang\\Desktop\\dataDncrypt.txt"; + try { + FileOutputStream fileWriter =new FileOutputStream(inputPath); + fileWriter.write(bytes); + fileWriter.flush(); + fileWriter.close(); + }catch (IOException e){ + e.printStackTrace(); + } + + + key.SYMDecryptDataWithFile(1, "X246F7CEC2EF09A7A8F0475C6B1CE4B05", inputPath, outputPath); + + long endTime=System.currentTimeMillis(); //获取结束时间 + System.out.println("程序运行时间: "+(endTime-startTime)+"ms"); + + System.out.println("执行结束\n\n" ); + key.disconnect(); + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestECBWithFile.java b/src/test/java/com/sunyard/sydapi/test/TestECBWithFile.java new file mode 100644 index 0000000..510f98d --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestECBWithFile.java @@ -0,0 +1,84 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import racal.sunyard.main.SydApi4j; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.UnsupportedEncodingException; + + +public class TestECBWithFile +{ + + public static void main(String[] args) throws UnsupportedEncodingException { + + System.out.println("SydApi 测试程序启动"); + /*SydApi key = new SydApi4j().connect("172.16.18.72",8889,null,10000); + System.out.println("连接成功"); + + + + int lenIndata = 0; + try { + lenIndata = getInDataLen("d:\\TestFile.txt"); + }catch (Exception e) + {} + byte[] data = new byte[lenIndata]; + try { + data = getInData("d:\\TestFile.txt"); + } catch (Exception e) + {} + + byte[] encryptData = key.SYMEncryptData(0x01, "X246F7CEC2EF09A7A8F0475C6B1CE4B05",data); + + try { + outData2file(encryptData, "d:\\TestFileEncrypt.txt"); + } catch (Exception e) + {} + + byte[] decryptData = key.SYMDecryptData(0x01, "X246F7CEC2EF09A7A8F0475C6B1CE4B05",encryptData);*/ + +// byte[] decryptDataWithFile = key.SYMDecryptDataWithFile(0x01, "X246F7CEC2EF09A7A8F0475C6B1CE4B05","d:\\TestFileEncrypt.txt"); + byte a = 1; + int x = (a- 0x30); + System.out.println("执行结束\n\n:"+ x); +// key.disconnect(); + + } + + // 读取文件长度 + public static int getInDataLen(String filePath) throws Exception + { + FileInputStream tmpInput = new FileInputStream(filePath); + int lenInData = tmpInput.available(); + + return lenInData; + } + + // 读取文件内容 + public static byte[] getInData(String fileName) throws Exception { + FileInputStream tmpInput = new FileInputStream(fileName); + int InDataLen = tmpInput.available(); + + byte[] InData = new byte[InDataLen]; + + tmpInput.read(InData); + tmpInput.close(); + + System.out.println("[Info] Read File:{" + fileName + "}, Read Length:{" + InDataLen + "} ..."); + + return InData; + } + + // 写入文件内容 + public static void outData2file(byte[] outData, String filePath) throws Exception + { + FileOutputStream tmpOutput = new FileOutputStream(filePath); + tmpOutput.write(outData); + tmpOutput.close(); + } + + +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestEnDeApi.java b/src/test/java/com/sunyard/sydapi/test/TestEnDeApi.java new file mode 100644 index 0000000..3a1c846 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestEnDeApi.java @@ -0,0 +1,114 @@ +package com.sunyard.sydapi.test; + + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + +/** + * SydApi 网联相关接口 + * 调用方法参考如下,加密机需要相应的设置。 + */ +public class TestEnDeApi { + + public static void write(String file, String content) { + write(file, content.getBytes()); + } + + public static void write(String file, byte[] content) { + try { + File f = new File(file); + if (!f.exists()) { + f.createNewFile(); + } + FileOutputStream fos = new FileOutputStream(f); + fos.write(content); + } catch (Exception e) { + System.out.println("写入文件 " + file + " 异常"); + } + } + + public static String read(String file) { + try { + File f = new File(file); + if (!f.exists()) { + return null; + } + FileInputStream fis = new FileInputStream(f); + byte[] buff = new byte[5024]; + int len = fis.read(buff); + return new String(buff, 0, len); + } catch (Exception e) { + return null; + } + } + + public static void main(String[] args) { + + System.setProperty("com.sunyard.sydapi4j.debug", "true"); + + // 连接加密机 + SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.1.226", 8889, null, 1000); + + + + final String testSN1 = "1004282451"; + final String testSN2 = "1004282452"; + final String testPubKey = "0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"; + final String testPubKey1 = "034200040B2FCF5E2B15D341FC12A9B6A88631D83A7B79DC6BABF9E49FFF624BD148E2FA44A9F1B7F1E36E39B22AA6BD79B7EA527DB912617148A62CB94760CB80EE3A68"; + byte[] testData = new byte[ 10 ]; + Arrays.fill(testData, (byte) 0x88); + testData[testData.length - 3] = (byte) 0xFF; + testData[testData.length - 2] = (byte) 0xFF; + testData[testData.length - 1] = (byte) 0xFF; + final String testUser = "8012"; + + + try { + + +// // testData = "".getBytes(); +// System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 -----"); +// String sessionKey = read("./SessionKey.bin"); +// byte[] enSm4Data = api.SYMEncryptData(SydApi.NALG_SM4, sessionKey, testData); +// System.out.print("密文 : "); +// System.out.println(Util.bytes2HexString(enSm4Data)); +// write("./EnData.bin", enSm4Data); + +// +// System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 -----"); +// byte[] deSM4Data = api.SYMDecryptData(SydApi.NALG_SM4, sessionKey, enSm4Data); +// System.out.print("解密 : "); +// System.out.println(Util.bytes2HexString(deSM4Data)); +// write("./DeData.bin", enSm4Data); +// + + System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 CBC -----"); + String sessionKeyCBC = "X12345678123456781234567812345678"; //read("./SessionKey.bin"); + byte[] enDataCBC = api.SYMEncryptDataCBC(SydApi.NALG_SM4, sessionKeyCBC, testData); + System.out.print("密文 : "); + System.out.println(Util.bytes2HexString(enDataCBC)); + write("./EnData.bin", enDataCBC); + + + System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 CBC -----"); + byte[] deDataCBC = api.SYMDecryptDataCBC(SydApi.NALG_SM4, sessionKeyCBC, enDataCBC); + System.out.print("解密 : "); + System.out.println(Util.bytes2HexString(deDataCBC)); + write("./DeData.bin", deDataCBC); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + api.disconnect(); + } + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestException.java b/src/test/java/com/sunyard/sydapi/test/TestException.java new file mode 100644 index 0000000..4d16c77 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestException.java @@ -0,0 +1,15 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.SydApiException; + +public class TestException { + + public static void main(String[] args) { + + //System.out.println( new SydApiException("通信数据错误", -3) ); + + + new SydApiException("通信数据错误", -3).printStackTrace(); + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestGongYin.java b/src/test/java/com/sunyard/sydapi/test/TestGongYin.java new file mode 100644 index 0000000..225ace4 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestGongYin.java @@ -0,0 +1,92 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; +import racal.sunyard.main.SydApiBuilder; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + + +public class TestGongYin +{ + + public static void main(String[] args) throws UnsupportedEncodingException { + + System.out.println("工银亚洲测试功能测试"); + byte[] testData = new byte[17000]; + Arrays.fill(testData, (byte) 0x88); + + SydApi api = new SydApiBuilder() + .setIp("192.168.0.222") + .useEBCDMode() + .useDebugMode() + .useETEncrypt() + .build(); + +// SydApi api = new SydApi4j().connect("192.168.0.222", 8889, null, 3000); + + try { + + String r32 = api.GenerateRandom(32); + System.out.println( r32 ); + + + // + // 6A000163C9300000000009CX + RetWrap wrapNum = api.generateDE("1000000020", SydApi.ALG_SM4); + System.out.print("Session Key : "); + System.out.println(wrapNum.get(SydApi.RET_SESSION_KEY)); + System.out.print("Cipher Key : "); + System.out.println(wrapNum.get(SydApi.RET_CIPHER_KEY)); + System.out.print("KCV: "); + System.out.println(wrapNum.get(SydApi.RET_KCV)); + + + + String ck = wrapNum.get(SydApi.RET_CIPHER_KEY).toString(); + RetWrap wrap = api.decryptDE("1000000020", ck); + System.out.print("Session Key : "); + System.out.println(wrap.get(SydApi.RET_SESSION_KEY)); + String sk = (String) wrap.get(SydApi.RET_SESSION_KEY); + + System.out.print("KCV : "); + System.out.println(wrap.get(SydApi.RET_KCV)); + + + System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 -----"); + byte[] enSm4Data = api.SYMEncryptData(SydApi.NALG_SM4, sk, testData); + System.out.print("密文 : "); + System.out.println(Util.bytes2HexString(enSm4Data)); + + + + System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 -----"); + byte[] deSM4Data = api.SYMDecryptData(SydApi.NALG_SM4, sk, enSm4Data); + System.out.print("解密 : "); + System.out.println(Util.bytes2HexString(deSM4Data)); + + + + System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 CBC -----"); + byte[] enDataCBC = api.SYMEncryptDataCBC(SydApi.NALG_SM4, sk, testData); + System.out.print("密文 : "); + System.out.println(Util.bytes2HexString(enDataCBC)); + + + System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 CBC -----"); + byte[] deDataCBC = api.SYMDecryptDataCBC(SydApi.NALG_SM4, sk, enDataCBC); + System.out.print("解密 : "); + System.out.println(Util.bytes2HexString(deDataCBC)); + + + }finally { + api.disconnect(); + } + + } + + +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestHAApi.java b/src/test/java/com/sunyard/sydapi/test/TestHAApi.java new file mode 100644 index 0000000..4533126 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestHAApi.java @@ -0,0 +1,141 @@ +package com.sunyard.sydapi.test; + + +import com.sunyard.SydApi; +import com.sunyard.cert.X509; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +import java.io.UnsupportedEncodingException; + +public class TestHAApi { + public static void main(String[] args) throws UnsupportedEncodingException { + + + SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.17.162", 8889 , 1000); + + SydApi4j api = (SydApi4j) new SydApi4j();//.connect("wuyong.fullstack.club" , 8889, null,1000); + + + + System.out.println("\n\n----- 获取公钥 () -----"); + String pk = api.SYD_SM2_Get_Id_PublicKey_HA("1234", 0); + System.out.print("\r\n公钥 : "); + System.out.println( pk ); + + + String pk1 = api.SYD_SM2_Get_Dn_PublicKey_HA("C=CN,O=Sunyard,OU=8001,CN=8001".getBytes("GBK"), 0); + System.out.print("\r\n公钥 : "); + System.out.println( pk1 ); +// +// +// // 签名 + String data="1015570000408702018091900000000012018-09-19T10:13:391015570000408702015970000397542018-09-1900000001123456,测试"; + final String testPubKey = "0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"; +// System.out.println("\n\n----- SM2 算法签名 (原始数据) -----"); +// String sign = api.SYD_SM2_Sign_HA( +// "1234", +// SydApi.DATA_ORIGIN, +// Util.hexString2Bytes(testPubKey), +// data.getBytes() +// ); +// System.out.print("\n\n----- SM2 算法签名 结果: "); +// System.out.println( sign ); +// +// +// +// +// +// System.out.println("\n\n----- SM2 算法验签 (原始数据) -----"); +// boolean SM2VerifyRet = api.SYD_SM2_Verify_HA( +// SydApi.DATA_ORIGIN, +// Util.hexString2Bytes(testPubKey), data.getBytes() , sign); +// if (SM2VerifyRet){ +// System.out.println("验签通过"); +// }else{ +// System.err.println("验签失败"); +// throw new RuntimeException("验签失败"); +// } + + + +// // 签名验签 2 +// System.out.println("\n\n----- 签名验签 2 -----"); +// String sign2 = api.SYD_SM2_DetachedSign_HA( data.getBytes() , "C=CN,O=Sunyard,OU=8001,CN=8001"); +// System.out.println( sign2 ); + + + String sign2 = "MIICpQYKKoEcz1UGAQQCAqCCApUwggKRAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIIByTCCAcUwggFooAMCAQICCDyTAAAAAAAlMAwGCCqBHM9VAYN1BQAwJjELMAkGA1UEBhMCQ04xFzAVBgNVBAMMDlN1bnlhcmRTTTJSb290MB4XDTE3MDUxNzAyNTI0NFoXDTIyMDcyNTAyNTI0NFowPTELMAkGA1UEBhMCQ04xEDAOBgNVBAoMB1N1bnlhcmQxDTALBgNVBAsMBDgwMDExDTALBgNVBAMMBDgwMDEwWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAAQ+2joQe3zDXMAFx/vwu05rQ6B+4U42BgPSLsoqYAstD6AwVdQA0SQDAPVGSLhJ0T9QszD/FDUbVkWxNoaCCmW7o2cwZTAOBgNVHQ8BAf8EBAMCAMAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwHwYDVR0jBBgwFoAU93/arv8hxtk6eq2g+6z+AqVO1cEwHQYDVR0OBBYEFAMWZaY2AwaQTNiFLpsa0dyCzBZ6MAwGCCqBHM9VAYN1BQADSQAwRgIhAIl2ZHGfln5hedcousARzZ2yeUjUbxSFMmhMmr5t6Q6nAiEAvqYX/KpIcvnPyB/Yiil+oq6DFdVM6P3vDxBhU/8taXExgaAwgZ0CAQEwMjAmMQswCQYDVQQGEwJDTjEXMBUGA1UEAwwOU3VueWFyZFNNMlJvb3QCCDyTAAAAAAAlMAwGCCqBHM9VAYMRBQAwDQYJKoEcz1UBgi0BBQAERzBFAiATwLIYiylt7xHmBkH6EclrchClxzLlKWC5guxxzkr58gIhANSw+owu8cyypdJtHGrGqjSiB1BVzGva+irUHelx/GbC"; + sign2 = "MIID7gYKKoEcz1UGAQQCAqCCA94wggPaAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIIC2jCCAtYwggJ6oAMCAQICBUACgAF0MAwGCCqBHM9VAYN1BQAwYTELMAkGA1UEBhMCQ04xMDAuBgNVBAoMJ0NoaW5hIEZpbmFuY2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEgMB4GA1UEAwwXQ0ZDQSBBQ1MgVEVTVCBTTTIgT0NBMzEwHhcNMTcxMTE2MDY1NDQ1WhcNMjIxMTE2MDY1NDQ1WjCBgzELMAkGA1UEBhMCQ04xHDAaBgNVBAoME0NGQ0EgVEVTVCBTTTIgT0NBMzExDjAMBgNVBAsMBVNIQ1BFMRkwFwYDVQQLDBBPcmdhbml6YXRpb25hbC0xMSswKQYDVQQDDCIwNTFA5LiK5rW356Wo5o2u5Lqk5piT5omAQEFBQUFBQUA4MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEYPA9UQRL/ZaThEN0nc3SwkOHw4hPDXG9hZeKiBnNdhgPy1EtX4My2bpNFpYMmQ0nvkJUM4qpJrF7MSqEws6rLaOB+TCB9jA/BggrBgEFBQcBAQQzMDEwLwYIKwYBBQUHMAGGI2h0dHA6Ly9vY3NwdGVzdC5jZmNhLmNvbS5jbjo4MC9vY3NwMB8GA1UdIwQYMBaAFATHvPlZAWk+jDQ2IGIYPN68tbsMMAwGA1UdEwEB/wQCMAAwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovLzIxMC43NC40Mi4zL09DQTMxL1NNMi9jcmwxLmNybDAOBgNVHQ8BAf8EBAMCBsAwHQYDVR0OBBYEFKJnS7XYRDWG9eqXtSzUZXK+De2/MB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDBDAMBggqgRzPVQGDdQUAA0gAMEUCIGaSRoaUSpoH4lW3at1ABluiNwFDH21jHesHmy0F5gjqAiEA0sUykW9E36F3qQ91YDvasQg8EnOMp1idhgt6pq/NUAYxgdgwgdUCAQEwajBhMQswCQYDVQQGEwJDTjEwMC4GA1UECgwnQ2hpbmEgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MSAwHgYDVQQDDBdDRkNBIEFDUyBURVNUIFNNMiBPQ0EzMQIFQAKAAXQwDAYIKoEcz1UBgxEFADANBgkqgRzPVQGCLQEFAARHMEUCIQDH3ePzq4nYJ8pAodJyqPKqCQuQwmOpyj/rWcDILzFj2gIgUW5c9W6jD7u91opMcDwaw4aNEvEtGX6ks5XDIMIkUjI="; + + + +// boolean pass = api.SYD_SM2_DetachedVerify_HA( "0000000000000002018091810000086272018-09-17T19:06:39CC00".getBytes(), sign2 ); +// System.out.println( pass ); + +// // 获取公钥 + X509 x = api.SYD_Get_X509_CertInfo_HA( "0000000000000002018091810000086272018-09-17T19:06:39CC00".getBytes(), sign2 ); + System.out.println( Util.bytes2HexString( x.getPubKey() ) ); + + + String sign3 = api.SYD_SM2_Sign_HA( + "1234", + SydApi.DATA_ORIGIN, + x.getPubKey(), + data.getBytes() + ); + System.out.print("\n\n----- SM2 算法签名 结果: "); + System.out.println( sign3 ); + + System.out.println( api.SYD_SM2_Verify_HA( + SydApi.DATA_ORIGIN, + x.getPubKey(), + "1015570000408702018091900000000012018-09-19T10:13:391015570000408702015970000397542018-09-1900000001123456,测试".getBytes() , + "MEUCIQD59AIVnr01eVm7TQ5zyx6kc1P7OYbVQb50lSL+ydWYcQIgX0/j/Tjim9J8aalnjSK+ljZ60tQ51KDRsuqNUkScZkQ=" + ) ); + + } +} + + +/* +801201484D61696E426F64793E3C4D736749643E3C49643E3130313535373030303034303837303230313830393139303030303030303030313C2F49643E3C4372654474546D3E323031382D30392D31395431303A31333A33393C2F4372654474546D3E3C2F4D736749643E3C517279723E3C4D627249643E3130313535373C2F4D627249643E3C427249643E3030303034303837303C2F427249643E3C2F517279723E3C5273706E723E3C4D627249643E3230313539373C2F4D627249643E3C427249643E3030303033393735343C2F427249643E3C2F5273706E723E3C42697A517279496E663E3C51727944743E323031382D30392D31393C2F51727944743E3C51727949643E30303030303030313C2F51727949643E3C436E74733E313233343536EFBC8CE6B58BE8AF953C2F436E74733E3C2F42697A517279496E663E3C2F4D61696E426F64793E01557141694541307355796B57394533364633715139315944766173516738456E4F4D703169646867743670712F4E55415978676467776764554341514577616A42684D517377435159445651514745774A44546A45774D433447413155454367776E51326870626D4567526D6C755957356A6157467349454E6C636E52705A6D6C6A59585270623234675158563061473979615852354D534177486759445651514444426444526B4E42494546445579425552564E5549464E4E4D6942505130457A4D51494651414B4141585177444159494B6F45637A315542677845464144414E42676B7167527A50565147434C514546414152484D455543495144483365507A71346E594A3870416F644A7971504B7143517551776D4F70796A2F72576344494C7A466A32674967555735633957366A44377539316F704D634477617734614E457645744758366B73355844494D496B556A493D0001 + + +801200A83C4D61696E426F64793E3C4D736749643E3C49643E3030303030303030303030303030303230313830393138313030303030383632373C2F49643E3C4372654474546D3E323031382D30392D31375431393A30363A33393C2F4372654474546D3E3C2F4D736749643E3C436572744E746663746E496E663E3C43686E6754703E434330303C2F43686E6754703E3C2F436572744E746663746E496E663E3C2F4D61696E426F64793E + 0155 + 7141694541307355796B57394533364633715139315944766173516738456E4F4D703169646867743670712F4E55415978676467776764554341514577616A42684D517377435159445651514745774A44546A45774D433447413155454367776E51326870626D4567526D6C755957356A6157467349454E6C636E52705A6D6C6A59585270623234675158563061473979615852354D534177486759445651514444426444526B4E42494546445579425552564E5549464E4E4D6942505130457A4D51494651414B4141585177444159494B6F45637A315542677845464144414E42676B7167527A50565147434C514546414152484D455543495144483365507A71346E594A3870416F644A7971504B7143517551776D4F70796A2F72576344494C7A466A32674967555735633957366A44377539316F704D634477617734614E457645744758366B73355844494D496B556A493D0001 +801200A83C4D61696E426F64793E3C4D736749643E3C49643E3030303030303030303030303030303230313830393138313030303030383632373C2F49643E3C4372654474546D3E323031382D30392D31375431393A30363A33393C2F4372654474546D3E3C2F4D736749643E3C436572744E746663746E496E663E3C43686E6754703E434330303C2F43686E6754703E3C2F436572744E746663746E496E663E3C2F4D61696E426F64793E + 0544 + 4D4949443767594B4B6F45637A31554741515143417143434139347767675061416745424D513477444159494B6F45637A315542677845464144414D42676F7167527A5056515942424149426F494943326A43434174597767674A366F414D434151494342554143674146304D41774743437142484D395641594E31425141775954454C4D416B474131554542684D43513034784D44417542674E5642416F4D4A304E6F6157356849455A70626D467559326C68624342445A584A3061575A7059324630615739754945463164476876636D6C30655445674D423447413155454177775851305A445153424251314D6756455654564342545454496754304E424D7A45774868634E4D5463784D5445324D4459314E4451315768634E4D6A49784D5445324D4459314E445131576A4342677A454C4D416B474131554542684D43513034784844416142674E5642416F4D45304E475130456756455654564342545454496754304E424D7A4578446A414D42674E564241734D42564E49513142464D526B77467759445651514C44424250636D6468626D6C365958527062323568624330784D5373774B51594456515144444349774E544641354C694B357257333536576F356F3275354C716B35706954356F6D415145464251554642515541344D466B77457759484B6F5A497A6A3043415159494B6F45637A3155426769304451674145595041395551524C2F5A615468454E306E633353776B4F487734685044584739685A654B69426E4E646867507931457458344D793262704E4670594D6D51306E766B4A554D3471704A7246374D537145777336724C614F422B544342396A412F4267677242674546425163424151517A4D4445774C7759494B775942425155484D41474749326830644841364C79397659334E776447567A6443356A5A6D4E684C6D4E766253356A626A6F344D43397659334E774D42384741315564497751594D4261414641544876506C5A41576B2B6A44513249474959504E36387462734D4D41774741315564457745422F7751434D4141774E67594456523066424338774C5441726F436D674A34596C6148523063446F764C7A49784D4334334E4334304D69347A4C30394451544D784C314E4E4D69396A636D77784C6D4E796244414F42 + + + +3045022012D85D4913F0628CFBEBC562DD31D2F18A92EFB5F019DACA916E7A55 + +1205CFF4022100D2AA5BEA6D173AE640D9C3F0FA17199C8D4F4D36E1EBFE132E1B38DF7AD35988 + +3045022012D85D4913F0628CFBEBC562DD31D2F18A92EFB5F019DACA916E7A55 + +1205CFF4022100D2AA5BEA6D173AE640D9C3F0FA17199C8D4F4D36E1EBFE132E + +0220 +30440220 + +3044 +0220 +3045 +0220 +12D85D4913F0628CFBEBC562DD31D2F18A92EFB5F019DACA916E7A5502201205CFF4 +0221 +00D2AA5BEA6D173AE640D9C3F0FA17199C8D4F4D36E1EBFE132E + + + + + +30440220 + +3045022012D85D4913F0628CFBEBC562DD31D2F18A92EFB5F019DACA916E7A551205CFF4022100D2AA5BEA6D173AE640D9C3F0FA17199C8D4F4D36E1EBFE132E +3045022012D85D4913F0628CFBEBC562DD31D2F18A92EFB5F019DACA916E7A551205CFF4022100D2AA5BEA6D173AE640D9C3F0FA17199C8D4F4D36E1EBFE132E1B38DF7AD35988 + */ diff --git a/src/test/java/com/sunyard/sydapi/test/TestIt.java b/src/test/java/com/sunyard/sydapi/test/TestIt.java new file mode 100644 index 0000000..dbbbc9e --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestIt.java @@ -0,0 +1,60 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +import java.io.UnsupportedEncodingException; + + +public class TestIt +{ + + public static void main(String[] args) throws UnsupportedEncodingException { + + System.out.println("SydApi 测试程序启动"); + + System.setProperty("com.sunyard.sydapi4j.debug","true"); + + + SydApi key = new SydApi4j().connect("172.16.18.73",8889,null,10000); + System.out.println("连接成功"); + + /* //原始数据 + byte[] data = "asfkahfkahfkahdaghfashflsaldfasf".getBytes(); + //X509 证书的序列号 + String pCertSerial = "112233"; + //数据明文 + byte[] data2 = "asfkahfkahfkafadfhdaghfashadfaflsaldfasf".substring(0,32).getBytes(); + //PKCS1签名 + String netSign = key.netSign(pCertSerial, data); + //PKCS1验签 + key.netVerify(pCertSerial,data,netSign); + //PKCS#7签名 + String s = key.detachedSign(1, data, "DN"); + //PKCS#7验签 + key.detachedVerify(1,data,s);*/ + //生成数字信封 + RetWrap retWrap = key.generateDE("1004282452", (byte)1); + String cipherKey = (String)retWrap.get("CipherKey"); + String seesionKey = (String) retWrap.get("SessionKey"); + //解密数字信封 + key.decryptDE("1004282452",cipherKey ); + //对称密钥加密-ECB +// byte[] bytes = key.SYMEncryptData(1, seesionKey, data2); + //对称密钥解密-ECB +// key.SYMDecryptData(1,seesionKey,bytes); + /* // 将PINBLOCK从一个密钥翻译到另一个密钥 + String srcKey = "000000000000000200A00000000"; // 源秘钥 + String desKey = seesionKey; // 目的秘钥 + String sPin = "2DECE6BA4A4A3EE51A10B0419E9595C9"; // 源Pin块 + String primaryAccount = "123456789012"; // 主账号 + byte[] bytePin = key.transPinFrOneKeyToAno(srcKey, desKey, 2, sPin, primaryAccount);*/ + System.out.println("执行结束\n\n" ); + key.disconnect(); + + } + + +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestKey2.java b/src/test/java/com/sunyard/sydapi/test/TestKey2.java new file mode 100644 index 0000000..1664e41 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestKey2.java @@ -0,0 +1,66 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +public class TestKey2 { + + public static void main(String[] args) { + + + SydApi hsm1 = (new SydApi4j()).connect("172.16.17.162", 8889,null , 10000); + SydApi hsm2 = (new SydApi4j()).connect("172.16.18.72", 8889,null , 10000); + + String hsm1_pk = "03420004DBF3A1BD52F4AC06E8F18A988104CC25F5F8DE85AA0BFFEE076CA6547C5C98CD49153C6B3F67A801F961890028AFF378A4F82166FDF6D2F02BDC17E6519FD09B"; + String hsm1_sk = "000100001EB9A893ED4589EA1AEF84D24EA52EE13FE1AE60D20E3BC9B3B0B87BDF1F14180000000000000000000000000000000000000000000000000000000000000000"; + + + String hsm2_pk = "0342000401A256CE599BDC6DFBD87FDB3D04F303A506EFE7E1A0569634703770BD4272C52B3BBCC13283B46204CA4EA34F7EA21764CDFC0AFCB8521BAEE6BD58DD8C4FB8"; + String hsm2_sk = "00010000EF3C17C8D971D52CD9F9561AA698CE1A28AD4894A73BE7F711BC3CCE6659BC730000000000000000000000000000000000000000000000000000000000000000"; + + + // 中心端 + String hsm1_keyA = "S6F91526D7E311230A768A31BB55C44FF"; // BBA1836255B9698C + + String hsm1_keyB = "S01A6A301EAFB237CD87012C0FA8CCACA"; // 87F88C219C74B08FD6950081CCB5DAD5 + + + // S3DE99F29940CA73A4878CB36EE988ECB + + // 会员端 + String hsm2_keyA = "SFB3989DB9783869658BC31CC8DB1D2DC"; // BBA1836255B9698C293987AA427D8E17 + + String hsm2_keyB = "SE0A2D5BDA20299CE687EB8EC87F1D4C3"; // 87F88C219C74B08F + + // S39A06BA1B157DD513B97907AA5DD2EEF + + + try { + + + + byte[] o = hsm2.SYMDecryptDataCBC(0x01, hsm2_keyA, Util.hexString2Bytes("4649F0894D0905D8F7DA4E5D8B9CE3BA") ); + + + System.out.println( Util.bytes2HexString( o ) ); + System.out.println( new String( o ) ); + + + byte[] o1 = hsm1.SYMDecryptDataCBC(0x01, hsm1_keyA, Util.hexString2Bytes("4649F0894D0905D8F7DA4E5D8B9CE3BA") ); + + + System.out.println( Util.bytes2HexString( o1 ) ); + System.out.println( new String( o1 ) ); + + }finally { + + hsm1.disconnect(); + hsm2.disconnect(); + } + + + } + + +} \ No newline at end of file diff --git a/src/test/java/com/sunyard/sydapi/test/TestKeyTool.java b/src/test/java/com/sunyard/sydapi/test/TestKeyTool.java new file mode 100644 index 0000000..adad0f5 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestKeyTool.java @@ -0,0 +1,121 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +public class TestKeyTool { + +//4649F0894D0905D8F7DA4E5D8B9CE3BA + public static void main(String[] args) { + + SydApi hsm1 = (new SydApi4j()).connect("172.16.17.162", 8889,null , 10000); + SydApi hsm2 = (new SydApi4j()).connect("172.16.18.72", 8889,null , 10000); + + String hsm1_pk = "03420004DBF3A1BD52F4AC06E8F18A988104CC25F5F8DE85AA0BFFEE076CA6547C5C98CD49153C6B3F67A801F961890028AFF378A4F82166FDF6D2F02BDC17E6519FD09B"; + String hsm1_sk = "000100001EB9A893ED4589EA1AEF84D24EA52EE13FE1AE60D20E3BC9B3B0B87BDF1F14180000000000000000000000000000000000000000000000000000000000000000"; + + + String hsm2_pk = "0342000401A256CE599BDC6DFBD87FDB3D04F303A506EFE7E1A0569634703770BD4272C52B3BBCC13283B46204CA4EA34F7EA21764CDFC0AFCB8521BAEE6BD58DD8C4FB8"; + String hsm2_sk = "00010000EF3C17C8D971D52CD9F9561AA698CE1A28AD4894A73BE7F711BC3CCE6659BC730000000000000000000000000000000000000000000000000000000000000000"; + + + // 中心端 + String hsm1_keyA = "S8B28E4D9E92250209E9CF2F36663911D"; // BBA1836255B9698C + + String hsm1_keyB = "S01A6A301EAFB237CD87012C0FA8CCACA"; // 87F88C219C74B08FD6950081CCB5DAD5 + + + // S3DE99F29940CA73A4878CB36EE988ECB + + // 会员端 + String hsm2_keyA = "S1423772EC5960B0054D946279E172F36"; // BBA1836255B9698C293987AA427D8E17 + + String hsm2_keyB = "SE0A2D5BDA20299CE687EB8EC87F1D4C3"; // 87F88C219C74B08F + + // S39A06BA1B157DD513B97907AA5DD2EEF + + + try { + + + +// RetWrap ret = hsm1.mixKey( hsm1_keyA, hsm1_keyB , "S" ); +// +// +// System.out.println( ret ); +// +// +// ret = hsm2.mixKey( hsm2_keyA, hsm2_keyB , "S" ); +// +// +// System.out.println( ret ); + + +// RetWrap ret = hsm1.SM2GenKeyPair(); +// String VK1 = Util.bytes2HexString((byte[]) ret.get("PublicKey")); +// String SK1 = Util.bytes2HexString((byte[]) ret.get("PrivateKey")); +// +// +// +// String key2 = "S31A82D54F09B237D648B2F84347777C5"; +// +// +// +// // lmk -> pken +// String ek = hsm2.enKeyPk( VK1 , key2 ); +// System.out.println( ek ); +// +// ret = hsm1.deKeyEx( SK1 , ek , "S"); +// String key1 = ret.get("lmk").toString(); +// +// +// +// +// System.out.println( key1 ); +// System.out.println( key2 ); + + + String key1 = "S376A03994307D447C63A225A2ADB1591"; + String key2 = "S1DE03BBD17083DABD4C1BF7ECD2D9193"; + + +// byte[] en1 = hsm1.SYMEncryptDataCBC(0x01, key1, "huangqian".getBytes() ); +// byte[] en2 = hsm2.SYMEncryptDataCBC(0x01, key2, "huangqian".getBytes() ); +// +// +// System.out.println( Util.bytes2HexString( en1 ) ); +// System.out.println( Util.bytes2HexString( en2 ) ); + + + byte[] w = new byte[0];//hsm2.SYMEncryptDataCBC( 0x01, key2, "d".getBytes() , Util.bytes2HexString("SHANGPIAOJIAOSUO".getBytes()).getBytes() ); + + + System.out.println( Util.bytes2HexString( w ) ); + + + byte[] o = hsm2.SYMDecryptDataCBC(0x01, key2, Util.hexString2Bytes("B8ACEBD675B5CBB5BCEAAE5BF41A9F813BE4CD94BA07745728E688FE8C27FE9C") ); + + + System.out.println( Util.bytes2HexString( o ) ); + System.out.println( new String( o ) ); + + + byte[] o1 = hsm1.SYMDecryptDataCBC(0x01, key1, Util.hexString2Bytes("B8ACEBD675B5CBB5BCEAAE5BF41A9F813BE4CD94BA07745728E688FE8C27FE9C") ); + + + System.out.println( Util.bytes2HexString( o1 ) ); + System.out.println( new String( o1 ) ); + + }finally { + + hsm1.disconnect(); + hsm2.disconnect(); + } + + + } + + +} \ No newline at end of file diff --git a/src/test/java/com/sunyard/sydapi/test/TestLast.java b/src/test/java/com/sunyard/sydapi/test/TestLast.java new file mode 100644 index 0000000..886e53a --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestLast.java @@ -0,0 +1,816 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import racal.sunyard.main.SydApi4j; + +public class TestLast { + SydApi4j api; + String keyTye = "000"; + String key1 = "1234567812345678"; + String key2 = "X12345678123456781234567812345678"; + String key6 = "U00000000000000000000000000000000"; + String key3 = "Y123456781234567812345678123456781234567812345678"; + String key4 = "X87654321876543218765432187654321"; + String key5 = "1234567812345678"; + String key7 = "12345678123456781234567812345678"; + + public static void main(String[] args) { + System.setProperty("com.sunyard.sydapi4j.debug", "true"); + SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.17.162", 8889, null, 1000); + + String keyTye = "000"; + String key1 = "1234567812345678"; + String key2 = "X12345678123456781234567812345678"; + String key6 = "U00000000000000000000000000000000"; + String key3 = "Y123456781234567812345678123456781234567812345678"; + String key4 = "X87654321876543218765432187654321"; + String key5 = "1234567812345678"; + String key7 = "12345678123456781234567812345678"; + + /* //RetWrap retWrap = api.conversionKey("000", key2, 'X'); ->pass + //2.2由2到9个ZMK成份组成一个ZMK(=) GY-> : code = 23 ( 0x17 ) msg = 未定义的错误 + String s1 = Util.bytes2HexString(key1.getBytes()); + String s2 = Util.bytes2HexString(key1.getBytes()); + RetWrap retWrap= api.genComposeKey(new String[]{s1,s2}); + System.out.println(retWrap);*//* + //将ZMK由ZMK转为LMK加密(+) BY -> pass + // RetWrap retWrap = api.changZMK2LMK( key2, key1); + //获取加密机cpu,内存,磁盘使用状况 HI ->接收数据超时 + // RetWrap retWrap = api.getStatus(); + //24.2获取加密机设备信息 -> pass + //RetWrap retWrap = api.getVersion("1234"); + //22.1计算HASH散列值(HMAC-MD5\SHA1\SHA256)(+) ->code = 129 ( 0x81 ) msg = 未定义的错误 等待消息 + // RetWrap retWrap = api.CalcHash(key1, 2, "0000",new byte[]{001,010}); + //System.out.println(retWrap); + //二十一章,80,81,7E三条指令 -> code = 33 ( 0x21 ) msg = 检索的数据或密钥不存在*/ + /**/ + + /* + + */ + + /* + */ + /* */ + + /**/ + + /* */ + + /* + */ + + + + /* */ + + + /* RetWrap retWrap = api.SM2GenKeyPair(); + String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey")); + String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")); + System.out.println(pk); + System.out.println(sk);*/ + + /*RetWrap retWrap = api.SM2OrRSAGenKeyPair(1,"006",256); + String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey")); + String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")); + System.out.println(pk); + System.out.println(sk); + + //15.7计算HASH散列值(MD5\SHA1\SHA256)(+) -> pass + RetWrap retWrap2 = api.conutHash(1,0, key2.getBytes(), key1.getBytes()); + String hash = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap2.get("hash")))); + System.out.println(hash); + + /* //15.3私钥加密指令(?) -> code = 13 ( 0xd ) msg = 未定义的错误(无返回加密数据) + byte[] bytes = api.encryptBySk(0, sk, "001".getBytes()); + System.out.println(bytes); + + byte[] bytes1 = api.decryptByPk(0, pk, bytes); + System.out.println(new String(bytes1));*/ + + /*//每一次重新生成都要更换索引值 + RetWrap retWrap = api.SM2OrRSAGenKeyPair(0,"0000000000000005",1024); + System.out.println(Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"))); + //获取私钥 + String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")); + System.out.println("sk:"+sk); + //获取公钥 + String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey")); + System.out.println("pk:"+pk); + + //15.7计算HASH散列值(MD5\SHA1\SHA256)(+) -> pass + RetWrap retWrap1 = api.conutHash(1,0, key2.getBytes(), key1.getBytes()); + String hash = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("hash")))); + System.out.println(hash); + System.out.println(retWrap1); + + //15.5 RSA私钥签名(+) -> pass + byte[] bytes = api.RSASignC("0000000000000005", 1, 0,(byte[]) retWrap1.get("hash")); + System.out.println(bytes); + //15.6 RSA验证签名(+) -> pass + boolean hash1 = api.RSAVerify(1, 0, (byte[]) retWrap.get("PublicKey"), (byte[]) retWrap1.get("hash"), bytes); + System.out.println(hash1);*/ + + + /* //10.1装载对称密钥至用户存储区(=) -> pass + RetWrap retWrap1 = api.genSymmetricKey(keyTye, 'X'); + String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey")))); + String keyCheck = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("keyCheck")))); + System.out.println(lmkKey); + System.out.println(keyCheck); + Boolean loadKey = api.loadKey("999999999999999900000000003", lmkKey,keyCheck); + System.out.println(loadKey);*/ + + /*//10.2从用户存储区读取对称密钥(=) -> pass + RetWrap retWrap1 = api.readKey("999999999999999900000000003"); + System.out.println(retWrap1); + System.out.println(retWrap1.get("key")); + String key = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("key")))); + System.out.println(key);*/ + + /*//10.3更新对称密钥至用户存储区(=) -> pass + RetWrap retWrap1 = api.genSymmetricKey(keyTye, 'X'); + String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey")))); + String keyCheck = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("keyCheck")))); + System.out.println(lmkKey); + System.out.println(keyCheck); + Boolean updateKey = api.updateKey("999999999999999900000000012", lmkKey,keyCheck); + System.out.println(updateKey);*/ + + + /*//9.2 数据转加密指令(Y0)(=) -> pass 密文数据那项不一定需要传加密出来的数据 + //生成DEK + RetWrap retWrap1 = api.genSymmetricKey("000", 'X'); + System.out.println("sDEK:"+ new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey"))))); + String sDEK = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey")))); + + RetWrap retWrap2 = api.genSymmetricKey("000", 'X'); + String dDEK = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap2.get("lmkKey")))); + System.out.println("dDEK:"+dDEK); + + byte[] bytes1 = api.switchEncryY("000", 1, "000", 1, 2, sDEK, dDEK, key1.getBytes(), key1); + System.out.println(new String(key1.getBytes())); + System.out.println(bytes1);*/ + + + /* //8.3用对大消息生成MAC(MAB)(*) -> pass + //8.4对大消息生成MAC(MAB)(PBOC3.0方式)(*) -> pass + //生成TAK + RetWrap retWrap = api.genTAK(key2); + System.out.println(retWrap); + String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey")))); + System.out.println(lmkKey); + String tmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("tmkKey")))); + System.out.println(tmkKey); + + byte[] bytes = api._calcPBOCMAC(0, 0, lmkKey, key1.getBytes(), 0, key1.getBytes()); + System.out.println(bytes); + + RetWrap retWrap1 = api.genMAB(0, 0, 0, lmkKey, key1.getBytes(), key1.getBytes()); + System.out.println(retWrap1); +*/ + + /* //7.1生成一个随机的PIN(=) -> pass 不能传算法标识和加密算法这两项,否则报错 + String s = api.genPIN("123456789123"); + System.out.println(s);*/ + + /* //7.2解密PINBLOCK, 并打印PIN 明文(=) -> : code = -2 ( 0xfffffffe ) msg = 接收数据超时 + String s = api.genPIN("123456789123"); + System.out.println(s); + Boolean c = api.decryPINBAndPrint('B', "123456789123", 1, s); + System.out.println(c); +*/ + + /* //生成: LMK对(02-03)下加密的导出PINBLOCK + String account="123456789123"; + String s1 = api.genPIN(account); + System.out.println("7.1LMK对(02-03)下加密的导出PINBLOCK:"+s1); + //7.5将PINBLOCK从LMK翻译到ZPK(*) ->pass + String s2 = api.transPINFromLMKToZPK(key4, 0, 1, 01, s1, account); + System.out.println("7.5将PINBLOCK从LMK翻译到ZPK(*):"+s2); + //7.3将PINBLOCK从一个ZPK翻译到另一个ZPK(*) ->pass + String s3 = api.transPINFromZPKToZPK(key4, key2, 1, 1,01,01, s2, account); + System.out.println("7.3将PINBLOCK从一个ZPK翻译到另一个ZPK(*)"+s3); + //7.4将PINBLOCK从ZPK翻译到LMK(*) ->pass + String s4 = api.transPINFromZPKToLMK(key2, 1, 1, 01, s3, account); + System.out.println("7.4将PINBLOCK从ZPK翻译到LMK(*)"+s4);*/ + /* //7.6将PINBLOCK从TPK翻译到ZPK(=) -> pass + String s2 = api.transPINFromLMKToZPK(key4, 0, 0, 01, s1, account); + System.out.println("7.5将PINBLOCK从LMK翻译到ZPK(*):"+s2); + String s10 = api.transPinFrOneKeyToAno("001", "002", key4, key2, 0, 0, s2, account); + System.out.println("LMK对(14-15)下加密:"+s10); + String s6 = api.transPINFromTPKToZPK(key2, key4, 0, 0, 01, 01, s10, account); + System.out.println("7.6将PINBLOCK从TPK翻译到ZPK(=):"+s6);*/ + /*//7.7将PINBLOCK从TPK翻译到LMK(=) -> pass + String s2 = api.transPINFromLMKToZPK(key4, 0, 0, 01, s1, account); + System.out.println("7.5将PINBLOCK从LMK翻译到ZPK(*):"+s2); + String s10 = api.transPinFrOneKeyToAno("001", "002", key4, key2, 0, 0, s2, account); + System.out.println("LMK对(14-15)下加密:"+s10); + String s7 = api.transPINFromTPKToLMK(key2, 0, 1, 01, s10, account); + System.out.println("7.7将PINBLOCK从TPK翻译到LMK(=):"+s7);*/ + /* //7.8 加密一个明文的PIN(*) -> pass + String s2 = api.encryPIN(0, "06123486FFFFFFFF", account); + System.out.println(s2); + //7.9解密一个已加密的PIN(*) -> 只解出原PIn,缺少参考数这一项 + String s3 = api.decryPIN(0, s2, account); + System.out.println(s3);*/ + /* //7.10将PINBLOCK从一个密钥翻译到另一个密钥 -> pass + String s2 = api.transPINFromLMKToZPK(key4, 0, 0, 01, s1, account); + System.out.println("7.5将PINBLOCK从LMK翻译到ZPK(*):"+s2); + String s = api.transPinFrOneKeyToAno("001", "001", key4, key2, 0, 0, s2, account); + System.out.println(s);*/ + + /*//6.1生成一个TAK(=) : -> pass + RetWrap retWrap = api.genSymmetricKey("002", 'Z'); + String tmk = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey")))); + String keyCheck = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("keyCheck")))); + System.out.println("tmk:"+tmk); + System.out.println(keyCheck); + RetWrap retWrap1 = api.genTAK(tmk); + System.out.println(retWrap1); + String lmk = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey")))); + System.out.println("lmk:"+lmk); + String tmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("tmkKey")))); + System.out.println("tmk:"+tmkKey); + //6.3将TAK从LMK转为ZMK加密(=) -> PASS + RetWrap retWrap2 = api.transTAKFromLMKToZMK(key2, lmk); + System.out.println(retWrap2); + String zmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap2.get("zmkKey")))); + System.out.println("6.3将TAK从LMK转为ZMK加密,zmkKey:"+zmkKey); + //6.2将TAK从ZMK转为LMK加密(=) -> pass + RetWrap retWrap3 = api.transTAKFromZMKToLMK(key2, zmkKey); + System.out.println(retWrap3); + String lmkKey3 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap3.get("lmkKey")))); + System.out.println("6.2将TAK从ZMK转为LMK加密(=),lmkKey3:"+lmkKey3); + //6.4将TAK从LMK转为TMK加密(=) -> PASS + RetWrap retWrap4 = api.transTAKFromLMKToTMK(tmk, lmkKey3); + System.out.println(retWrap4); + String tmkKey4 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap4.get("tmkKey")))); + System.out.println("6.4将TAK从LMK转为TMK加密,tmkKey4:"+tmkKey4);*/ + + /*//5.1生成一个TMK、TPK或PVK加密下的新密钥(=) -> PASS + RetWrap retWrap = api.genSymmetricKey("002", 'Z'); + String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey")))); + String keyCheck = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("keyCheck")))); + System.out.println(lmkKey); + System.out.println(keyCheck); + RetWrap retWrap1 = api.genKeyByTMKOrTPKOrPVK(lmkKey); + System.out.println(retWrap1); + String lmkKey1 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey")))); + String tmkKey1 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("tmkKey")))); + System.out.println("当前的TMK (TPK或PVK)下加密的新密钥,tmkKey1:"+tmkKey1); + System.out.println("LMK下加密的新密钥,lmkKey1:"+lmkKey1); + //5.2将TMK、TPK或PVK从LMK转为另一TMK、TPK或PVK加密(+) -> PASS + RetWrap retWrap2 = api.genSymmetricKey("002", 'Z'); + String lmkKey2 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey")))); + RetWrap retWrap22 = api.tranKeyByTMKToAno(tmkKey1, lmkKey2); + System.out.println(retWrap22); + String tmkKey2 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap22.get("tmkKey")))); + System.out.println("tmkKey2:"+tmkKey2); + //5.4将TMK、TPK或PVK从LMK转为ZMK加密(=) ->PASS + RetWrap retWrap4 = api.tranKeyByTMKFromLMKToZMK(key2, tmkKey2); + System.out.println(retWrap4); + String tmkKey4 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap4.get("tmkKey")))); + System.out.println("5.4将TMK、TPK或PVK从LMK转为ZMK加密,tmkKey4:"+tmkKey4); + //5.3将TMK、TPK或PVK从ZMK转为LMK加密(=) -> PASS + RetWrap retWrap3 = api.tranKeyByTMKFromZMKToLMK(key2, tmkKey4); + System.out.println(retWrap3); + String tmkKey3 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap3.get("tmkKey")))); + System.out.println("5.3将TMK、TPK或PVK从ZMK转为LMK加密(=):"+tmkKey3);*/ + + /* //4.1生成一个ZEK/ZAK(=) ->pass + RetWrap retWrap = api.genZEKOrZAK(0, key2); + System.out.println(retWrap); + String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey")))); + String zmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("zmkKey")))); + System.out.println("lmkKey:"+lmkKey); + System.out.println("zmkKey:"+zmkKey); + + //4.2将ZEK/ZAK从ZMK转为LMK加密(=) -> pass + RetWrap retWrap1 = api.tranZEAKFromZMKToLMK(0, key2, zmkKey); + System.out.println(retWrap1); + String lmkKey1 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey")))); + System.out.println("4.2将ZEK/ZAK从ZMK转为LMK加密,lmkKey1:"+lmkKey1); + + //4.3将ZEK/ZAK从LMK转为ZMK加密(=) -> pass + RetWrap retWrap2 = api.tranZEAKFromLMKToZMK(0, key2, lmkKey); + System.out.println(retWrap2); + String zmkKey1 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap2.get("zmkKey")))); + System.out.println("4.3将ZEK/ZAK从LMK转为ZMK加密,zmkKey1:"+zmkKey1);*/ + + /*//3.1生成一个ZPK(=) -> pass + RetWrap retWrap = api.genZPK(key2); + System.out.println(retWrap); + String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey")))); + String zmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("zmkKey")))); + System.out.println("lmkKey:"+lmkKey); + System.out.println("zmkKey:"+zmkKey); + //3.2将ZPK由ZMK转为LMK加密(=)-> pass + RetWrap retWrap1 = api.tranZPKFromZMKToLMK(key2, zmkKey); + System.out.println(retWrap1); + String zpkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("zpkKey")))); + System.out.println("3.2将ZPK由ZMK转为LMK加密,zpkKey:"+zpkKey); + //3.3将ZPK由LMK转为ZMK加密-> pass + RetWrap retWrap2 = api.tranZPKFromLMKToZMK(key2, lmkKey); + System.out.println(retWrap2); + String zpkKey1 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap2.get("zpkKey")))); + System.out.println("3.3将ZPK由LMK转为ZMK加密,zpkKey:"+zpkKey1);*/ + + /* //2.1生成并打印一个ZMK成份(=) -> : code = 23 ( 0x17 ) msg = 未定义的错误 + RetWrap retWrap = api.genZMKAndPrint(); + System.out.println(retWrap); + //2.3将ZMK由ZMK转为LMK加密(+) BY -> pass + RetWrap retWrap = api.changZMK2LMK( key2, key1); + System.out.println(retWrap); + String zmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("zmkKey")))); + System.out.println(zmkKey);*/ + + /*//1.4由2-9个密钥成份组成一个密钥(=) ->: code = 23 ( 0x17 ) msg = 未定义的错误 + String s1 = Util.bytes2HexString(key2.getBytes()); + String s2 = Util.bytes2HexString(key2.getBytes()); + RetWrap retWrap = api.composeKey(keyTye, new String[]{s1, s2}); + System.out.println(retWrap);*/ + /* //1.1生成一个对称密钥(*) -> pass + RetWrap retWrap = api.genSymKey(1,keyTye, 'X',key2); + System.out.println(retWrap); + String zmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("zmkKey")))); + System.out.println(zmkKey); + String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey")))); + System.out.println(lmkKey);*/ + /*//2.2生成并打印一个成份(=) ->: code = 23 ( 0x17 ) msg = 未定义的错误 + RetWrap retWrap = api.genAndPrint(keyTye, "X"); + System.out.println(retWrap);*/ + /*//1.3生成一个密钥并以分开的成份形式打印(=) -> : code = -2 ( 0xfffffffe ) msg = 接收数据超时 + RetWrap retWrap = api.genAndPrintSplit(keyTye, 'X'); + System.out.println(retWrap);*/ + /* //1.5输入一个密钥(*) -> pass + RetWrap retWrap1 = api.inputKey(keyTye, 'X', key1, zmkKey); + System.out.println(retWrap1); + String lmkKey1 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("key")))); + System.out.println(lmkKey1); + //1.6输出一个密钥(*)-> pass + RetWrap retWrap2 = api.outputKey(keyTye, 'X', key2, lmkKey); + System.out.println(retWrap2); + String zmkKey2 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap2.get("key")))); + System.out.println(zmkKey2); + //1.7转换密钥方案(+) ->PASS + RetWrap retWrap3 = api.conversionKey(keyTye, lmkKey, 'S'); + System.out.println(retWrap3); + String lmkkey3 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap3.get("lmkkey")))); + System.out.println(lmkkey3); + //1.8密钥合成(*,安徽农信) ->PASS + RetWrap retWrap4 = api.genComposeKey(keyTye, 'Z', key1); + System.out.println(retWrap4); + String lmkkey4= new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap4.get("lmkKey")))); + System.out.println(lmkkey4);*/ + + /*//8.1生成一个MAC(=) -> pass + RetWrap retWrap = api.genTAK(key2); + System.out.println(retWrap); + String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey")))); + System.out.println(lmkKey); + String tmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("tmkKey")))); + System.out.println(tmkKey); + String s = api.MACCalc(0, 0, lmkKey, 0, key1.getBytes(), 2); + System.out.println(s); + //8.2校验一个MAC(=) -> pass + api.MACCheck(0,0,lmkKey,0,key1.getBytes(),s);*/ + + /*// + RetWrap retWrap = api.SM2OrRSAGenKeyPair(1,"001",256); + System.out.println(Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"))); + //获取私钥 + String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")); + System.out.println("sk:"+sk); + //获取公钥 + String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey")); + System.out.println("pk:"+pk); + //15.1公钥加密指令(+) -> pass + byte[] bytes = api.encryptByPk(1, pk, "001".getBytes()); + System.out.println("公钥加密数据:"+Util.bytes2HexString(bytes)); + //15.2私钥解密指令(+) -> pass + byte[] data = api.decryptBySk(1, sk, bytes); + System.out.println(new String(data)); + + //15.3私钥加密指令(?) -> code = 13 ( 0xd ) msg = 未定义的错误(无返回加密数据) + byte[] bytes = api.encryptBySk(1, sk, key7.getBytes()); + System.out.println(bytes); + //15.4公钥解密指令(?) -> 等待15.3 + byte[] bytes1 = api.decryptByPk(1, pk, bytes); + System.out.println(new String(bytes1));*/ + + api.disconnect(); + } + + @Before + public void before() { + System.setProperty("com.sunyard.sydapi4j.debug", "true"); + api = (SydApi4j) new SydApi4j().connect("172.16.17.163", 8889, null, 1000); + } + + @After + public void after() { + try { + this.api.disconnect(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + //9.2 数据转加密指令(Y0)(=) -> pass 密文数据那项不一定需要传加密出来的数据 + @Test + public void switchEncryY() { + /* //生成DEK + RetWrap retWrap = api.genSymmetricKey("100", 'X'); + System.out.println(new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey"))))); + String DEK = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey")))); + + byte[] bytes = api.SYMEncryptDataCBC(1,DEK, "001".getBytes()); + System.out.println("加密:"+Util.bytes2HexString(bytes)); + + byte[] bytesx = api.SYMDecryptDataCBC(1, DEK, bytes); + System.out.println("解密:"+Util.bytes2HexString(bytesx));*/ + + //生成DEK + RetWrap retWrap1 = api.genSymmetricKey("000", 'X'); + System.out.println("sDEK:" + new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey"))))); + String sDEK = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey")))); + + RetWrap retWrap2 = api.genSymmetricKey("002", 'X'); + String dDEK = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap2.get("lmkKey")))); + System.out.println("dDEK:" + dDEK); + + byte[] bytes1 = api.switchEncryY("000", 1, "002", 1, 2, sDEK, dDEK, "0000000000123123".getBytes(), "9965432112345699"); + String cipherData = new String(Util.hexString2Bytes(Util.bytes2HexString(bytes1))); + System.out.println(cipherData); + } + + /* //10.1装载对称密钥至用户存储区(=) -> pass(需更换索引地址) + @Test + public void loadKey(){ + RetWrap retWrap1 = api.genSymmetricKey(keyTye, 'X'); + String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey")))); + String keyCheck = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("keyCheck")))); + System.out.println(lmkKey); + System.out.println(keyCheck); + Boolean loadKey = api.loadKey("999999999999999900000000007", lmkKey,keyCheck); + System.out.println(loadKey); + }*/ + + //10.2从用户存储区读取对称密钥(=) -> pass(秘钥校验值暂时无法获取) + @Test + public void readKey() { + RetWrap retWrap1 = api.readKey("999999999999999900000000003"); + System.out.println(retWrap1); + String key = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("key")))); + System.out.println(key); + } + + /*//10.3更新对称密钥至用户存储区(=) -> pass(需更换索引地址) + @Test + public void updateKey(){ + RetWrap retWrap1 = api.genSymmetricKey(keyTye, 'X'); + String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey")))); + String keyCheck = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("keyCheck")))); + System.out.println(lmkKey); + System.out.println(keyCheck); + Boolean updateKey = api.updateKey("999999999999999900000000012", lmkKey,keyCheck); + System.out.println(updateKey); + }*/ + + + //15.1公钥加密指令(+) -> pass + @Test + public void encryptByPk() { + RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "001", 256); + System.out.println(Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"))); + //获取私钥 + String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")); + System.out.println("sk:" + sk); + //获取公钥 + String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey")); + System.out.println("pk:" + pk); + + byte[] bytes = api.encryptByPk(1, pk, "001".getBytes()); + System.out.println("公钥加密数据:" + Util.bytes2HexString(bytes)); + } + + //15.2私钥解密指令(+) -> pass + @Test + public void decryptBySk() { + RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "001", 256); + System.out.println(Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"))); + //获取私钥 + String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")); + //获取公钥 + String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey")); + byte[] bytes = api.encryptByPk(1, pk, "001".getBytes()); + byte[] data = api.decryptBySk(1, sk, bytes); + System.out.println(new String(data)); + } + + /* //15.3私钥加密指令(?) -> code = 13 ( 0xd ) msg = 未定义的错误(无返回加密数据) + @Test + public void encryptBySk(){ + RetWrap retWrap = api.SM2OrRSAGenKeyPair(1,"001",256); + System.out.println(Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"))); + //获取私钥 + String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")); + //获取公钥 + String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey")); + byte[] bytes = api.encryptBySk(0, sk, "001".getBytes()); + System.out.println(bytes); + byte[] bytes1 = api.decryptByPk(0, pk, bytes); + System.out.println(new String(bytes1)); + } +*/ + + /* //15.5 RSA私钥签名(+) -> + @Test + public void RSASignC(){ + RetWrap retWrap1 = api.conutHash(1,0, key2.getBytes(), key1.getBytes()); + byte[] bytes = api.RSASignC("0000000000000005", 1, 0,(byte[]) retWrap1.get("hash")); + System.out.println(bytes); + }*/ + + + /* //15.6 RSA验证签名(+) + @Test + public void RSAVerify(){ + RetWrap retWrap = api.SM2OrRSAGenKeyPair(0,"0000000000000005",1024); + //15.7计算HASH散列值(MD5\SHA1\SHA256)(+) -> pass + RetWrap retWrap1 = api.conutHash(1,0, key2.getBytes(), key1.getBytes()); + String hash = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("hash")))); + System.out.println(hash); + System.out.println(retWrap1); + //15.5 RSA私钥签名(+) + byte[] bytes = api.RSASignC("0000000000000005", 1, 0,(byte[]) retWrap1.get("hash")); + System.out.println(bytes); + boolean hash1 = api.RSAVerify(1, 0, (byte[]) retWrap.get("PublicKey"), (byte[]) retWrap1.get("hash"), bytes); + System.out.println(hash1); + } +*/ + + //15.7计算HASH散列值(MD5\SHA1\SHA256)(+) -> pass + @Test + public void RSASignC() { + RetWrap retWrap1 = api.conutHash(1, 0, key2.getBytes(), key1.getBytes()); + System.out.println(retWrap1); + } + + //16.1 RSA、SM2非对称密钥产生(*) ->pass + @Test + public void SM2GenSessionKey() { + RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "", 256); + //RetWrap retWrap = api.SM2GenKeyPair(); + String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey")); + System.out.println(pk); + String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")); + System.out.println(sk); + } + + //16.2产生随机密钥,由公钥加密并且以LMK加密输出(+) ->pass + @Test + public void SM2OrRSAGenKeyPair() { + RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "006", 256); + String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey")); + String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")); + System.out.println(pk); + System.out.println(sk); + RetWrap retWrap1 = api.SM2GenSessionKey(pk); + System.out.println(retWrap1); + } + + //16.3由私钥解密随机密钥并以LMK加密输出(+) -> pass + @Test + public void SM2ConfirmSessionKey() { + RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "006", 256); + String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey")); + String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")); + System.out.println(pk); + System.out.println(sk); + //16.2产生随机密钥,由公钥加密并且以LMK加密输出(+) ->pass + RetWrap retWrap1 = api.SM2GenSessionKey(pk); + System.out.println(retWrap1); + String CipherKey = retWrap1.get(SydApi.RET_CIPHER_KEY).toString(); + + RetWrap retWrap2 = api.SM2ConfirmSessionKey(sk, CipherKey); + System.out.println(retWrap2); + + byte[] bytes = api.SM3Hash(pk, "0001".getBytes()); + System.out.println(Util.bytes2HexString(bytes)); + } + + //16.5 SM2私钥签名(+) ->pass + @Test + public void SYD_SM2_Sign_HA() { + RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "006", 256); + String s = api.SYD_SM2_Sign_HA(1, (byte[]) retWrap.get("PrivateKey"), (byte[]) retWrap.get("PublicKey"), key7.getBytes()); + System.out.println(s); + } + + //16.6 SM2公钥验签(+)->pass (仅签名数据类型为原数据通过) + @Test + public void SYD_SM2_Verify_HA() { + RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "006", 256); + String s = api.SYD_SM2_Sign_HA(1, (byte[]) retWrap.get("PrivateKey"), (byte[]) retWrap.get("PublicKey"), key7.getBytes()); + System.out.println(s); + boolean b = api.SYD_SM2_Verify_HA(1, (byte[]) retWrap.get("PublicKey"), key7.getBytes(), s); + System.out.println(b); + } + + //16.7 LMK加密密钥转公钥加密输出 ->pass + @Test + public void LMK2SM2() { + RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "006", 256); + String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey")); + RetWrap retWrap2 = api.LMK2SM2(Util.hexString2Bytes(pk), key2); + System.out.println(retWrap2); + } + + /* //16.8 ECC密钥生成 -> code = 129 ( 0x81 ) msg = 未定义的错误, 服务器代码问题 + @Test + public void genKeyPair(){ + RetWrap retWrap2 = api.genKeyPair(0415, 1234); + System.out.println(retWrap2); + }*/ + + /* //17.8 获取传输保护密钥(+) -> code = 18 ( 0x12 ) msg = 未定义的错误 + @Test + public void getTransmissionKey(){ + RetWrap transmissionKey = api.getTransmissionKey(); + System.out.println(transmissionKey); + }*/ + + /* //17.9 角色认证(+) -> : code = 2 ( 0x2 ) msg = 签名验证错误 + @Test + public void roleVerify(){ + RetWrap retWrap = api.roleVerify("0000000000000012"); + System.out.println(retWrap); + }*/ + + //17.10 获取随机数(=) -> PASS + @Test + public void GenerateRandom() { + String s = api.GenerateRandom(012); + System.out.println(s); + } + + //17.11 获取应用密钥明文(+) -> PASS + @Test + public void getPlainText() { + RetWrap retWrap = api.genSymmetricKey("002", 'X'); + System.out.println(retWrap); + String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey")))); + RetWrap plainText = api.getPlainText(lmkKey, 0); + System.out.println(plainText); + } + + //18.1加押指令(+) -> pass + @Test + public void impose() { + RetWrap retWrap = api.impose(keyTye, key2, "000".getBytes()); + System.out.println(retWrap); + } + + //18.2核押指令(+) -> pass + @Test + public void verifyImpose() { + //获取密押 + RetWrap impose = api.impose(keyTye, key2, "000".getBytes()); + //byte[] secret = Util.hexString2Bytes(Util.bytes2HexString((byte[]) impose.get("MAC"))); + System.out.println(impose); + Boolean verifyImpose = api.verifyImpose(keyTye, key2, impose.get("MAC").toString().getBytes(), "000".getBytes()); + System.out.println(verifyImpose); + } + + //18.3加解密指令(+) -> pass + @Test + public void encryAndDecry() { + RetWrap impose = api.impose(keyTye, key2, "000".getBytes()); + RetWrap retWrap = api.encryAndDecry(keyTye, key2, impose.get("MAC").toString().getBytes()); + System.out.println(retWrap.get("info").toString()); + } + + //18.4转加密指令(+) -> pass + @Test + public void switchEncry() { + RetWrap impose = api.impose(keyTye, key2, "000".getBytes()); + RetWrap retWrap = api.switchEncry(keyTye, key2, key4, impose.get("MAC").toString().getBytes()); + System.out.println(retWrap); + + String info = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("info")))); + System.out.println(Util.bytes2HexString((byte[]) retWrap.get("info"))); + } + + //18.5 PIN加解密指令(+) -> pass + @Test + public void encryAndDecry4PIN() { + String s1 = api.encryPIN(0, "06123456FFFFFFFF", "123456789123"); + System.out.println(s1); + System.out.println(Util.hexString2Bytes(s1)); + byte[] bytes = api.encryAndDecry4PIN(key2, Util.hexString2Bytes(s1)); + System.out.println(bytes); + String s = Util.bytes2HexString(bytes); + System.out.println(s); + } + + //18.6 PIN转加密指令(+) -> pass + @Test + public void switchEncry4PIN() { + String s1 = api.encryPIN(0, "06123456FFFFFFFF", "123456789123"); + System.out.println(s1); + System.out.println(Util.hexString2Bytes(s1)); + byte[] bytes = api.switchEncry4PIN(key2, key4, Util.hexString2Bytes(s1)); + System.out.println(bytes); + } + + + /* // 19.1解密数据并由公钥加密输出 ->: code = 19 ( 0x13 ) msg = 数据解密错(C3) + @Test + public void decryptAndEncryptByP(){ + //生成公钥 + //RetWrap retWrap = api.SM2OrRSAGenKeyPair(0,"001",256); + RetWrap retWrap = api.SM2GenKeyPair(); + String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey")); + System.out.println(pk); + //生成DEK + RetWrap retWrap1 = api.genSymmetricKey("100", 'X'); + System.out.println(new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey"))))); + String DEK = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey")))); + + byte[] bytes = api.SYMEncryptDataCBC(1,DEK, "001".getBytes()); + System.out.println("加密:"+Util.bytes2HexString(bytes)); + + byte[] bytesx = api.SYMDecryptDataCBC(1, DEK, bytes); + System.out.println("解密:"+Util.bytes2HexString(bytesx)); + + retWrap = api.decryptAndEncryptByP(DEK,bytes, 1, (byte[]) retWrap.get("PublicKey")); + System.out.println(retWrap); + }*/ + + /* //19.2由私钥解密密文数据并经过DEK加密后输出 ->code = 21 ( 0x15 ) msg = 输入的数据格式错误 + @Test + public void decryptAndEncryptByS(){ + RetWrap retWrap = api.SM2OrRSAGenKeyPair(1,"001",256); + System.out.println(Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"))); + //获取私钥 + String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")); + System.out.println("sk:"+sk); + //获取公钥 + String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey")); + System.out.println("pk:"+pk); + //公钥加密 + byte[] bytes = api.encryptByPk(1, pk, "001".getBytes()); + System.out.println("公钥加密数据:"+Util.bytes2HexString(bytes)); + //私钥解密 + byte[] data = api.decryptBySk(1, sk, bytes); + System.out.println(new String(data)); + RetWrap retWrap1 = api.genSymmetricKey("0D0", 'X'); + String s = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey")))); + RetWrap retWrap2 = api.decryptAndEncryptByS(s,bytes,sk); + System.out.println(retWrap2); + }*/ + + + /*//20.1生成数字信封 -> : code = 33 ( 0x21 ) msg = 检索的数据或密钥不存在 + @Test + public void generateDE(){ + RetWrap retWrap = api.generateDE("1004282452", (byte) 0x31); + System.out.println(retWrap); + }*/ + + /*//24.1获取加密机cpu,内存,磁盘使用状况 HI ->: code = -2 ( 0xfffffffe ) msg = 接收数据超时 + @Test + public void getStatus(){ + RetWrap retWrap = api.getStatus(); + System.out.println(retWrap); + }*/ + + //24.2获取加密机设备信息 -> pass + @Test + public void getVersion() { + RetWrap version = api.getVersion("1234"); + System.out.println(version); + } + + + @Test + public void directBytes() { + String s = "00DF00000000000000023738313939393939393939393939393939393939393939393939393939393030363800010000339C7BFC0EA0E75D8165F1539889D9932AD64F6117FA66649850D6E331CB797A000000000000000000000000000000000000000000000000000000000000000030313039306B02204A99C4E0B610AE7452277896A22E1D551E45F9FF9CAF3241497AF3C85AA7CCB002206E15B65AE8F16A1990BCD51FC29235943A92D17C36F493BE7E3D694CC46B1E830420CD099F4BC3B8E1FD475134183E16E2CDF65F8615760BE94CB72738545399B48104039C1D29"; + byte[] bytes1 = Util.hexString2Bytes(s); + byte[] bytes = api.directBytes(bytes1); + String s1 = Util.bytes2HexString(bytes); + System.out.println(s1); + } + +} + + + diff --git a/src/test/java/com/sunyard/sydapi/test/TestMixKey.java b/src/test/java/com/sunyard/sydapi/test/TestMixKey.java new file mode 100644 index 0000000..04b0598 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestMixKey.java @@ -0,0 +1,59 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +public class TestMixKey { + + + public static void main(String[] args) { + + SydApi sydApi = (new SydApi4j()).connect("172.16.17.163", 8889,null , 10000); + String pk = "0342000417CCD26D6DD2D1A4022C2A94DCF6CE07229C153DA9729D45274F5C6BF6BB9CF5B9C1FA3B2C7113C54C7873470D01B174501498BC5640A164F883E9C4A6844FCF"; + String sk = "00010000160C81E621BBCC2348FABAF7C812F2D2E014C75C5F94820E7DD52A23C59759A90000000000000000000000000000000000000000000000000000000000000000"; + + + String id = "012345678901234567890123456789"; + + String enData = sydApi.SM2Encrypt( + Util.hexString2Bytes(pk), + (id + "123456").getBytes() + ); + + System.out.println( enData ); + +// sydApi.SM2DecryptC() + + + +// RetWrap ret = sydApi.genKeyEx( pk , "000000"); +// +// // key 258 +// System.out.println( ret ); +// +// +// ret = sydApi.deKeyEx( sk , ret.get("key").toString() , "S"); +// +// +// System.out.println( ret ); +// +// String lmk = ret.get("lmk").toString(); +// +// ret = sydApi.mixKey( lmk, lmk , "S" ); +// +// +// System.out.println( ret ); +// +// +// // lmk -> pken +// String ek = sydApi.enKeyPk( pk , lmk ); +// System.out.println( ek ); +// +// ret = sydApi.deKeyEx( sk , ek , "S"); +// System.out.println( ret ); + } + + +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestPJS.java b/src/test/java/com/sunyard/sydapi/test/TestPJS.java new file mode 100644 index 0000000..b6aaf18 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestPJS.java @@ -0,0 +1,36 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +public class TestPJS { + + public static void main(String[] args) { + + String ip = "172.16.18.72"; //"172.16.18.72"; //"172.16.17.162"; + byte[] pInData = Util.hexString2Bytes("4649F0894D0905D8F7DA4E5D8B9CE3BA"); + String seesionKey = "S203AE74FEE98FE440E232B9EDCF0EA61"; + + + + SydApi sydApi = (new SydApi4j()).connect(ip, 8889,null , 10000); + byte[] ret = sydApi.SYMDecryptDataCBC(0x01, seesionKey, pInData ); + + System.out.println( new String(ret) ); + + +// SydApi sydApi = (new SydApi4j()).connect(ip, 8889,null , 10000); +// byte[] ret = sydApi.SYMEncryptDataCBC(0x01, seesionKey, pInData, Util.bytes2HexString("SHANGPIAOJIAOSUO".getBytes()).getBytes()); +// +// +// System.out.println( Util.bytes2HexString(ret) ); +// +// +// ret = sydApi.SYMDecryptDataCBC(0x01, seesionKey, ret, Util.bytes2HexString("TEST-PIAOJIAOSUO".getBytes()).getBytes()); +// +// System.out.println( Util.bytes2HexString(ret) ); + + } + +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestPKCS1.java b/src/test/java/com/sunyard/sydapi/test/TestPKCS1.java new file mode 100644 index 0000000..e3d6cf2 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestPKCS1.java @@ -0,0 +1,45 @@ +package com.sunyard.sydapi.test; + + +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + + +public class TestPKCS1 { + + private static final String testData = "1015570000408702018091900000000012018-09-19T10:13:391015570000408702015970000397542018-09-1900000001123456,测试"; + private static final String testCertNo = "C=CN,O=Sunyard,OU=8001,CN=8001"; + + + public static void main(String[] args) { + + // 连接加密机 + SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.17.162", 8889, null, 1000); + + + try { + + // 原始数据模式 + case1(api); + + + } catch (Exception e) { + e.printStackTrace(); + } finally { + api.disconnect(); + } + } + + public static void case1(SydApi api) { + // 签名验签 1 + System.out.println("\n\n----- 裸签名 -----"); + byte[] sign = api.SYD_NakedSign(testData.getBytes(), testCertNo); + System.out.println("签名结果 " + Util.bytes2HexString(sign) ); + + + boolean pass = api.SYD_NakedVerify(testData.getBytes(), sign, testCertNo); + System.out.println("验签结果 " + pass); + } + +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestPKCS7.java b/src/test/java/com/sunyard/sydapi/test/TestPKCS7.java new file mode 100644 index 0000000..545c8f1 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestPKCS7.java @@ -0,0 +1,121 @@ +package com.sunyard.sydapi.test; + + +import com.sunyard.SydApi; +import racal.sunyard.main.SydApi4j; + + +public class TestPKCS7 { + + private static final String testData = "1015570000408702018091900000000012018-09-19T10:13:391015570000408702015970000397542018-09-1900000001123456,测试"; + private static final String testPubKey = "034200043EDA3A107B7CC35CC005C7FBF0BB4E6B43A07EE14E360603D22ECA2A600B2D0FA03055D400D1240300F54648B849D13F50B330FF14351B5645B13686820A65BB"; + private static final String testCertNo = "C=CN,O=Sunyard,OU=8001,CN=8001"; + + public static void main(String[] args) { + + // 连接加密机 + // SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.17.162", 8889, null, 1000); + SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.18.69", 8889, 1000); + SydApi4j api = (SydApi4j) new SydApi4j(); + + try { + + // 基础接口 原始数据模式 + case1( api ); +/* + // 基础接口 HASH 数据模式 + case2( api ); + + // 原始数据模式专用接口 + case3( api ); + + // HASH 模式专用接口 + case4( api );*/ + + + } catch (Exception e) { + e.printStackTrace(); + } finally { + api.disconnect(); + } + } + + public static void case1(SydApi api) { + System.out.println("\n\n----- PKCS7 签名验签 基础接口原始数据模式 -----"); + String sign = api.detachedSign( + SydApi.DATA_ORIGIN, + testData.getBytes(), + testCertNo + ); + + System.out.println("\t签名结果: " + sign); + + boolean verify = api.detachedVerify( + SydApi.DATA_ORIGIN, + testData.getBytes(), + sign + ); + + System.out.println("\t验签结果: " + verify); + } + + public static void case2(SydApi api) { + System.out.println("\n\n----- PKCS7 签名验签 基础接口 hash 数据模式 -----"); + byte[] hash = api.SM3Hash(testPubKey, testData.getBytes()); + + String sign = api.detachedSign( + SydApi.DATA_HASH, + hash, + TestPKCS7.testCertNo + ); + + System.out.println("\t签名结果: " + sign); + + boolean verify = api.detachedVerify( + SydApi.DATA_HASH, + hash, + sign + ); + + System.out.println("\t验签结果: " + verify); + } + + public static void case3(SydApi api) { + System.out.println("\n\n----- PKCS7 签名验签 原始数据模式 -----"); + + String sign = api.SYD_DetachedSign( + testData.getBytes(), + testCertNo + ); + + System.out.println("\t签名结果: " + sign); + + boolean verify = api.SYD_DetachedVerify( + testData.getBytes(), + sign + ); + + System.out.println("\t验签结果: " + verify); + } + + public static void case4(SydApi api) { + System.out.println("\n\n----- PKCS7 签名验签 hash 数据模式 -----"); + + String sign = api.sm3AndDetachedSign( + testData.getBytes(), + testPubKey, + TestPKCS7.testCertNo + ); + + System.out.println("\t签名结果: " + sign); + + boolean verify = api.sm3AndDetachedVerify( + testData.getBytes(), + testPubKey, + sign + ); + + System.out.println("\t验签结果: " + verify); + } + +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestPool.java b/src/test/java/com/sunyard/sydapi/test/TestPool.java new file mode 100644 index 0000000..8f18db7 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestPool.java @@ -0,0 +1,300 @@ +package com.sunyard.sydapi.test; + + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.proto.Util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.Arrays; + +/** + * SydApi 测试程序! + * 调用方法参考如下,加密机需要相应的设置。 + */ +public class TestPool { + + public static void write(String file, String content) { + write(file, content.getBytes()); + } + + public static void write(String file, byte[] content) { + try { + File f = new File(file); + if (!f.exists()) { + f.createNewFile(); + } + FileOutputStream fos = new FileOutputStream(f); + fos.write(content); + } catch (Exception e) { + System.out.println("写入文件 " + file + " 异常"); + } + } + + public static String read(String file) { + try { + File f = new File(file); + if (!f.exists()) { + return null; + } + FileInputStream fis = new FileInputStream(f); + byte[] buff = new byte[5024]; + int len = fis.read(buff); + return new String(buff, 0, len); + } catch (Exception e) { + return null; + } + } + + public static void main(String[] args) { + + int total = 1; + try { + total = Integer.valueOf(args[0]); + } catch (Exception e) { + } + doit(total); + } + + + public static void doit(int total) { + System.out.println("SydApi 测试程序启动"); + + final String testSN1 = "1004282451"; + final String testSN2 = "1004282452"; + final String testPubKey = "0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"; + final String testPubKey1 = "034200040B2FCF5E2B15D341FC12A9B6A88631D83A7B79DC6BABF9E49FFF624BD148E2FA44A9F1B7F1E36E39B22AA6BD79B7EA527DB912617148A62CB94760CB80EE3A68"; + + final String testUser = "8012"; + byte[] testData = new byte[100]; + Arrays.fill(testData, (byte) 0x88); + testData[testData.length - 3] = (byte) 0xFF; + testData[testData.length - 2] = (byte) 0xFF; + testData[testData.length - 1] = (byte) 0xFF; + + + System.out.println("\n\n----- connect -----"); + SydApi sydApi = null; + +// +// // 建议从配置文件读取配置 +// // 单服务器测试使用 +// PoolManager.INSTANCE.createPool("default", "{\n" + +// " \"mode\" : \"solo\", // (必填)\n" + +// " \"oipc\" : \"com.sunyard.pool4sydapi.SydApiInPool\", " + +// " \"ip\" : \"172.16.18.69\", // (必填)\n" + +// " \"port\": 8889, // (必填)【数字】\n" + +// " \"pwd\": \"\", // 没有就不填写此项\n" + +// " \"timeout\": 1000 //【数字】不限超时时间就不填写此项\n" + +// "}"); + + +// // 推荐配置 +// PoolManager.INSTANCE.createPool("default", "{\n" + +// " \"mode\" : \"round-robin\", // (必填)\n" + +// " \"oipc\" : \"com.sunyard.pool4sydapi.SydApiInPool\", // (必填)\n" + +// " \"ips\" : [ // (必填)\n" + +// " \"172.16.18.69\",\n" + +// " \"172.16.18.70\"\n" + +// " ],\n" + +// " \"port\": 8889, //(必填)【数字】\n" + +// " \"pwd\": \"\", //【数字】没有就不填写此项\n" + +// " \"timeout\": 1000 , //【数字】【数字】链接和响应超时时限,不限超时时间就不填写此项\n" + +// " \"connectTimeout\" : 1000, //【数字】【数字】链接超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" + +// " \"waitRecvTimeout\" : 1000, //【数字】【数字】响应超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" + +// " \"maxContinuousErrorTime\" : 3, //【数字】 单台加密机连续出错次数\n" + +// " \"recoveryTime\" : 300000, //【数字】 恢复时间,单位毫秒,默认 5 分钟,最大 2^63\n" + +// " \"keepAlive\" : 1, //【数字】 保持链接个数,默认是链接池个数的一半\n" + +// " \"maxAliveTime\" : 300000000, //【数字】 最大生存时间\n" + +// " \"maxIdleTime\" : 300000 , //【数字】 最大空闲时间,默认 5 分钟,最大 2^63\n" + +// " \"checkMode\" : \"before/after/deamon\", // 链接检测模式,使用前/使用后/后台轮询\n" + +// " \"checkGap\" : 300000 // 后台轮询检测间隔\n" + +// "}"); + + +// // 自定义配置 +// PoolManager.INSTANCE.createPool("default", "{\n" + +// " \"mode\" : \"weighted-round-robin\", // (必填)\n" + +// " \"oipc\" : \"com.sunyard.pool4sydapi.SydApiInPool\", // (必填)\n" + +// " \"ips\" : { // (必填)\n" + +// " \"172.16.18.69\" : 1,\n" + +// " \"172.16.18.70\" : 3\n" + +// " },\n" + +// " \"port\": 8889, //(必填)【数字】\n" + +// " \"pwd\": \"\", //【数字】没有就不填写此项\n" + +// " \"timeout\": 1000 , //【数字】【数字】链接和响应超时时限,不限超时时间就不填写此项\n" + +// " \"connectTimeout\" : 1000, //【数字】【数字】链接超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" + +// " \"waitRecvTimeout\" : 1000, //【数字】【数字】响应超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" + +// " \"maxContinuousErrorTime\" : 3, //【数字】 单台加密机连续出错次数\n" + +// " \"recoveryTime\" : 300000, //【数字】 恢复时间,单位毫秒,默认 5 分钟,最大 2^63\n" + +// " \"keepAlive\" : 1, //【数字】 保持链接个数,默认是链接池个数的一半\n" + +// " \"maxAliveTime\" : 300000000, //【数字】 最大生存时间\n" + +// " \"maxIdleTime\" : 300000 , //【数字】 最大空闲时间,默认 5 分钟,最大 2^63\n" + +// " \"checkMode\" : \"before/after/deamon\", // 链接检测模式,使用前/使用后/后台轮询\n" + +// " \"checkGap\" : 300000 // 后台轮询检测间隔\n" + +// "}"); +// +// +// long bt = 0; +// long et = 0; +// +// try { +// +// String data = "10002018-03-05T09:53:290001046392001240003707001110000103050953290000432018-03-05WKA0023WKA0023卡号不合法或不存在2018-03-05T09:54:4904639200W0ACQ001W0ACQ001"; +// +// System.out.println("\n\n----- SM2 算法签名 (原始数据) -----"); +// byte[] hash = sydApi.SM3Hash( +// null, +// data.getBytes() +// ); +// +// String sign = sydApi.SM2SignC( +// "1234", +// "1234567812345678", +// SydApi.DATA_ORIGIN, +// Util.hexString2Bytes(testPubKey), +// hash +// ); +// System.out.print("\n\n----- SM2 算法签名 结果: "); +// System.out.println(sign); +// +// +// System.out.println("\n\n----- SM2 算法验签 (原始数据) -----"); +// +// boolean SM2VerifyRet = sydApi.SM2Verify( +// "1234567812345678", +// SydApi.DATA_ORIGIN, +// Util.hexString2Bytes(testPubKey), hash, sign); +// if (SM2VerifyRet) { +// System.out.println("验签通过"); +// } else { +// System.err.println("验签失败"); +// throw new RuntimeException("验签失败"); +// } +// +// System.out.println("\n\n----- SM3 hash -----"); +// bt = System.currentTimeMillis(); +// byte[] sm3 = null; +// for (int i = 0; i < total; i++) { +// sm3 = sydApi.SM3Hash( +// testPubKey, +// testData +// ); +// } +// et = System.currentTimeMillis(); +// System.out.print("\n\n----- SM3 hash 时间: "); +// System.out.println(et - bt); +// +// System.out.print("Hash : "); +// write("./Hash.bin", sm3); +// System.out.println(Util.bytes2HexString(hash)); +// System.out.print("\n\n\n\n\n"); +// +// +// System.out.print("\n\n----- SM2 算法签名 Customized"); +// bt = System.currentTimeMillis(); +// String sm2sign = null; +// for (int i = 0; i < total; i++) { +// sm2sign = sydApi.SM2SignCustomized( +// "1004282451", +// testData +// ); +// } +// et = System.currentTimeMillis(); +// System.out.print("\n\n----- SM2 算法签名 结果: "); +// System.out.println(sm2sign); +// System.out.print("\n\n----- SM2 算法签名 时间: "); +// System.out.println(et - bt); +// System.out.print("\n\n\n\n\n"); +// +// +// System.out.println("\n\n----- SM2 算法验签 Customized -----"); +// bt = System.currentTimeMillis(); +// boolean SM2VerifyCustomizedRet = false; +// for (int i = 0; i < total; i++) { +// SM2VerifyCustomizedRet = sydApi.SM2VerifyCustomized( +// "1004282451", +// testData, +// sm2sign); +// if (SM2VerifyCustomizedRet) { +// System.out.println("验签通过"); +// } else { +// System.err.println("验签失败"); +// throw new RuntimeException("验签失败"); +// } +// } +// et = System.currentTimeMillis(); +// System.out.print("\n\n----- SM2 算法验签 时间: "); +// System.out.println(et - bt); +// System.out.print("\n\n\n\n\n"); +// +// +// System.out.println("\n\n----- SM2 公钥加密数据 -----"); +// bt = System.currentTimeMillis(); +// String enData = null; +// for (int i = 0; i < total; i++) { +// enData = sydApi.SM2Encrypt( +// Util.hexString2Bytes(testPubKey1), +// testData +// ); +// } +// et = System.currentTimeMillis(); +// System.out.print("\n\n----- SM2 公钥加密时间 "); +// System.out.println(et - bt); +// System.out.println(enData); +// System.out.print("\n\n\n\n\n"); +// +// +// System.out.println("\n\n----- SM2 私钥解密数据 -----"); +// bt = System.currentTimeMillis(); +// byte[] odata = null; +// for (int i = 0; i < total; i++) { +// odata = sydApi.SM2DecryptC( +// testUser, +// enData +// ); +// } +// et = System.currentTimeMillis(); +// System.out.print("\n\n----- SM2 私钥解密数据 时间"); +// System.out.println(et - bt); +// System.out.println(Util.bytes2HexString(odata)); +// System.out.print("\n\n\n\n\n"); +// +// +// System.out.println("\n\n----- 生成密钥对 -----"); +// RetWrap key = null; +// bt = System.currentTimeMillis(); +// for (int i = 0; i < total; i++) { +// key = sydApi.SM2GenKeyPair(); +// } +// et = System.currentTimeMillis(); +// System.out.print("\n\n----- 生成密钥对 时间: "); +// System.out.println(et - bt); +// System.out.print("Public Key : "); +// write("./PubKey.bin", (byte[]) key.get(SydApi.RET_PUBLIC_KEY)); +// System.out.println(Util.bytes2HexString((byte[]) key.get(SydApi.RET_PUBLIC_KEY))); +// System.out.print("Private Key : "); +// write("./PriKey.bin", (byte[]) key.get(SydApi.RET_PRIVATE_KEY)); +// System.out.println(Util.bytes2HexString((byte[]) key.get(SydApi.RET_PRIVATE_KEY))); +// System.out.print("\n\n\n\n\n"); +// +// +// System.out.println("\n\n----- 获取公钥 () -----"); +// String pk = sydApi.SM2GetPublicKeyC("1234", 0); +// write("./PubKey.bin", pk); +// System.out.print("\r\n公钥 : "); +// System.out.println(pk); +// +// +// } finally { +// System.out.println("\n\n----- disconnect -----"); +// sydApi.disconnect(); +// } + + + System.out.println("执行结束\n\n"); + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestQNUCApi.java b/src/test/java/com/sunyard/sydapi/test/TestQNUCApi.java new file mode 100644 index 0000000..a6addd2 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestQNUCApi.java @@ -0,0 +1,164 @@ +package com.sunyard.sydapi.test; + + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + +/** + * SydApi 网联相关接口 + * 调用方法参考如下,加密机需要相应的设置。 + */ +public class TestQNUCApi { + + public static void write(String file, String content) { + write(file, content.getBytes()); + } + + public static void write(String file, byte[] content) { + try { + File f = new File(file); + if (!f.exists()) { + f.createNewFile(); + } + FileOutputStream fos = new FileOutputStream(f); + fos.write(content); + } catch (Exception e) { + System.out.println("写入文件 " + file + " 异常"); + } + } + + public static String read(String file) { + try { + File f = new File(file); + if (!f.exists()) { + return null; + } + FileInputStream fis = new FileInputStream(f); + byte[] buff = new byte[5024]; + int len = fis.read(buff); + return new String(buff, 0, len); + } catch (Exception e) { + return null; + } + } + + public static void main(String[] args) { + + // 连接加密机 + SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.18.226", 8889, null, 1000); + + final String testSN1 = "1004282451"; + final String testSN2 = "1004282452"; + final String testPubKey = "0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"; + final String testPubKey1 = "034200040B2FCF5E2B15D341FC12A9B6A88631D83A7B79DC6BABF9E49FFF624BD148E2FA44A9F1B7F1E36E39B22AA6BD79B7EA527DB912617148A62CB94760CB80EE3A68"; + byte[] testData = new byte[100]; + Arrays.fill(testData, (byte) 0x88); + testData[testData.length - 3] = (byte) 0xFF; + testData[testData.length - 2] = (byte) 0xFF; + testData[testData.length - 1] = (byte) 0xFF; + final String testUser = "8012"; + + + try { + System.out.println("\n\n----- 用指定的证书私钥对指定的数据进行数字签名。 -----"); + String signPri = api.netSign(testSN1, testData); + System.out.print("sign : "); + System.out.println(signPri); + + write("./Sign.b64", signPri); + + + System.out.println("\n\n----- 用指定证书对指定的原始数据进行数字签名验证。 -----"); + signPri = read("./Sign.b64"); + if (api.netVerify(testSN1, testData, signPri)) { + System.out.println("验证通过"); + } else { + System.out.println("验证失败"); + } + + + System.out.println("\n\n----- 通过证书的 DN,获取证书的序号。 -----"); + String sn = null; + try { + sn = api.getX509SN(SydApi.ALG_AES, "C=CN,O=Sunyard,OU=8001,CN=8001".getBytes("GBK")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + System.out.print("sn : "); + System.out.println(sn); + + + System.out.println("\n\n----- 生成数字信封 -----"); + RetWrap wrapNum = api.generateDE(testSN2, SydApi.ALG_SM4); + System.out.print("Session Key : "); + System.out.println(wrapNum.get(SydApi.RET_SESSION_KEY)); + System.out.print("Cipher Key : "); + System.out.println(wrapNum.get(SydApi.RET_CIPHER_KEY)); + System.out.print("KCV: "); + System.out.println(wrapNum.get(SydApi.RET_KCV)); + + + write("./CipherKey.b64", (String) wrapNum.get(SydApi.RET_CIPHER_KEY)); + write("./SessionKey.bin", (String) wrapNum.get(SydApi.RET_SESSION_KEY)); + + + System.out.println("\n\n----- 解密数字信封 -----"); + String cipherKey = read("./CipherKey.b64"); + System.out.print("Cipher Key : "); + System.out.println(cipherKey); + + + RetWrap wrap = api.decryptDE(testSN2, cipherKey); + System.out.print("Session Key : "); + System.out.println(wrap.get(SydApi.RET_SESSION_KEY)); + + System.out.print("KCV : "); + System.out.println(wrap.get(SydApi.RET_KCV)); + + + System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 -----"); + String sessionKey = read("./SessionKey.bin"); + byte[] enSm4Data = api.SYMEncryptData(SydApi.NALG_SM4, sessionKey, testData); + System.out.print("密文 : "); + System.out.println(Util.bytes2HexString(enSm4Data)); + write("./EnData.bin", enSm4Data); + + + System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 -----"); + byte[] deSM4Data = api.SYMDecryptData(SydApi.NALG_SM4, sessionKey, enSm4Data); + System.out.print("解密 : "); + System.out.println(Util.bytes2HexString(deSM4Data)); + write("./DeData.bin", enSm4Data); + + + System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 CBC -----"); + String sessionKeyCBC = read("./SessionKey.bin"); + byte[] enDataCBC = api.SYMEncryptDataCBC(SydApi.NALG_SM4, sessionKeyCBC, testData); + System.out.print("密文 : "); + System.out.println(Util.bytes2HexString(enDataCBC)); + write("./EnData.bin", enDataCBC); + + + System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 CBC -----"); + byte[] deDataCBC = api.SYMDecryptDataCBC(SydApi.NALG_SM4, sessionKeyCBC, enDataCBC); + System.out.print("解密 : "); + System.out.println(Util.bytes2HexString(deDataCBC)); + write("./DeData.bin", deDataCBC); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + api.disconnect(); + } + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestReflection.java b/src/test/java/com/sunyard/sydapi/test/TestReflection.java new file mode 100644 index 0000000..77f5823 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestReflection.java @@ -0,0 +1,11 @@ +package com.sunyard.sydapi.test; + +import java.lang.reflect.Method; + +public class TestReflection { + public static void main(String[] args) throws Exception { + Class clazz = Class.forName("com.sunyard." + "Util"); + Method method = clazz.getMethod("hello",String.class); + method.invoke(clazz.newInstance(),"123"); + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestSDNXApi.java b/src/test/java/com/sunyard/sydapi/test/TestSDNXApi.java new file mode 100644 index 0000000..8ea2dee --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestSDNXApi.java @@ -0,0 +1,162 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.SydApi; +import com.sunyard.cert.X509; +import com.sunyard.inf.customize.SydSDNXApiImpl; +import racal.sunyard.main.SydApi4j; + +public class TestSDNXApi { + + private static final String testCertNo = "C=cn,O=CFCA TEST CA,OU=NCS2,OU=Enterprises,CN=041@Z402451000010@ShanDong@00000001"; + //private static final String testCertNo = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1"; + //private static final String testCertNo = "C=CN,O=Sunyard,OU=8001,CN=8001"; + //private static final String testData = "1015570000408702018091900000000012018-09-19T10:13:391015570000408702015970000397542018-09-1900000001123456,测试"; + private static final String testData = "0000000000000002019022310000129102019-02-23T09:29:19CC00"; + private static final String testUser = "201597"; + //private static final String testUser = "8001"; + //private static final String testUser = "402030000011"; + + public static void main(String[] args) { + + + SydApi api = null; + System.out.println("\n\n----- connect -----"); + + // 建议从配置文件读取配置 + + // 单服务器测试使用 +// PoolManager.INSTANCE.createPool("default", "{\n" + +// " \"mode\" : \"solo\", // (必填)\n" + +// " \"oipc\" : \"com.sunyard.pool4sydapi.SydApiSDNXInPool\", " + +// " \"ip\" : \"172.16.18.71\", // (必填)\n" + +// " \"port\": 8889, // (必填)【数字】\n" + +// " \"pwd\": \"\", // 没有就不填写此项\n" + +// " \"timeout\": 1000 //【数字】不限超时时间就不填写此项\n" + +// "}"); + + + // // 推荐配置 +// PoolManager.INSTANCE.createPool("default", "{\n" + +// " \"mode\" : \"round-robin\", // (必填)\n" + +// " \"oipc\" : \"com.sunyard.pool4sydapi.SydApiSDNXInPool\", // (必填)\n" + +// " \"ips\" : [ // (必填)\n" + +// " \"172.16.18.69\",\n" + +// " \"172.16.18.70\"\n" + +// " ],\n" + +// " \"port\": 8889, //(必填)【数字】\n" + +// " \"pwd\": \"\", //【数字】没有就不填写此项\n" + +// " \"timeout\": 1000 , //【数字】【数字】链接和响应超时时限,不限超时时间就不填写此项\n" + +// " \"connectTimeout\" : 1000, //【数字】【数字】链接超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" + +// " \"waitRecvTimeout\" : 1000, //【数字】【数字】响应超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" + +// " \"maxContinuousErrorTime\" : 3, //【数字】 单台加密机连续出错次数\n" + +// " \"recoveryTime\" : 300000, //【数字】 恢复时间,单位毫秒,默认 5 分钟,最大 2^63\n" + +// " \"keepAlive\" : 1, //【数字】 保持链接个数,默认是链接池个数的一半\n" + +// " \"maxAliveTime\" : 300000000, //【数字】 最大生存时间\n" + +// " \"maxIdleTime\" : 300000 , //【数字】 最大空闲时间,默认 5 分钟,最大 2^63\n" + +// " \"checkMode\" : \"before/after/deamon\", // 链接检测模式,使用前/使用后/后台轮询\n" + +// " \"checkGap\" : 300000 // 后台轮询检测间隔\n" + +// "}"); + + // 自定义配置 +// PoolManager.INSTANCE.createPool("default", "{\n" + +// " \"mode\" : \"weighted-round-robin\", // (必填)\n" + +// " \"oipc\" : \"com.sunyard.pool4sydapi.SydApiSDNXInPool\", // (必填)\n" + +// " \"ips\" : { // (必填)\n" + +// " \"172.16.18.69\" : 1,\n" + +// " \"172.16.18.70\" : 3\n" + +// " },\n" + +// " \"port\": 8889, //(必填)【数字】\n" + +// " \"pwd\": \"\", //【数字】没有就不填写此项\n" + +// " \"timeout\": 1000 , //【数字】【数字】链接和响应超时时限,不限超时时间就不填写此项\n" + +// " \"connectTimeout\" : 1000, //【数字】【数字】链接超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" + +// " \"waitRecvTimeout\" : 1000, //【数字】【数字】响应超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" + +// " \"maxContinuousErrorTime\" : 3, //【数字】 单台加密机连续出错次数\n" + +// " \"recoveryTime\" : 300000, //【数字】 恢复时间,单位毫秒,默认 5 分钟,最大 2^63\n" + +// " \"keepAlive\" : 1, //【数字】 保持链接个数,默认是链接池个数的一半\n" + +// " \"maxAliveTime\" : 300000000, //【数字】 最大生存时间\n" + +// " \"maxIdleTime\" : 300000 , //【数字】 最大空闲时间,默认 5 分钟,最大 2^63\n" + +// " \"checkMode\" : \"before/after/deamon\", // 链接检测模式,使用前/使用后/后台轮询\n" + +// " \"checkGap\" : 300000 // 后台轮询检测间隔\n" + +// "}"); + + + try { + + + //热备模式连接 + SydApi4j.SYD_Set_Parameter_HA("unkown", "122.224.86.107", 8889, 1000); + api = new SydApi4j(); + + + // 链接池和负载均衡模式 + //api = (SydSDNXApiImpl) PoolManager.INSTANCE.getPool().get().getOrigin(); + + System.out.println("连接加密机成功"); + } catch (Exception e) { + e.printStackTrace(); + } + + + try { + + + //用证书DN签名 + //case1(api); + + //根据机构号验签,上传并返回证书内容,并更新机构号 + case2(api); + + + //裸签名 + //case3(api); + + //验签 + //case4(api); + + } finally { + System.out.println("\n\n----- disconnect -----"); + api.disconnect(); + } + + System.out.println("执行结束\n\n"); + } + + public static void case1(SydSDNXApiImpl api) { + + System.out.println("\n\n----- 签名 基础接口原始数据模式 -----"); + String sign = api.detachedSign(SydApi4j.DATA_ORIGIN, testData.getBytes(), testCertNo); + System.out.println("\t签名结果: " + sign); + + + } + + //需要上传验签结果,测试的时候签名和验签不能同时进行,签名以后要删除数据库数据才可以验签(仅限测试可以这样操作) + public static void case2(SydApi api) { + + System.out.println("\n\n----- 验签 ,上传并返回证书内容,并更新机构号 -----"); + + String sign = "MIIEYQYKKoEcz1UGAQQCAqCCBFEwggRNAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIIDUjCCA04wggLyoAMCAQICBUCEF1MkMAwGCCqBHM9VAYN1BQAwXDELMAkGA1UEBhMCQ04xMDAuBgNVBAoMJ0NoaW5hIEZpbmFuY2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEbMBkGA1UEAwwSQ0ZDQSBBQ1MgU00yIE9DQTMxMB4XDTE4MDExNzAxMTExMFoXDTIzMDExNzAxMTExMFowgYIxCzAJBgNVBAYTAkNOMRswGQYDVQQKDBJDRkNBIEFDUyBTTTIgT0NBMzExDjAMBgNVBAsMBVNIQ1BFMRkwFwYDVQQLDBBPcmdhbml6YXRpb25hbC0xMSswKQYDVQQDDCIwNTFA5LiK5rW356Wo5o2u5Lqk5piT5omAQEFBQUFBQUAxMFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEz79HajSQLou2kkL6n26pCKkcKcbHTWR6MbArRQruWY+WDiyPhRaYLU4W6d8wBTDTOS6T5dCtSNZBxeb5qoeeNaOCAXYwggFyMGwGCCsGAQUFBwEBBGAwXjAoBggrBgEFBQcwAYYcaHR0cDovL29jc3AuY2ZjYS5jb20uY24vb2NzcDAyBggrBgEFBQcwAoYmaHR0cDovL2NybC5jZmNhLmNvbS5jbi9vY2EzMS9vY2EzMS5jZXIwHwYDVR0jBBgwFoAUCNjRJsRIfZzsrJjp8X9iuYDOqUUwDAYDVR0TAQH/BAIwADBIBgNVHSAEQTA/MD0GCGCBHIbvKgEEMDEwLwYIKwYBBQUHAgEWI2h0dHA6Ly93d3cuY2ZjYS5jb20uY24vdXMvdXMtMTQuaHRtMDsGA1UdHwQ0MDIwMKAuoCyGKmh0dHA6Ly9jcmwuY2ZjYS5jb20uY24vb2NhMzEvU00yL2NybDcyLmNybDAOBgNVHQ8BAf8EBAMCBsAwHQYDVR0OBBYEFIzDvi38AZLlWA/Wqfk93ZPe7qNgMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDBDAMBggqgRzPVQGDdQUAA0gAMEUCICDVyelEL86xbj0mAeMl3knQD0n2QKERtni/e82bQz/nAiEAjq5SKIaVJu9T/lkds3QQfgLpBX65Rwj2Scgc7cC2dVcxgdMwgdACAQEwZTBcMQswCQYDVQQGEwJDTjEwMC4GA1UECgwnQ2hpbmEgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MRswGQYDVQQDDBJDRkNBIEFDUyBTTTIgT0NBMzECBUCEF1MkMAwGCCqBHM9VAYMRBQAwDQYJKoEcz1UBgi0BBQAERzBFAiEA03ogUebmqNyLjD5/OXr4gSdVQfqp3yqrVVPgRmGPy1QCIBkHrzpSxw/ZPloL+t1GHlEp2rW7qVgy966/lQqE7UVH"; + X509 x509 = api.SYD_Get_X509_CertInfo_HA(testData.getBytes(), sign); + System.out.println("验签结果" + x509); + } + + + public static void case3(SydSDNXApiImpl api) { + + System.out.println("\n\n----- 裸签名 -----"); + String sign = api.nakedSign(testData.getBytes(), testCertNo); + System.out.println("签名结果 " + sign); + } + + public static void case4(SydSDNXApiImpl api) { + + System.out.println("\n\n----- 裸签名 -----"); + String sign = api.nakedSign(testData.getBytes(), testCertNo); + System.out.println("签名结果 " + sign); + //String sign = "dFOUuU+JVNEZO8494MV+xtPuMVhEjnXlilHlymK9Cz/jQ3m+lRKTbv4tfyo5Eb7MM7lqQi6cdwKZ/CLnkOa+Vsye4DDYYSweqsraLwdtrVcc1sw2KDHeJUao2SXIhdhgxSw+puiOCDq/4FsJADdnYprIp+GSLfjj7tuhbBBb0JCV6rnTutIozq2QDPQKEspzMxQ2TtbVQezfL3uMA5GuYNdJYz4eAasQtxTQS5dhe3/CaWbjBeL2kKhsvuMbP6wsx2HeuXvaf99OEBkyXq2fFPJtuU7WB4SIYKN1wI0BK/IMa0ULj1Q1SBakd5+iO8ckrokJJ6E2JH3Nd/mT+5DdRg=="; + + System.out.println("\n\n----- 验签 -----"); + boolean pass = api.SYD_NakedVerify(testData.getBytes(), sign, testUser); + System.out.println("验签结果 " + pass); + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestSM3.java b/src/test/java/com/sunyard/sydapi/test/TestSM3.java new file mode 100644 index 0000000..7e3f223 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestSM3.java @@ -0,0 +1,35 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +public class TestSM3 { + + + public static void main(String[] args) { + System.setProperty("com.sunyard.sydapi4j.debug","true"); + SydApi sydApi = (new SydApi4j()).connect("172.16.18.72", 8889,null , 10000); + + byte[] data = new byte[64]; + data = "0000000000001234000000000000123411223312".getBytes(); +// data = "0000000000001234".getBytes(); + /* + byte[] hash = sydApi.SM3Hash( + null, + data + ); + + System.out.println(Util.bytes2HexString(hash) );*/ + byte[] bytes = sydApi.SYD_Encrypt_Data(2,"000012345600000101000000000", data,null,2,"0000001100000011".getBytes()); +// System.out.println("000012345600000100300000000".length()); + sydApi.SYD_Decrypt_Data(2, "000012345600000101000000000", bytes,null,2,"0000001100000011".getBytes()); + + + + sydApi.SYD_MAC_Data("000012345600000100300000000","1239172397129300","0000001100000011".getBytes(),null,1,2); +// sydApi.MAC_Data("000012345600000100300000000","12391723971293",null); +// sydApi.SYD_Disperse("000012345600000100300000000",0,1,"0000123400001234".getBytes(), 6, 0); + sydApi.disconnect(); + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestSignDev.java b/src/test/java/com/sunyard/sydapi/test/TestSignDev.java new file mode 100644 index 0000000..4ca7470 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestSignDev.java @@ -0,0 +1,51 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.RetWrap; +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +public class TestSignDev { + + + public static void main(String[] args) { + + +// // LMK 加密 +// String mpk = "0342000444764761741DB405927EA722AD11D9740B9884CE5FDFF8D55CAFA5D0A2A8AF2509FE98DCDD57D86029FB6760526FAC9CC8339B7346BCDF7900185835596DC5EE"; +// String msk = "000100006EAE89B76EA4852B3EA389BE3B5F4AA5AB433DB210B5A76BE2B0E1ED63016CC90000000000000000000000000000000000000000000000000000000000000000"; +// +// String devchk = "313230303131313131313131313131313434333233363330343434353331343359ED844B507EE2D2F1A4AB1E27A75F6F55AFAEC33CD7A7E6D32FA92D3376A72C8F1DBF5A3DB27B45C005BA62978E97F7DAB8EBF119037F6624945596D5CC13ED"; +// +// // 用会员端的设备做签名 +// SydApi member = (new SydApi4j()).connect("47.111.95.168", 8889,null , 10000); +// RetWrap ret = member.SM2SignDEV( +// +// Util.hexString2Bytes( msk ), +// Util.hexString2Bytes( mpk ), +// "hq".getBytes() +// ); +// +// byte[] sign = (byte[]) ret.get("sign"); +// System.out.println( "sign " + Util.bytes2HexString( sign ) ); + + +// // 使用中心端加密机做验签 +// SydApi center = (new SydApi4j()).connect("172.16.17.162", 8889,null , 10000); +// +// byte[] v = Util.hexString2Bytes( devchk ); +// byte[] d = "hq".getBytes(); +// byte[] s = new byte[ v.length + d.length ]; +// System.arraycopy( d, 0 , s, 0, d.length ); +// System.arraycopy( v, 0 ,s, d.length, v.length ); +// +// boolean r = center.SM2VerifyDEV( +// sign, +// Util.hexString2Bytes( mpk ), +// s +// ); +// +// System.out.println( r ? "pass" : "ban"); + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestTps.java b/src/test/java/com/sunyard/sydapi/test/TestTps.java new file mode 100644 index 0000000..bff5067 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestTps.java @@ -0,0 +1,98 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +import java.util.ArrayList; +import java.util.List; + +public class TestTps { + + public void send(int threadNum, final int times) throws InterruptedException { + + SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.17.162", 8889, 1000); + final SydApi4j api = (SydApi4j) new SydApi4j(); + String pk = "03420004C9FD0B37230DF91621F6880C8123A445CB14FFB1B1342D0AC9449374876A4B1E00A15B9E8DF307EE538526883F093568C5B70C5A61BEF5F880C827DDC90366B5"; + String sk = "00010000C530EFBC1971D6526BDAB640370EE9197BFB0D78F88417C1ED49981FFEF226980000000000000000000000000000000000000000000000000000000000000000"; + final byte[] skByte = Util.hexString2Bytes(sk); + final byte[] pkByte = Util.hexString2Bytes(pk); + final String data = "MainBody>1015570000408702018091900000000012018-09-19T10:13:391015570000408702015970000397542018-09-1900000001123456,测试"; + + + //开始时间 + long startTime = System.currentTimeMillis(); + + List list = new ArrayList(); + for (int i = 0; i < threadNum; i++) { + + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + for (int j = 0; j < times; j++) { + api.SYD_SM2_Sign_HA( + SydApi.DATA_ORIGIN, + skByte, + pkByte, + data.getBytes() + ); + } + } + }); + thread.start(); + list.add(thread); + } + + try { + for(Thread thread : list){ + thread.join(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + + //结束时间 + long endTime = System.currentTimeMillis(); + long useTime = endTime - startTime; + long tps = (threadNum * times * 1000) / useTime; + System.out.println(threadNum + "个线程,tps:" + tps); + } + + + public static void main(String[] args) throws InterruptedException { + + TestTps testTps = new TestTps(); + int times = 100; + testTps.send(2, times); +// testTps.send(2, times); +// testTps.send(4, times); +// testTps.send(8, times); +// testTps.send(12, times); +// testTps.send(16, times); + + + } +} + + +/* + + public void computeTps(int threadNum, final int times) { + + long startTime = System.currentTimeMillis(); + //System.out.println(" main startTime:"+startTime); + + //send(threadNum, times); + + long endTime = System.currentTimeMillis(); + //System.out.println("main useTime:"+(endTime - startTime)); + + long useTime = endTime - startTime; + // System.out.println("send useTime" + useTime); + + long tps = (threadNum * times * 1000) / useTime; + System.out.println(threadNum + "个线程,tps:" + tps); + + } +*/ diff --git a/src/test/java/com/sunyard/sydapi/test/TestUtil.java b/src/test/java/com/sunyard/sydapi/test/TestUtil.java new file mode 100644 index 0000000..67ac437 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestUtil.java @@ -0,0 +1,45 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.trans.PacketSN; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; + +public class TestUtil { + public static void main(String[] args) throws Exception { + /* PacketSN sn = PacketSN.gen(); + HashMap packet = new HashMap(); + packet.put("header", sn.getSn().array()); + HashMap data = new HashMap(); + data.put("alg$option", 0); + data.put("certificateModel$option", 0); + data.put("certificateSn", "113123"); + data.put("keyType", "X"); + packet.put("data", data); + SectionWrap s=new SectionWrap(); + HashMap sc = new HashMap(); + SectionValue s2=new SectionValue(); + s2.setValue("L".getBytes()); + sc.put("data",s2); + s.setSections(sc);*/ +// HashMap packet = new HashMap(); +// HashMap data = new HashMap(); +// packet.put("data", data); +// PacketSN sn = PacketSN.gen(); +// packet.put("header", sn.getSn().array()); +// data.put("algorithmId$option", 0x1); +// data.put("keyLength", 256); +// +// try { +// byte[] a=(byte[]) Util.eval("ResE2","getKeyLen",packet,null,null); +// System.out.println(a[0]); +// } catch (Exception e) { +// e.printStackTrace(); +// } + + + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestXianfeng.java b/src/test/java/com/sunyard/sydapi/test/TestXianfeng.java new file mode 100644 index 0000000..a294f7d --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestXianfeng.java @@ -0,0 +1,39 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.SydApi; +import com.sunyard.proto.Util; +import racal.sunyard.main.SydApi4j; + +public class TestXianfeng { + + + public static void main(String[] args) { + System.setProperty("com.sunyard.sydapi4j.debug","true"); + + + SydApi sydApi = (new SydApi4j()).connect("172.16.18.72", 8889,null , 10000); + + +// byte[] data = "0000000000001234000000000000123411223312".getBytes(); +// byte[] bytes = sydApi.SYD_Encrypt_Data(2,"000012345600000101000000000", data,null,2,"0000001100000011".getBytes()); +// +// +// +// +// sydApi.SYD_Decrypt_Data(2, "000012345600000101000000000", bytes,null,2,"0000001100000011".getBytes()); + + + + + byte[] mac = sydApi.SYD_MAC_Data("000012345600000100300000000","0000000a0200000000000120190927175528", "00000011000000110000001100000011".getBytes(),"1234567812345678",2,2); + + + System.out.print("mac = "); + System.out.println( Util.bytes2HexString(mac) ); + + + sydApi.disconnect(); + } + +} + diff --git a/src/test/java/com/sunyard/sydapi/test/TestY8.java b/src/test/java/com/sunyard/sydapi/test/TestY8.java new file mode 100644 index 0000000..e449650 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/TestY8.java @@ -0,0 +1,17 @@ +package com.sunyard.sydapi.test; + +import racal.sunyard.main.SydApi4j; + +public class TestY8 { + + public static void testY8(){ + //SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.18.69", 8889, 1000); + SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.18.226", 8500, null, 1000); + api.GenerateRandom(8); + System.out.println("==============="); + } + + public static void main(String[] args) { + testY8(); + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/Xianfeng.java b/src/test/java/com/sunyard/sydapi/test/Xianfeng.java new file mode 100644 index 0000000..bd78a21 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/Xianfeng.java @@ -0,0 +1,56 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.SydApi; +import com.sunyard.SydApiException; +import racal.sunyard.main.SydApi4j; + + +class Test { + + public static void main(String[] args) { + + SydApi sydApi = null; + try { + System.out.println("SydApi 测试程序启动"); + //设置为调试模式 上线使用不需要 + System.setProperty("com.sunyard.sydapi4j.debug", "true"); + //建立链接 + sydApi = (new SydApi4j()).connect("172.16.17.162", 8889, null, 30000); + System.out.println("连接成功"); + + //原始数据 + byte[] data = "cdb1af4bb0ab6de6".getBytes("UTF-8"); + //加解密密钥 + String key1 = "000079500100000101000000000"; + //MAC密钥 + String key2 = "000079500100000100300000001"; + //MAC数据 + String data2 = "000000000600000000000120190927164948"; + //分散因子 + String data3 = "0000000000002456aece4be200050001"; + // 随机数 + String pRandom = "0000000000000000"; + //加密 + byte[] bytes = sydApi.SYD_Encrypt_Data(2, key1, data, null, 2, data3.getBytes()); + System.out.println("Encrypt:" + new String(bytes, "UTF-8")); + //解密 + sydApi.SYD_Decrypt_Data(2, key1, bytes, null, 2, data3.getBytes()); + //生成MAC + byte[] macBytes = sydApi.SYD_MAC_Data(key2, data2, data3.getBytes(), pRandom, 2, 2); + + System.out.println("MAC:" + new String(macBytes, "UTF-8")); + + System.out.println("执行结束"); + sydApi.disconnect(); + } catch (SydApiException e) { + System.out.print("执行错误1:" + e); + + } catch (Exception ex) { + System.out.print("执行错误2:" + ex); + } finally { + if (sydApi != null) { + sydApi.disconnect(); + } + } + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/ora.kt b/src/test/java/com/sunyard/sydapi/test/ora.kt new file mode 100644 index 0000000..cd7f860 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/ora.kt @@ -0,0 +1,41 @@ +package com.sunyard.sydapi.test + +import com.sunyard.proto.Util +import kotlin.experimental.xor + + +fun main(args: Array) { + +// val k1 = Util.hexString2Bytes(String(Util.hexString2Bytes("61613030313131313131313131313131"))) +// val k2 = Util.hexString2Bytes( String( Util.hexString2Bytes("33303435333533353331343133353338"))) +// +// +// println( String(k1) ) +// println( String(k2) ) +// +// +// val d = ByteArray(8) +// for ( i in 0..7 ){ +// d[i] = k1[i] xor k2[i] +// } +// +// println(Util.bytes2HexString(d) ) +// println( String(d) ) + + + val k1 = Util.hexString2Bytes("61613030313131313131313131313131") + val k2 = Util.hexString2Bytes("33303435333533353331343133353338") + + + println( String(k1) ) + println( String(k2) ) + + + val d = ByteArray(16) + for ( i in 0..15 ){ + d[i] = k1[i] xor k2[i] + } + + println( Util.bytes2HexString(d) ) + println( String(d) ) +} \ No newline at end of file diff --git a/src/test/java/com/sunyard/sydapi/test/parseTest.java b/src/test/java/com/sunyard/sydapi/test/parseTest.java new file mode 100644 index 0000000..3ebf41f --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/parseTest.java @@ -0,0 +1,25 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.proto.ProtocolParser; +import com.sunyard.proto.ProtocolSet; +import com.sunyard.proto.Util; +import com.sunyard.proto.loader.Loader; +import com.sunyard.proto.loader.ResourceLoader; + +public class parseTest { + public static void main(String[] args) throws Exception { + String test = "00C600000000000000013642303030313031303034323832343532303136384D4877434944674F4A375A327A6262447368426C456D394479506541444B4656366B376F473050526E5348743343654841694541734F58682F35694138574E5736676A483855445849376F464E744B597A69536A4F5939757048474F3845384549424935357438424E4E744556754E4E415A4472645762676F59414D6F6C487534344D56327973785153586E42424F794B43464B34316D4F303845382B2B592F524E67646349736558"; + byte[] indata = Util.hexString2Bytes(test); + Loader loader = new ResourceLoader( "^packet.racal.sunyard.*"); + ProtocolSet pset = new ProtocolSet(loader); + ProtocolParser parser = pset.getProtocolResParse(); + //Packet packet = parser.parse(ByteBuffer.wrap(indata)); + + + + + + //System.out.println(packet.toMap()); + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/rendTest.java b/src/test/java/com/sunyard/sydapi/test/rendTest.java new file mode 100644 index 0000000..90413e5 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/rendTest.java @@ -0,0 +1,33 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.proto.ProtocolRender; +import com.sunyard.proto.ProtocolSet; +import com.sunyard.proto.Util; +import com.sunyard.proto.loader.Loader; +import com.sunyard.proto.loader.ResourceLoader; +import com.sunyard.trans.PacketSN; + +import java.nio.ByteBuffer; +import java.util.HashMap; + +public class rendTest { + public static void main(String[] args) throws Exception { + + Loader loader = new ResourceLoader( "^packet.racal.sunyard.*"); + ProtocolSet pset = new ProtocolSet(loader); + ProtocolRender render = pset.getProtocolReqRender("E2"); + + // 填充数据 + HashMap packet = new HashMap(); + HashMap data = new HashMap(); + packet.put("data",data); + PacketSN sn = PacketSN.gen(); + packet.put("header", sn.getSn().array()); + data.put("algorithmId", 0x1); + data.put("keyLength", 256); + + ByteBuffer buf = render.rend( packet ); + System.out.println(Util.bytes2HexString(Util.toArray(buf))); + + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/test.groovy b/src/test/java/com/sunyard/sydapi/test/test.groovy new file mode 100644 index 0000000..a015536 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/test.groovy @@ -0,0 +1,5 @@ +package com.sunyard.sydapi.test + +def a = "P".charAt(0) + +println 'P' == a diff --git a/src/test/java/com/sunyard/sydapi/test/test.html b/src/test/java/com/sunyard/sydapi/test/test.html new file mode 100644 index 0000000..2d0972e --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/test.html @@ -0,0 +1,12 @@ + + + + + Title + + + + + + + diff --git a/src/test/java/com/sunyard/sydapi/test/testDemo.java b/src/test/java/com/sunyard/sydapi/test/testDemo.java new file mode 100644 index 0000000..436afba --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/testDemo.java @@ -0,0 +1,185 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.DaToSHCA; + + +import java.io.FileInputStream; +import java.util.Scanner; + + + +public class testDemo { + public static DaToSHCA.da_handle tmpHandle = new DaToSHCA.da_handle(); + public static DaToSHCA tmpTest = new DaToSHCA(); + + public static byte[] HashData; + public static String SignData; + + public static void mainHandle() { + System.out.println("/*---------------------*/"); + System.out.println("/* 1. SM3分步哈希 "); + System.out.println("/* 2. SM2签名 "); + System.out.println("/* 3. SM2验证 "); + System.out.println("/* 0. exit "); + System.out.println("/*---------------------*/"); + } + + public static void main(String[] args) { + //==============创建连接============= + boolean OpenFlag = tmpTest.DA_OpenHsmServer(tmpHandle, "172.16.18.73",8889); + if (!OpenFlag) { + System.out.println("[ERROR] DA_OpenHsmServer error ..."); + return ; + } + else { + System.out.println("[SUCCESS] DA_OpenHsmServer success ..."); + } + + while(true) { + mainHandle(); + Scanner scan = new Scanner(System.in); + System.out.print("Please Input Number: "); + int choice = scan.nextInt(); + + switch(choice) { + case 1: + try { + testSM3Hash(); + } catch (Exception e) { + System.out.println("[ERROR] testSM3: " + e.getMessage()); + e.printStackTrace(); + } + break; + case 2: + try { + testDA_SM2Sgin(); + } catch (Exception e) { + System.out.println("[ERROR] testDA_SM2Sgin: " + e.getMessage()); + e.printStackTrace(); + } + break; + case 3: + try { + testDA_SM2Verify(); + } catch (Exception e) { + System.out.println("[ERROR] testDA_SM2Verify: " + e.getMessage()); + e.printStackTrace(); + } + break; + case 0: + scan.close(); + // ==============释放连接============= + boolean CloseFlag = tmpTest.DA_CloseHsmServer(tmpHandle); + if (!CloseFlag) { + System.out.println("[ERROR] DA_CloseHsmServer error ..."); + return ; + } + else { + System.out.println("[SUCCESS] DA_CloseHsmServer success ..."); + } + return ; + default: + System.out.println("Number Error, Please Input Again ..."); + } + } + } + + public static void testSM3Hash() throws Exception { + byte[] InData = getInData("d:\\TestFile.txt"); + + // 获取 SM3 Hash运算公钥 + byte[] sm2Pub = tmpTest.DA_GetSM2PublicKey(tmpHandle, 3).getEncoded(); + + // SM3 初始化 + tmpTest.SM3_Init(tmpHandle, sm2Pub); + + // SM3 Updata + int p = InData.length/128; + int q = InData.length%128; + + for(int i=0; i>>> Hex HashData[" + HashData.length + "] = "); + System.out.println(bin2HexString(HashData)); + } + } + + public static void testDA_SM2Sgin() throws Exception { + // 对数据进行 SM2签名 + SignData = new String(tmpTest.DA_SM2Sgin(tmpHandle, 3,HashData )); + if (SignData == null) { + System.out.println("[ERROR] DA_SM2Sgin error ..."); + return ; + } + else { + System.out.println("[SUCCESS] DA_SM2Sgin success ...\n"); + + // 打印 Base64编码后的 DER格式的 SM2签名数据 + System.out.println(">>>> Base64 Der SignData[" + SignData.length() + "] = "); + System.out.println(SignData); + + } + } + + public static void testDA_SM2Verify() throws Exception { + // 获取SM2公钥 + byte[] sm2Pub = tmpTest.DA_GetSM2PublicKey(tmpHandle, 3).getEncoded(); + + // 对数据及签名值进行 SM2验签 + boolean VerifyFlag = tmpTest.DA_SM2Verify(tmpHandle, HashData, SignData, sm2Pub); + if (!VerifyFlag) { + System.out.println("[ERROR] DA_SM2Verify error ..."); + return ; + } + else { + System.out.println("[SUCCESS] DA_SM2Verify success ..."); + } + } + + // 读取文件内容 + public static byte[] getInData(String fileName) throws Exception { + FileInputStream tmpInput = new FileInputStream(fileName); + int InDataLen = tmpInput.available(); + + byte[] InData = new byte[InDataLen]; + + tmpInput.read(InData); + tmpInput.close(); + + System.out.println("[Info] Read File:{" + fileName + "}, Read Length:{" + InDataLen + "} ..."); + + return InData; + } + + // 2进制数组 转化为 16进制字符串 + public static String bin2HexString(byte[] tmpBin) { + StringBuilder tmpStrB = new StringBuilder(); + + for(int i=0; i