Merge remote-tracking branch 'origin/dev-1.12' into dev-1.12
This commit is contained in:
commit
50de278cd3
@ -17,6 +17,9 @@
|
|||||||
<option cn="SM2_SM4_ECB 机构码|02|密钥">
|
<option cn="SM2_SM4_ECB 机构码|02|密钥">
|
||||||
<hex>2</hex>
|
<hex>2</hex>
|
||||||
</option>
|
</option>
|
||||||
|
<option cn="PKCS7_SM2_SM4_ECB">
|
||||||
|
<hex>3</hex>
|
||||||
|
</option>
|
||||||
</options>
|
</options>
|
||||||
</alg>
|
</alg>
|
||||||
|
|
||||||
@ -49,6 +52,14 @@
|
|||||||
可选项,只针对“证书模式”为 1时有。
|
可选项,只针对“证书模式”为 1时有。
|
||||||
</certificateDn>
|
</certificateDn>
|
||||||
|
|
||||||
|
<orgDataLen len="4" :value="dataLen()" :if="3 == $packet.data.alg$option" cn="数据长度">
|
||||||
|
只针对算法标识为3时传入
|
||||||
|
</orgDataLen>
|
||||||
|
|
||||||
|
<orgData :if="3 == $packet.data.alg$option" cn="数据长度">
|
||||||
|
只针对算法标识为3时传入
|
||||||
|
</orgData>
|
||||||
|
|
||||||
<keyType len="1" cn="加密密钥方案">
|
<keyType len="1" cn="加密密钥方案">
|
||||||
LMK 下加密密钥的方案。
|
LMK 下加密密钥的方案。
|
||||||
</keyType>
|
</keyType>
|
||||||
@ -72,11 +83,10 @@
|
|||||||
</tail>
|
</tail>
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</req>
|
</req>
|
||||||
<res>
|
|
||||||
|
|
||||||
|
|
||||||
|
<res>
|
||||||
<command>
|
<command>
|
||||||
<hex>6B</hex>
|
<hex>6B</hex>
|
||||||
</command>
|
</command>
|
||||||
@ -162,12 +172,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getKeyLen() {
|
function getKeyLen() {
|
||||||
return Util.a2i( $final.getSection('data').getSection('keyLen') )
|
return Util.a2i( $final.getSection('data').getSection('keyLen') )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function lmkLen() {
|
function lmkLen() {
|
||||||
if( Arrays.equals("L".getBytes(),
|
if( Arrays.equals("L".getBytes(),
|
||||||
$final.getSection('data').getSection('lmkHead').getValue()
|
$final.getSection('data').getSection('lmkHead').getValue()
|
||||||
@ -178,6 +186,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dataLen() {
|
||||||
|
return $packet.data.orgData.length()
|
||||||
|
}
|
||||||
|
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
function hasOrgCode() {
|
function hasOrgCode() {
|
||||||
if(2 == $packet.data.alg$option && 'P' == $packet.data.pFlag) {
|
if(2 == $packet.data.alg$option && 'P' == $packet.data.pFlag) {
|
||||||
|
|||||||
@ -7,6 +7,10 @@
|
|||||||
</command>
|
</command>
|
||||||
<data extend="data">
|
<data extend="data">
|
||||||
|
|
||||||
|
<pFlag len="1" required="false" cn="P标志">
|
||||||
|
可选,如果输入P代表使用PKCS7_SM2_SM4_ECB模式解密数字信封
|
||||||
|
</pFlag>
|
||||||
|
|
||||||
<certificateModel len="1" cn="证书模式">
|
<certificateModel len="1" cn="证书模式">
|
||||||
<options>
|
<options>
|
||||||
<option cn="证书序号">
|
<option cn="证书序号">
|
||||||
@ -55,8 +59,6 @@
|
|||||||
</tail>
|
</tail>
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</req>
|
</req>
|
||||||
<res>
|
<res>
|
||||||
|
|
||||||
@ -104,6 +106,14 @@
|
|||||||
</options>
|
</options>
|
||||||
</error>
|
</error>
|
||||||
|
|
||||||
|
<oDataLen len="4" cn="明文数据长度">
|
||||||
|
明文原始数据长度(只针对P存在时,无P时为0)
|
||||||
|
</oDataLen>
|
||||||
|
|
||||||
|
<oData :len="oDataLen()" cn="明文数据">
|
||||||
|
原始数据(只针对P存在时,无P时不存在)
|
||||||
|
</oData>
|
||||||
|
|
||||||
<!--<keyLen len="4" cn="密钥密文长度">-->
|
<!--<keyLen len="4" cn="密钥密文长度">-->
|
||||||
<!--公钥加密的密钥密文长度-->
|
<!--公钥加密的密钥密文长度-->
|
||||||
<!--</keyLen>-->
|
<!--</keyLen>-->
|
||||||
@ -173,5 +183,9 @@
|
|||||||
function orgCodeLen() {
|
function orgCodeLen() {
|
||||||
return Util.a2i( $final.getSection('data').getSection('orgCodeLen') )
|
return Util.a2i( $final.getSection('data').getSection('orgCodeLen') )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function oDataLen() {
|
||||||
|
return Util.a2i( $final.getSection('data').getSection('oDataLen') )
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</packet>
|
</packet>
|
||||||
|
|||||||
191
DProto/6BXF.xml
Normal file
191
DProto/6BXF.xml
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<packet extend="base">
|
||||||
|
<req>
|
||||||
|
|
||||||
|
<command>
|
||||||
|
<hex>6B</hex>
|
||||||
|
</command>
|
||||||
|
<data extend="data">
|
||||||
|
|
||||||
|
<pFlag len="1" required="false" cn="P标志">
|
||||||
|
可选,如果输入P代表使用PKCS7_SM2_SM4_ECB模式解密数字信封
|
||||||
|
</pFlag>
|
||||||
|
|
||||||
|
<certificateModel len="1" cn="证书模式">
|
||||||
|
<options>
|
||||||
|
<option cn="证书序号">
|
||||||
|
<hex>0</hex>
|
||||||
|
</option>
|
||||||
|
<option cn="证书 DN">
|
||||||
|
<hex>1</hex>
|
||||||
|
</option>
|
||||||
|
</options>
|
||||||
|
</certificateModel>
|
||||||
|
|
||||||
|
|
||||||
|
<certificateLen len="4" :value="certificateLen()" cn="证书内容长度">
|
||||||
|
根据证书模式,需要输入内容项的长度 n
|
||||||
|
</certificateLen>
|
||||||
|
|
||||||
|
|
||||||
|
<certificateSn :len="strlen()" :if="0 == $packet.data.certificateModel$option" cn="X509 证书序号">
|
||||||
|
可选项,只针对“证书模式”为 0时有。
|
||||||
|
</certificateSn>
|
||||||
|
|
||||||
|
<certificateDn :if="1 == $packet.data.certificateModel$option" cn="X509 证书的 subject">
|
||||||
|
可选项,只针对“证书模式”为 1时有。
|
||||||
|
</certificateDn>
|
||||||
|
|
||||||
|
<keyLen len="4" :value="keyLen()" cn="密钥密文长度">
|
||||||
|
公钥加密的密钥密文长度
|
||||||
|
</keyLen>
|
||||||
|
|
||||||
|
<key :len="getKeyLen()" cn="密钥密文">
|
||||||
|
公钥加密的密钥密文的 BASE64 编码
|
||||||
|
</key>
|
||||||
|
|
||||||
|
<keyType len="1" cn="加密密钥方案">
|
||||||
|
LMK 下加密密钥的方案。
|
||||||
|
</keyType>
|
||||||
|
|
||||||
|
<tailSep len="1" :if=" null != $packet.data.tail " cn="尾分隔">
|
||||||
|
可选项。如果显示消息尾域,则该域必须显示。值为
|
||||||
|
“X’19”。
|
||||||
|
<hex>19</hex>
|
||||||
|
</tailSep>
|
||||||
|
|
||||||
|
<tail maxLen="32" required="false" cn="尾部">
|
||||||
|
可选项。最大长度为 32个字符。
|
||||||
|
</tail>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
</req>
|
||||||
|
<res>
|
||||||
|
|
||||||
|
<command>
|
||||||
|
<hex>6C</hex>
|
||||||
|
</command>
|
||||||
|
<data>
|
||||||
|
<error len="2" cn="错误码" format="X" :catch="catchError('%s')">
|
||||||
|
<options>
|
||||||
|
<option cn="无错误">
|
||||||
|
<hex>00</hex>
|
||||||
|
</option>
|
||||||
|
<option cn="公钥不符合编码规则">
|
||||||
|
<hex>04</hex>
|
||||||
|
</option>
|
||||||
|
<option cn="无效的加密标识">
|
||||||
|
<hex>06</hex>
|
||||||
|
</option>
|
||||||
|
<option cn="无效的附加模式标识">
|
||||||
|
<hex>07</hex>
|
||||||
|
</option>
|
||||||
|
<option cn="密钥奇偶校验错误">
|
||||||
|
<hex>10</hex>
|
||||||
|
</option>
|
||||||
|
<option cn="LMK 错误">
|
||||||
|
LMK 错误;报告给管理员。
|
||||||
|
<hex>13</hex>
|
||||||
|
</option>
|
||||||
|
<option cn="输入数据错">
|
||||||
|
<hex>15</hex>
|
||||||
|
</option>
|
||||||
|
<option cn="输入的数据格式错误">
|
||||||
|
<hex>21</hex>
|
||||||
|
</option>
|
||||||
|
<option cn="DSP 错误">
|
||||||
|
DSP 错误;报告给管理员。
|
||||||
|
<hex>47</hex>
|
||||||
|
</option>
|
||||||
|
<option cn="密钥块长度错误">
|
||||||
|
<hex>76</hex>
|
||||||
|
</option>
|
||||||
|
<option cn="输入数据长度错误">
|
||||||
|
<hex>80</hex>
|
||||||
|
</option>
|
||||||
|
</options>
|
||||||
|
</error>
|
||||||
|
|
||||||
|
<oDataLen len="4" cn="明文数据长度">
|
||||||
|
明文原始数据长度(只针对P存在时,无P时为0)
|
||||||
|
</oDataLen>
|
||||||
|
|
||||||
|
<oData :len="oDataLen()" cn="明文数据">
|
||||||
|
原始数据(只针对P存在时,无P时不存在)
|
||||||
|
</oData>
|
||||||
|
|
||||||
|
<!--<keyLen len="4" cn="密钥密文长度">-->
|
||||||
|
<!--公钥加密的密钥密文长度-->
|
||||||
|
<!--</keyLen>-->
|
||||||
|
|
||||||
|
<lmkHead len="1" cn="lmk 头">
|
||||||
|
如果是 'L' ,lmk 32 个字节长,否则 lmk 64 个字节长。
|
||||||
|
</lmkHead>
|
||||||
|
|
||||||
|
<lmk :len="lmkLen()" cn="对称密钥的密文">
|
||||||
|
对称密钥的密文,由 LMK30-31 保护。
|
||||||
|
</lmk>
|
||||||
|
|
||||||
|
<keyCheck len="16" cn="密钥校验值">
|
||||||
|
密钥校验值
|
||||||
|
</keyCheck>
|
||||||
|
|
||||||
|
<orgCodeLen len="4" cn="机构码长度">
|
||||||
|
公钥加密的密钥格式3所需机构码长度,仅当格式3以及'P'存在时存在
|
||||||
|
</orgCodeLen>
|
||||||
|
|
||||||
|
<orgCode :len="orgCodeLen()" cn="机构码长度">
|
||||||
|
公钥加密的密钥格式3所需机构码长度,仅当格式3以及'P'存在时存在
|
||||||
|
</orgCode>
|
||||||
|
|
||||||
|
<tailSep len="1" required="false" cn="尾分隔">
|
||||||
|
可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。
|
||||||
|
<hex>19</hex>
|
||||||
|
</tailSep>
|
||||||
|
|
||||||
|
<tail maxLen="32" required="false" cn="尾部">
|
||||||
|
可选项。最大长度为 32个字符。
|
||||||
|
</tail>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</res>
|
||||||
|
<script>
|
||||||
|
function certificateLen(){
|
||||||
|
var data = $packet.data;
|
||||||
|
if( 0 == data.certificateModel$option ){
|
||||||
|
return data.certificateSn.length
|
||||||
|
}
|
||||||
|
if( 1 == data.certificateModel$option ){
|
||||||
|
return data.certificateDn.length
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyLen() {
|
||||||
|
return $packet.data.key.length()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getKeyLen() {
|
||||||
|
return Util.a2i( $final.getSection('data').getSection('keyLen') )
|
||||||
|
}
|
||||||
|
|
||||||
|
function lmkLen() {
|
||||||
|
if( Arrays.equals("L".getBytes(),
|
||||||
|
$final.getSection('data').getSection('lmkHead').getValue()
|
||||||
|
) ){
|
||||||
|
return 64
|
||||||
|
}else{
|
||||||
|
return 32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function orgCodeLen() {
|
||||||
|
return Util.a2i( $final.getSection('data').getSection('orgCodeLen') )
|
||||||
|
}
|
||||||
|
|
||||||
|
function oDataLen() {
|
||||||
|
return Util.a2i( $final.getSection('data').getSection('oDataLen') )
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</packet>
|
||||||
Binary file not shown.
2
pom.xml
2
pom.xml
@ -71,7 +71,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sunyard</groupId>
|
<groupId>com.sunyard</groupId>
|
||||||
<artifactId>proto</artifactId>
|
<artifactId>proto</artifactId>
|
||||||
<version>1.0-20220402</version>
|
<version>1.0-20220412</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -216,6 +216,32 @@ public interface SydGenApi {
|
|||||||
*/
|
*/
|
||||||
RetWrap generateDEByDn(byte[] dn, int alg, int model) throws Exception;
|
RetWrap generateDEByDn(byte[] dn, int alg, int model) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产生对称密钥,通过公钥加密生成网联格式的数字信封。
|
||||||
|
|
||||||
|
* @param certSerial 证书DN。
|
||||||
|
* @param oData 明文数据
|
||||||
|
* @return RetWrap 包含 CipherKey SessionKey KCV
|
||||||
|
* CipherKey 公钥加密的会话密钥 ,BASE64 编码
|
||||||
|
* SessionKey 本地LMK 加密的会话密钥,HEX 格式, 本地 LMK 加密的会话密钥长度,HEX 格式(不包括第 1 个字符),一般为 33 个 Bytes。默认输入值为缓冲区的大小。
|
||||||
|
* KCV 会话密钥的检验值,HEX 格式,长度为 32H。
|
||||||
|
*/
|
||||||
|
RetWrap generateDEByDn(byte[] certSerial, String oData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产生对称密钥,通过公钥加密生成网联格式的数字信封。
|
||||||
|
|
||||||
|
* @param certSerial 证书DN或SN。
|
||||||
|
* @param alg 算法标识,0:AES,1-3:SM4
|
||||||
|
* @param model 证书模式,0:证书序号,1:证书 DN
|
||||||
|
* @param oData 明文数据
|
||||||
|
* @return RetWrap 包含 CipherKey SessionKey KCV
|
||||||
|
* CipherKey 公钥加密的会话密钥 ,BASE64 编码
|
||||||
|
* SessionKey 本地LMK 加密的会话密钥,HEX 格式, 本地 LMK 加密的会话密钥长度,HEX 格式(不包括第 1 个字符),一般为 33 个 Bytes。默认输入值为缓冲区的大小。
|
||||||
|
* KCV 会话密钥的检验值,HEX 格式,长度为 32H。
|
||||||
|
*/
|
||||||
|
RetWrap generateDE(byte[] certSerial, int alg, int model, String oData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 产生对称密钥,通过公钥加密生成网联格式的数字信封。
|
* 产生对称密钥,通过公钥加密生成网联格式的数字信封。
|
||||||
|
|
||||||
@ -271,6 +297,34 @@ public interface SydGenApi {
|
|||||||
String pCipherKey
|
String pCipherKey
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收用私钥解密数字信封,还原对称密钥。
|
||||||
|
* 默认会传P
|
||||||
|
* @param certSerial 输入。 对方 X509 证书的DN。
|
||||||
|
* @param pCipherKey 输入。 公钥加密的会话密钥,BASE64 编码
|
||||||
|
* @return RetWrap 包含 SessionKey KCV
|
||||||
|
* oData 如果有机构码的话会返回原数据
|
||||||
|
* SessionKey 输出。 本地LMK 加密的会话密钥,格式为:密钥类型|密钥密文,比如:02|密钥密文
|
||||||
|
* KCV 会话密钥的检验值,HEX 格式,长度为 36H。
|
||||||
|
* orgCode 如果有机构码的话会返回机构码
|
||||||
|
*/
|
||||||
|
RetWrap decryptDEByDN(byte[] certSerial, String pCipherKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收用私钥解密数字信封,还原对称密钥。
|
||||||
|
*
|
||||||
|
* @param pFlag 输入。 p标识,如果为true,则传入P
|
||||||
|
* @param model 输入。 证书模式,0:证书序号,1:证书 DN
|
||||||
|
* @param certSerial 输入。 对方 X509 证书的序列号或DN。
|
||||||
|
* @param pCipherKey 输入。 公钥加密的会话密钥,BASE64 编码
|
||||||
|
* @return RetWrap 包含 SessionKey KCV
|
||||||
|
* oData 如果有机构码的话会返回原数据
|
||||||
|
* SessionKey 输出。 本地LMK 加密的会话密钥,格式为:密钥类型|密钥密文,比如:02|密钥密文
|
||||||
|
* KCV 会话密钥的检验值,HEX 格式,长度为 36H。
|
||||||
|
* orgCode 如果有机构码的话会返回机构码
|
||||||
|
*/
|
||||||
|
RetWrap decryptDE(boolean pFlag, int model, byte[] certSerial, String pCipherKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 产生要求长度的随即数据串,可用于身份认证
|
* 产生要求长度的随即数据串,可用于身份认证
|
||||||
*
|
*
|
||||||
|
|||||||
@ -2115,58 +2115,6 @@ public class SydApi4j implements SydApi {
|
|||||||
return repackEncrypt(packet);
|
return repackEncrypt(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 当证书模式为证书序号时,测试成功
|
|
||||||
// 测试通过
|
|
||||||
@Override
|
|
||||||
public RetWrap generateDEByDn(byte[] dn, int alg, int model) {
|
|
||||||
Proto6A proto = new Proto6A();
|
|
||||||
// 填充数据
|
|
||||||
PacketSN sn = PacketSN.gen();
|
|
||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
|
||||||
packet.put("header", sn.getSn().array());
|
|
||||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
|
||||||
data.put("alg$option", alg);
|
|
||||||
data.put("certificateModel$option", model);
|
|
||||||
|
|
||||||
if (model == 0) {
|
|
||||||
data.put("certificateSn", dn);
|
|
||||||
} else {
|
|
||||||
data.put("certificateDn", dn);
|
|
||||||
}
|
|
||||||
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<String, Object> ret = p.toMap();
|
|
||||||
if (
|
|
||||||
!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())
|
|
||||||
) {
|
|
||||||
throw new SydApiException("包序号不匹配", -4);
|
|
||||||
}
|
|
||||||
ret = (Map<String, Object>) 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
|
@Override
|
||||||
public RetWrap generateDEbyGS(String certSerial, byte nAlg) {
|
public RetWrap generateDEbyGS(String certSerial, byte nAlg) {
|
||||||
return generateDE(1, certSerial, nAlg, null);
|
return generateDE(1, certSerial, nAlg, null);
|
||||||
@ -2238,7 +2186,74 @@ public class SydApi4j implements SydApi {
|
|||||||
return rw;
|
return rw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 当证书模式为证书序号时,测试成功
|
||||||
// 测试通过
|
// 测试通过
|
||||||
|
@Override
|
||||||
|
public RetWrap generateDEByDn(byte[] dn, int alg, int model) {
|
||||||
|
return generateDE(dn, alg, model, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RetWrap generateDEByDn(byte[] certSerial, String oData) {
|
||||||
|
return generateDE(certSerial, 3, 1, oData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RetWrap generateDE(byte[] certSerial, int alg, int model, String oData) {
|
||||||
|
Proto6A proto = new Proto6A();
|
||||||
|
// 填充数据
|
||||||
|
PacketSN sn = PacketSN.gen();
|
||||||
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
|
packet.put("header", sn.getSn().array());
|
||||||
|
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||||
|
data.put("alg$option", alg);
|
||||||
|
data.put("certificateModel$option", model);
|
||||||
|
|
||||||
|
if (model == 0) {
|
||||||
|
data.put("certificateSn", certSerial);
|
||||||
|
} else {
|
||||||
|
data.put("certificateDn", certSerial);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alg == 3) {
|
||||||
|
data.put("orgData", oData);
|
||||||
|
}
|
||||||
|
|
||||||
|
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<String, Object> ret = p.toMap();
|
||||||
|
if (
|
||||||
|
!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())
|
||||||
|
) {
|
||||||
|
throw new SydApiException("包序号不匹配", -4);
|
||||||
|
}
|
||||||
|
ret = (Map<String, Object>) 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
|
@Override
|
||||||
public RetWrap decryptDE(String certSerial, String pCipherKey) {
|
public RetWrap decryptDE(String certSerial, String pCipherKey) {
|
||||||
// 获取协议
|
// 获取协议
|
||||||
@ -2292,6 +2307,78 @@ public class SydApi4j implements SydApi {
|
|||||||
return rw;
|
return rw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RetWrap decryptDEByDN(byte[] certSerial, String pCipherKey) {
|
||||||
|
return decryptDE(true, 1, certSerial, pCipherKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 测试通过
|
||||||
|
@Override
|
||||||
|
public RetWrap decryptDE(boolean pFlag, int model, byte[] certSerial, String pCipherKey) {
|
||||||
|
// 获取协议
|
||||||
|
//ProtocolRender render = pset.getProtocolReqRender("6B");
|
||||||
|
// 与6B相同
|
||||||
|
Proto6BXF proto = new Proto6BXF();
|
||||||
|
// 填充数据
|
||||||
|
PacketSN sn = PacketSN.gen();
|
||||||
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
|
packet.put("header", sn.getSn().array());
|
||||||
|
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||||
|
if (pFlag) {
|
||||||
|
data.put("pFlag", "P");
|
||||||
|
}
|
||||||
|
data.put("certificateModel$option", model);
|
||||||
|
|
||||||
|
if (model == 0) {
|
||||||
|
data.put("certificateSn", certSerial);
|
||||||
|
} else {
|
||||||
|
data.put("certificateDn", 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<String, Object> ret = p.toMap();
|
||||||
|
if (
|
||||||
|
!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())
|
||||||
|
) {
|
||||||
|
throw new SydApiException("包序号不匹配", -4);
|
||||||
|
}
|
||||||
|
ret = (Map<String, Object>) 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();
|
||||||
|
|
||||||
|
if (pFlag) {
|
||||||
|
rw.put("oData", ((PacketSection) ret.get("oData")).getString());
|
||||||
|
}
|
||||||
|
|
||||||
|
int orgCodeLen = Util.a2i(((PacketSection) ret.get("orgCodeLen")).getBytes(), 10);
|
||||||
|
if (orgCodeLen != 0) {
|
||||||
|
rw.put("orgCode", ((PacketSection) ret.get("orgCode")).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
|
@Override
|
||||||
public String GenerateRandom(int nRandomSize) {
|
public String GenerateRandom(int nRandomSize) {
|
||||||
|
|||||||
@ -1353,8 +1353,7 @@ public class TestAllMethods {
|
|||||||
String sessionKey = (String) retWrap.get("SessionKey");
|
String sessionKey = (String) retWrap.get("SessionKey");
|
||||||
String CipherKey = (String) retWrap.get("CipherKey");
|
String CipherKey = (String) retWrap.get("CipherKey");
|
||||||
String KCV = (String) retWrap.get("KCV");
|
String KCV = (String) retWrap.get("KCV");
|
||||||
|
printRetWrap(retWrap);
|
||||||
System.out.println("CipherKey: " + CipherKey);
|
|
||||||
|
|
||||||
RetWrap retWrap1 = api.decryptDE(sn, CipherKey);
|
RetWrap retWrap1 = api.decryptDE(sn, CipherKey);
|
||||||
sessionKey = (String) retWrap1.get("SessionKey");
|
sessionKey = (String) retWrap1.get("SessionKey");
|
||||||
@ -1365,8 +1364,8 @@ public class TestAllMethods {
|
|||||||
// 6B
|
// 6B
|
||||||
@Test
|
@Test
|
||||||
public void testDecryptDE2() {
|
public void testDecryptDE2() {
|
||||||
// String sn = "1004282452";
|
String sn = "1004282452";
|
||||||
String sn = "1FD9F2049860FD072F0CC71B072EBF9952E2784E";
|
// String sn = "1FD9F2049860FD072F0CC71B072EBF9952E2784E";
|
||||||
RetWrap retWrap = api.generateDE(sn, SydApi.ALG_SM4);
|
RetWrap retWrap = api.generateDE(sn, SydApi.ALG_SM4);
|
||||||
String CipherKey = (String) retWrap.get("CipherKey");
|
String CipherKey = (String) retWrap.get("CipherKey");
|
||||||
printRetWrap(retWrap);
|
printRetWrap(retWrap);
|
||||||
@ -1426,6 +1425,20 @@ public class TestAllMethods {
|
|||||||
printRetWrap(retWrap1);
|
printRetWrap(retWrap1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDecryptDE5() throws UnsupportedEncodingException {
|
||||||
|
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||||
|
String oData = "00001111222233";
|
||||||
|
|
||||||
|
RetWrap retWrap = api.generateDEByDn(dn.getBytes("gbk"), oData);
|
||||||
|
String CipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||||
|
String sessionKey = (String) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||||
|
printRetWrap(retWrap);
|
||||||
|
|
||||||
|
RetWrap retWrap1 = api.decryptDEByDN(dn.getBytes("gbk"), CipherKey);
|
||||||
|
printRetWrap(retWrap1);
|
||||||
|
}
|
||||||
|
|
||||||
// 测试通过
|
// 测试通过
|
||||||
// 6C
|
// 6C
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -9,6 +9,11 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import racal.sunyard.main.SydApi4j;
|
import racal.sunyard.main.SydApi4j;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
import static com.sunyard.sydapi.util.PrintUtil.printRetWrap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 衡泰例子
|
* 衡泰例子
|
||||||
*/
|
*/
|
||||||
@ -71,7 +76,7 @@ public class TestHT {
|
|||||||
// 8018
|
// 8018
|
||||||
@Test
|
@Test
|
||||||
public void testAttachedSignAndVerify() {
|
public void testAttachedSignAndVerify() {
|
||||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||||
String orgData = "111111213323143243243";
|
String orgData = "111111213323143243243";
|
||||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||||
System.out.println("签名结果: " + sign);
|
System.out.println("签名结果: " + sign);
|
||||||
@ -82,7 +87,7 @@ public class TestHT {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAttachedSignAndVerifyGetX509() {
|
public void testAttachedSignAndVerifyGetX509() {
|
||||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||||
String orgData = "111111213323143243243";
|
String orgData = "111111213323143243243";
|
||||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||||
System.out.println("签名结果: " + sign);
|
System.out.println("签名结果: " + sign);
|
||||||
@ -93,7 +98,7 @@ public class TestHT {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAttachedSignAndVerifyRD() {
|
public void testAttachedSignAndVerifyRD() {
|
||||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||||
String orgData = "111111213323143243243";
|
String orgData = "111111213323143243243";
|
||||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||||
System.out.println("签名结果: " + sign);
|
System.out.println("签名结果: " + sign);
|
||||||
@ -104,7 +109,7 @@ public class TestHT {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAttachedSignAndVerifyGetAll() {
|
public void testAttachedSignAndVerifyGetAll() {
|
||||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||||
String orgData = "111111213323143243243";
|
String orgData = "111111213323143243243";
|
||||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||||
System.out.println("签名结果: " + sign);
|
System.out.println("签名结果: " + sign);
|
||||||
@ -116,6 +121,20 @@ public class TestHT {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDecryptDE5() throws UnsupportedEncodingException {
|
||||||
|
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||||
|
String oData = "00001111222233";
|
||||||
|
|
||||||
|
RetWrap retWrap = api.generateDEByDn(dn.getBytes("gbk"), oData);
|
||||||
|
String CipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||||
|
String sessionKey = (String) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||||
|
printRetWrap(retWrap);
|
||||||
|
|
||||||
|
RetWrap retWrap1 = api.decryptDEByDN(dn.getBytes("gbk"), CipherKey);
|
||||||
|
printRetWrap(retWrap1);
|
||||||
|
}
|
||||||
|
|
||||||
// 测试通过
|
// 测试通过
|
||||||
// 76
|
// 76
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user