Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5968c5245 | ||
|
|
73c315f714 | ||
|
|
b74443f38b | ||
|
|
b2d5103176 | ||
|
|
d34d5ff8e0 | ||
|
|
c7324ba414 | ||
|
|
041f992992 | ||
|
|
22b7929e40 | ||
|
|
954e5fb637 | ||
|
|
3abf5021a3 | ||
|
|
dc450dcdb5 | ||
|
|
aacd927fbf | ||
|
|
e18cfab77d |
@@ -11,6 +11,4 @@
|
||||
/.DS_Store
|
||||
src/test/java/com/sunyard/sydapi/sample/*.*
|
||||
*.p7
|
||||
~$*
|
||||
/pack/
|
||||
/.logs/
|
||||
|
||||
+152
-200
@@ -1,233 +1,195 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<packet extend="base">
|
||||
<req>
|
||||
<req>
|
||||
|
||||
<command>
|
||||
<hex>6A</hex>
|
||||
</command>
|
||||
<data extend="data">
|
||||
<alg len="1" cn="算法标识">
|
||||
<options>
|
||||
<option cn="RSA2048_AES256_ECB">
|
||||
<hex>0</hex>
|
||||
</option>
|
||||
<option cn="SM2_SM4_ECB">
|
||||
<hex>1</hex>
|
||||
</option>
|
||||
<option cn="SM2_SM4_ECB 机构码|02|密钥">
|
||||
<hex>2</hex>
|
||||
</option>
|
||||
<option cn="PKCS7_SM2_SM4_ECB">
|
||||
<hex>3</hex>
|
||||
</option>
|
||||
<option cn="RSA2048_AES256_CBC">
|
||||
<hex>4</hex>
|
||||
</option>
|
||||
</options>
|
||||
</alg>
|
||||
<command>
|
||||
<hex>6A</hex>
|
||||
</command>
|
||||
<data extend="data">
|
||||
<alg len="1" cn="算法标识">
|
||||
<options>
|
||||
<option cn="RSA2048_AES256_ECB">
|
||||
<hex>0</hex>
|
||||
</option>
|
||||
<option cn="SM2_SM4_ECB">
|
||||
<hex>1</hex>
|
||||
</option>
|
||||
<option cn="SM2_SM4_ECB 机构码|02|密钥">
|
||||
<hex>2</hex>
|
||||
</option>
|
||||
<option cn="PKCS7_SM2_SM4_ECB">
|
||||
<hex>3</hex>
|
||||
</option>
|
||||
</options>
|
||||
</alg>
|
||||
|
||||
<pFlag len="1" required="false" cn="P标志">
|
||||
可选,存在,则固定值为‘P’
|
||||
</pFlag>
|
||||
<pFlag len="1" required="false" cn="P标志">
|
||||
可选,存在,则固定值为‘P’
|
||||
</pFlag>
|
||||
|
||||
<certificateModel len="1" cn="证书模式">
|
||||
<options>
|
||||
<option cn="证书序号">
|
||||
<hex>0</hex>
|
||||
</option>
|
||||
<option cn="证书 DN">
|
||||
<hex>1</hex>
|
||||
</option>
|
||||
</options>
|
||||
</certificateModel>
|
||||
<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>
|
||||
<certificateLen len="4" :value="certificateLen()" cn="证书内容长度">
|
||||
根据证书模式,需要输入内容项的长度 n
|
||||
</certificateLen>
|
||||
|
||||
|
||||
<certificateSn :len="strlen()" :if="0 == $packet.data.certificateModel$option" cn="X509 证书序号">
|
||||
可选项,只针对“证书模式”为 0时有。
|
||||
</certificateSn>
|
||||
<certificateSn :len="strlen()" :if="0 == $packet.data.certificateModel$option" cn="X509 证书序号">
|
||||
可选项,只针对“证书模式”为 0时有。
|
||||
</certificateSn>
|
||||
|
||||
<certificateDn :len="strlen()" :if="1 == $packet.data.certificateModel$option" cn="X509 证书的 subject">
|
||||
可选项,只针对“证书模式”为 1时有。
|
||||
</certificateDn>
|
||||
<certificateDn :len="strlen()" :if="1 == $packet.data.certificateModel$option" cn="X509 证书的 subject">
|
||||
可选项,只针对“证书模式”为 1时有。
|
||||
</certificateDn>
|
||||
|
||||
<orgDataLen len="4" :value="dataLen()" :if="3 == $packet.data.alg$option||4 == $packet.data.alg$option" cn="数据长度">
|
||||
只针对算法标识为3、4时传入
|
||||
</orgDataLen>
|
||||
<orgDataLen len="4" :value="dataLen()" :if="3 == $packet.data.alg$option" cn="数据长度">
|
||||
只针对算法标识为3时传入
|
||||
</orgDataLen>
|
||||
|
||||
<orgData :if="3 == $packet.data.alg$option||4== $packet.data.alg$option" cn="数据长度">
|
||||
只针对算法标识为3、4时传入
|
||||
</orgData>
|
||||
<orgData :if="3 == $packet.data.alg$option" cn="数据长度">
|
||||
只针对算法标识为3时传入
|
||||
</orgData>
|
||||
|
||||
<keyType len="1" cn="加密密钥方案">
|
||||
LMK 下加密密钥的方案。
|
||||
</keyType>
|
||||
<keyType len="1" cn="加密密钥方案">
|
||||
LMK 下加密密钥的方案。
|
||||
</keyType>
|
||||
|
||||
<orgCodeLen len="2" :value="orgCodeLen()" :if="hasOrgCode()" cn="机构码长度">
|
||||
公钥加密的密钥格式3所需机构码长度,仅当格式3以及'P'存在时存在
|
||||
</orgCodeLen>
|
||||
<orgCodeLen len="2" :value="orgCodeLen()" :if="hasOrgCode()" cn="机构码长度">
|
||||
公钥加密的密钥格式3所需机构码长度,仅当格式3以及'P'存在时存在
|
||||
</orgCodeLen>
|
||||
|
||||
<orgCode :if="hasOrgCode()" cn="机构码长度">
|
||||
公钥加密的密钥格式3所需机构码长度,仅当格式3以及'P'存在时存在
|
||||
</orgCode>
|
||||
<orgCode :if="hasOrgCode()" cn="机构码长度">
|
||||
公钥加密的密钥格式3所需机构码长度,仅当格式3以及'P'存在时存在
|
||||
</orgCode>
|
||||
|
||||
<!-- 新增功能-->
|
||||
<pSignFlag len="1" required="false" cn="可选字段">
|
||||
签名数字信封标识符,存在则为P
|
||||
</pSignFlag>
|
||||
<tailSep len="1" :if=" null != $packet.data.tail " cn="尾分隔">
|
||||
可选项。如果显示消息尾域,则该域必须显示。值为
|
||||
“X’19”。
|
||||
<hex>19</hex>
|
||||
</tailSep>
|
||||
|
||||
<signCertificateLen len="4" :value="signCertificateLen()" :if="hasOrgCN()" cn="签名证书DN长度">
|
||||
可选项,只针对"可选字段"为P时存在。
|
||||
</signCertificateLen>
|
||||
<tail maxLen="32" required="false" cn="尾部">
|
||||
可选项。最大长度为 32个字符。
|
||||
</tail>
|
||||
</data>
|
||||
|
||||
<signCertificateDn :len="strlen()" :if="hasOrgCN()" cn="签名证书DN">
|
||||
可选项,只针对“证书模式”为1时有,只针对"可选字段"为P时存在。
|
||||
</signCertificateDn>
|
||||
<signCertificateModel len="1" :if="hasOrgCN()" cn="是否附带公钥信息">
|
||||
<options>
|
||||
<option cn="无需附带">
|
||||
<hex>0</hex>
|
||||
</option>
|
||||
<option cn="附带公钥信息">
|
||||
<hex>1</hex>
|
||||
</option>
|
||||
</options>
|
||||
</signCertificateModel>
|
||||
</req>
|
||||
|
||||
|
||||
<tailSep len="1" :if=" null != $packet.data.tail " cn="尾分隔">
|
||||
可选项。如果显示消息尾域,则该域必须显示。值为
|
||||
“X’19”。
|
||||
<hex>19</hex>
|
||||
</tailSep>
|
||||
<res>
|
||||
<command>
|
||||
<hex>6B</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="DSP 错误">
|
||||
DSP 错误;报告给管理员。
|
||||
<hex>47</hex>
|
||||
</option>
|
||||
<option cn="密钥块长度错误">
|
||||
<hex>76</hex>
|
||||
</option>
|
||||
<option cn="输入数据长度错误">
|
||||
<hex>80</hex>
|
||||
</option>
|
||||
</options>
|
||||
</error>
|
||||
|
||||
<tail maxLen="32" required="false" cn="尾部">
|
||||
可选项。最大长度为 32个字符。
|
||||
</tail>
|
||||
</data>
|
||||
<keyLen len="4" cn="密钥密文长度">
|
||||
公钥加密的密钥密文长度
|
||||
</keyLen>
|
||||
|
||||
</req>
|
||||
<key :len="getKeyLen()" cn="密钥密文">
|
||||
公钥加密的密钥密文的 BASE64 编码
|
||||
</key>
|
||||
|
||||
<lmkHead len="1" cn="lmk 头">
|
||||
如果是 'L' ,lmk 32 个字节长,否则 lmk 64 个字节长。
|
||||
</lmkHead>
|
||||
|
||||
<res>
|
||||
<command>
|
||||
<hex>6B</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="DSP 错误">
|
||||
DSP 错误;报告给管理员。
|
||||
<hex>47</hex>
|
||||
</option>
|
||||
<option cn="密钥块长度错误">
|
||||
<hex>76</hex>
|
||||
</option>
|
||||
<option cn="输入数据长度错误">
|
||||
<hex>80</hex>
|
||||
</option>
|
||||
</options>
|
||||
</error>
|
||||
<lmk :len="lmkLen()" cn="对称密钥的密文">
|
||||
对称密钥的密文,由 LMK30-31 保护。
|
||||
</lmk>
|
||||
|
||||
<keyLen len="4" cn="密钥密文长度">
|
||||
公钥加密的密钥密文长度
|
||||
</keyLen>
|
||||
<keyCheck len="16" cn="密钥校验值">
|
||||
密钥校验值
|
||||
</keyCheck>
|
||||
|
||||
<key :len="getKeyLen()" cn="密钥密文">
|
||||
公钥加密的密钥密文的 BASE64 编码
|
||||
</key>
|
||||
<tailSep len="1" required="false" cn="尾分隔">
|
||||
可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。
|
||||
<hex>19</hex>
|
||||
</tailSep>
|
||||
|
||||
<lmkHead len="1" cn="lmk 头">
|
||||
如果是 'L' ,lmk 32 个字节长,否则 lmk 64 个字节长。
|
||||
</lmkHead>
|
||||
|
||||
<lmk :len="lmkLen()" cn="对称密钥的密文">
|
||||
对称密钥的密文,由 LMK30-31 保护。
|
||||
</lmk>
|
||||
|
||||
<keyCheck len="16" cn="密钥校验值">
|
||||
密钥校验值
|
||||
</keyCheck>
|
||||
|
||||
<tailSep len="1" required="false" cn="尾分隔">
|
||||
可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。
|
||||
<hex>19</hex>
|
||||
</tailSep>
|
||||
|
||||
<tail maxLen="32" required="false" cn="尾部">
|
||||
可选项。最大长度为 32个字符。
|
||||
</tail>
|
||||
</data>
|
||||
<tail maxLen="32" required="false" cn="尾部">
|
||||
可选项。最大长度为 32个字符。
|
||||
</tail>
|
||||
</data>
|
||||
|
||||
|
||||
|
||||
</res>
|
||||
<script>
|
||||
</res>
|
||||
<script>
|
||||
function certificateLen(){
|
||||
var data = $packet.data;
|
||||
if( 0 == data.certificateModel$option ){
|
||||
return data.certificateSn.length
|
||||
var data = $packet.data;
|
||||
if( 0 == data.certificateModel$option ){
|
||||
return data.certificateSn.length
|
||||
}
|
||||
if( 1 == data.certificateModel$option ){
|
||||
return data.certificateDn.length
|
||||
}
|
||||
}
|
||||
if( 1 == data.certificateModel$option ){
|
||||
return data.certificateDn.length
|
||||
}
|
||||
}
|
||||
|
||||
function signCertificateLen(){
|
||||
var data = $packet.data;
|
||||
if( 'P' == $packet.data.pSignFlag ){
|
||||
return data.signCertificateDn.length
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
function getKeyLen() {
|
||||
return Util.a2i( $final.getSection('data').getSection('keyLen') );
|
||||
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;
|
||||
}
|
||||
if( Arrays.equals("L".getBytes(),
|
||||
$final.getSection('data').getSection('lmkHead').getValue()
|
||||
) ){
|
||||
return 64
|
||||
}else{
|
||||
return 32
|
||||
}
|
||||
}
|
||||
|
||||
function dataLen() {
|
||||
return $packet.data.orgData.length
|
||||
return $packet.data.orgData.length()
|
||||
}
|
||||
|
||||
|
||||
|
||||
<![CDATA[
|
||||
function hasOrgCode() {
|
||||
if(2 == $packet.data.alg$option && 'P' == $packet.data.pFlag) {
|
||||
@@ -237,21 +199,11 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function hasOrgCN() {
|
||||
if(1 == $packet.data.certificateModel$option && 'P' == $packet.data.pSignFlag) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function orgCodeLen() {
|
||||
def len = $packet.data.orgCode.length();
|
||||
def data = new byte[2];
|
||||
data[0] = (byte)(len >> 8 & 0xFF);
|
||||
data[1] = (byte)(len & 0xFF);
|
||||
data[0] = (byte)(len >> 8 & 0xFF)
|
||||
data[1] = (byte)(len & 0xFF)
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
+9
-40
@@ -11,18 +11,6 @@
|
||||
可选,如果输入P代表使用PKCS7_SM2_SM4_ECB模式解密数字信封
|
||||
</pFlag>
|
||||
|
||||
|
||||
<!--新增-->
|
||||
<pSignFlag len="1" required="false" if="'P' == $packet.data.pFlag" cn="可选字段2">
|
||||
如果输入P代表进行解封签名数字信封模式,必须当可选字段1为P时才可选
|
||||
</pSignFlag>
|
||||
<signCertificateLen len="4" :value="signCertificateLen()" if="'P' == $packet.data.pSignFlag" cn="签名证书内容长度">
|
||||
根据证书模式,需要输入内容项的长度n,只针对可选字段2为P时存在
|
||||
</signCertificateLen>
|
||||
<signCertificateDn :if="hasSign()" cn="签名证书DN">
|
||||
X509证书的subject可选项,只针对“证书模式”为1时有,只针对可选字段2为P时存在
|
||||
</signCertificateDn>
|
||||
|
||||
<certificateModel len="1" cn="证书模式">
|
||||
<options>
|
||||
<option cn="证书序号">
|
||||
@@ -48,16 +36,14 @@
|
||||
可选项,只针对“证书模式”为 1时有。
|
||||
</certificateDn>
|
||||
|
||||
|
||||
|
||||
<keyLen len="4" :value="keyLen()" cn="密钥密文长度">
|
||||
公钥加密的密钥密文长度
|
||||
</keyLen>
|
||||
|
||||
<key :len="getKeyLen()" cn="密钥密文">
|
||||
公钥加密的密钥密文的 BASE64 编码
|
||||
</key>
|
||||
|
||||
|
||||
<keyType len="1" cn="加密密钥方案">
|
||||
LMK 下加密密钥的方案。
|
||||
</keyType>
|
||||
@@ -71,8 +57,6 @@
|
||||
<tail maxLen="32" required="false" cn="尾部">
|
||||
可选项。最大长度为 32个字符。
|
||||
</tail>
|
||||
|
||||
|
||||
</data>
|
||||
|
||||
</req>
|
||||
@@ -142,7 +126,7 @@
|
||||
对称密钥的密文,由 LMK30-31 保护。
|
||||
</lmk>
|
||||
|
||||
<keyCheck len="32" cn="密钥校验值">
|
||||
<keyCheck len="16" cn="密钥校验值">
|
||||
密钥校验值
|
||||
</keyCheck>
|
||||
|
||||
@@ -171,30 +155,15 @@
|
||||
function certificateLen(){
|
||||
var data = $packet.data;
|
||||
if( 0 == data.certificateModel$option ){
|
||||
return data.certificateSn.length
|
||||
return data.certificateSn.length()
|
||||
}
|
||||
if( 1 == data.certificateModel$option ){
|
||||
return data.certificateDn.length
|
||||
return data.certificateDn.length()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function signCertificateLen(){
|
||||
var data = $packet.data;
|
||||
return data.signCertificateDn.length
|
||||
}
|
||||
<![CDATA[
|
||||
function hasSign() {
|
||||
if(1 == $packet.data.certificateModel$option && 'P' == $packet.data.pSignFlag) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
]]>
|
||||
|
||||
|
||||
function keyLen() {
|
||||
return $packet.data.key.length;
|
||||
return $packet.data.key.length()
|
||||
}
|
||||
|
||||
|
||||
@@ -206,17 +175,17 @@
|
||||
if( Arrays.equals("L".getBytes(),
|
||||
$final.getSection('data').getSection('lmkHead').getValue()
|
||||
) ){
|
||||
return 64;
|
||||
return 64
|
||||
}else{
|
||||
return 32;
|
||||
return 32
|
||||
}
|
||||
}
|
||||
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') );
|
||||
return Util.a2i( $final.getSection('data').getSection('oDataLen') )
|
||||
}
|
||||
</script>
|
||||
</packet>
|
||||
|
||||
@@ -1,191 +0,0 @@
|
||||
<?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>
|
||||
@@ -6,9 +6,6 @@
|
||||
<hex>72</hex>
|
||||
</command>
|
||||
<data extend="data">
|
||||
<pFlag len="1" required="false" cn="RSA标志符">
|
||||
可选,存在,则固定值为‘R’
|
||||
</pFlag>
|
||||
|
||||
<publicKeyLength len="4" :value="publicKeyLen()" cn="公钥长度">
|
||||
公钥长度
|
||||
|
||||
+1
-12
@@ -75,7 +75,7 @@
|
||||
</error>
|
||||
|
||||
|
||||
<hash :len="hashLen()" :if="0 == $packet.data.packSn$option || 3 == $packet.data.packSn$option" cn="hash"></hash>
|
||||
<hash len="32" :if="0 == $packet.data.packSn$option || 3 == $packet.data.packSn$option" cn="hash"></hash>
|
||||
|
||||
<filterDataLen len="4" :value="filterDataLength()" :if="2 == $packet.data.packSn$option || 1 == $packet.data.packSn$option" cn="过渡数据长度">
|
||||
只对“消息块号”为 2、1 时有效
|
||||
@@ -108,17 +108,6 @@ function filterDataLength(){
|
||||
var data = $packet.data;
|
||||
return data.filterData.length;
|
||||
}
|
||||
function hashLen(){
|
||||
if (0 == $packet.data.hashType$option){
|
||||
return 20;
|
||||
}
|
||||
if (1== $packet.data.hashType$option){
|
||||
return 32;
|
||||
}
|
||||
if (2 == $packet.data.hashType$option){
|
||||
return 16;
|
||||
}
|
||||
}
|
||||
|
||||
function getFilterDataLen() {
|
||||
return Util.a2i( $final.getSection('data').getSection('filterDataLen') )
|
||||
|
||||
+96
-116
@@ -1,137 +1,117 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<packet extend="base">
|
||||
<req>
|
||||
<req>
|
||||
|
||||
<command>
|
||||
<bin>8003</bin>
|
||||
</command>
|
||||
<data extend="data">
|
||||
<command>
|
||||
<bin>8003</bin>
|
||||
</command>
|
||||
<data extend="data">
|
||||
<signatureDataType len="1" cn="获取公私钥标记位">
|
||||
<options>
|
||||
<option cn="索引方式">
|
||||
<bin>00</bin>
|
||||
</option>
|
||||
<option cn="DN 方式">
|
||||
<bin>01</bin>
|
||||
</option>
|
||||
</options>
|
||||
</signatureDataType>
|
||||
|
||||
<algFlag len="1" :value="algFlag()" cn="算法标记">
|
||||
</algFlag>
|
||||
<DN cn="DN 或 DN索引">
|
||||
若上面的标志为1,则此域为证书DN,若为0,则此域为两个字节的证书索引;
|
||||
</DN>
|
||||
|
||||
<signatureDataType len="1" cn="获取公私钥标记位">
|
||||
<options>
|
||||
<option cn="索引方式">
|
||||
<bin>00</bin>
|
||||
</option>
|
||||
<option cn="DN 方式">
|
||||
<bin>01</bin>
|
||||
</option>
|
||||
</options>
|
||||
</signatureDataType>
|
||||
<dataLength len="2" :value="dataLen()" cn="待签名数据长度">
|
||||
待签名数据长度
|
||||
</dataLength>
|
||||
|
||||
<DN cn="DN 或 DN索引">
|
||||
若上面的标志为1,则此域为证书DN,若为0,则此域为两个字节的证书索引;
|
||||
</DN>
|
||||
<signData cn="待签名数据">
|
||||
待签名数据
|
||||
</signData>
|
||||
|
||||
<hashFlag len="1" :if="null != $packet.data.hash" :value="flag()" cn="外部 hash 标记">
|
||||
</hashFlag>
|
||||
|
||||
<hash len="32" :if="null != $packet.data.hash" cn="外部 hash">
|
||||
</hash>
|
||||
|
||||
<dataLength len="2" :value="dataLen()" :if="null == $packet.data.hash" cn="待签名数据长度">
|
||||
待签名数据长度
|
||||
</dataLength>
|
||||
|
||||
<signData cn="待签名数据" :if="null == $packet.data.hash">
|
||||
待签名数据
|
||||
</signData>
|
||||
|
||||
</data>
|
||||
</data>
|
||||
|
||||
|
||||
|
||||
</req>
|
||||
<res>
|
||||
</req>
|
||||
<res>
|
||||
|
||||
<command>
|
||||
<bin>8004</bin>
|
||||
</command>
|
||||
<data>
|
||||
<error len="2" cn="错误码" format="X" :catch="catchError('%s')">
|
||||
<options>
|
||||
<option cn="无错误">
|
||||
<hex>00</hex>
|
||||
</option>
|
||||
<option cn="无效的私钥类型">
|
||||
<hex>03</hex>
|
||||
</option>
|
||||
<option cn="无效私钥标记">
|
||||
<hex>04</hex>
|
||||
</option>
|
||||
<option cn="无效的哈希标识">
|
||||
<hex>05</hex>
|
||||
</option>
|
||||
<option cn="无效的签名标识">
|
||||
<hex>06</hex>
|
||||
</option>
|
||||
<option cn="无效的附加标识">
|
||||
<hex>07</hex>
|
||||
</option>
|
||||
<option cn="LMK 错误">
|
||||
LMK 错误;报告给管理员。
|
||||
<hex>13</hex>
|
||||
</option>
|
||||
<option cn="输入数据错">
|
||||
<hex>15</hex>
|
||||
</option>
|
||||
<option cn="DSP 错误">
|
||||
DSP 错误;报告给管理员。
|
||||
<hex>47</hex>
|
||||
</option>
|
||||
<option cn="私钥错误">
|
||||
私钥错误;报告给管理员。
|
||||
<hex>49</hex>
|
||||
</option>
|
||||
<option cn="无效摘要信息语法(仅仅无哈希模式)">
|
||||
<hex>74</hex>
|
||||
</option>
|
||||
<option cn="公钥长度错误">
|
||||
<hex>76</hex>
|
||||
</option>
|
||||
<option cn="私钥长度错误">
|
||||
<hex>78</hex>
|
||||
</option>
|
||||
<option cn="输入数据长度错误">
|
||||
<hex>80</hex>
|
||||
</option>
|
||||
</options>
|
||||
</error>
|
||||
<command>
|
||||
<bin>8004</bin>
|
||||
</command>
|
||||
<data>
|
||||
<error len="2" cn="错误码" format="X" :catch="catchError('%s')">
|
||||
<options>
|
||||
<option cn="无错误">
|
||||
<hex>00</hex>
|
||||
</option>
|
||||
<option cn="无效的私钥类型">
|
||||
<hex>03</hex>
|
||||
</option>
|
||||
<option cn="无效私钥标记">
|
||||
<hex>04</hex>
|
||||
</option>
|
||||
<option cn="无效的哈希标识">
|
||||
<hex>05</hex>
|
||||
</option>
|
||||
<option cn="无效的签名标识">
|
||||
<hex>06</hex>
|
||||
</option>
|
||||
<option cn="无效的附加标识">
|
||||
<hex>07</hex>
|
||||
</option>
|
||||
<option cn="LMK 错误">
|
||||
LMK 错误;报告给管理员。
|
||||
<hex>13</hex>
|
||||
</option>
|
||||
<option cn="输入数据错">
|
||||
<hex>15</hex>
|
||||
</option>
|
||||
<option cn="DSP 错误">
|
||||
DSP 错误;报告给管理员。
|
||||
<hex>47</hex>
|
||||
</option>
|
||||
<option cn="私钥错误">
|
||||
私钥错误;报告给管理员。
|
||||
<hex>49</hex>
|
||||
</option>
|
||||
<option cn="无效摘要信息语法(仅仅无哈希模式)">
|
||||
<hex>74</hex>
|
||||
</option>
|
||||
<option cn="公钥长度错误">
|
||||
<hex>76</hex>
|
||||
</option>
|
||||
<option cn="私钥长度错误">
|
||||
<hex>78</hex>
|
||||
</option>
|
||||
<option cn="输入数据长度错误">
|
||||
<hex>80</hex>
|
||||
</option>
|
||||
</options>
|
||||
</error>
|
||||
|
||||
<signatureLen len="2" cn="签名的字节长度">
|
||||
签名的字节长度
|
||||
</signatureLen>
|
||||
<signatureLen len="2" cn="签名的字节长度">
|
||||
签名的字节长度
|
||||
</signatureLen>
|
||||
|
||||
<signature :len="signatureLen()" cn="签名的 DER 编码">
|
||||
签名的 DER 编码
|
||||
</signature>
|
||||
<signature :len="signatureLen()" cn="签名的 DER 编码">
|
||||
签名的 DER 编码
|
||||
</signature>
|
||||
|
||||
<tailSep len="1" required="false" cn="尾分隔">
|
||||
可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。
|
||||
<hex>19</hex>
|
||||
</tailSep>
|
||||
<tailSep len="1" required="false" cn="尾分隔">
|
||||
可选项。如果显示消息尾域,则该域必须显示。值为 “X’19”。
|
||||
<hex>19</hex>
|
||||
</tailSep>
|
||||
|
||||
<tail maxLen="32" required="false" cn="尾部">
|
||||
可选项。最大长度为 32个字符。
|
||||
</tail>
|
||||
</data>
|
||||
<tail maxLen="32" required="false" cn="尾部">
|
||||
可选项。最大长度为 32个字符。
|
||||
</tail>
|
||||
</data>
|
||||
|
||||
|
||||
|
||||
</res>
|
||||
<script type="javascript"><![CDATA[
|
||||
function algFlag(){
|
||||
if( 'P' == $packet.data.rFlag ) {
|
||||
return ''
|
||||
} else {
|
||||
$packet.data.rFlag
|
||||
}
|
||||
}
|
||||
function flag(){
|
||||
return $packet.data.rFlag;
|
||||
}
|
||||
</res>
|
||||
<script type="javascript"><![CDATA[
|
||||
function dataLen(){
|
||||
def len = $packet.data.signData.length
|
||||
def ret = new byte[2]
|
||||
|
||||
+107
-127
@@ -1,152 +1,132 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<packet extend="base">
|
||||
<req>
|
||||
<req>
|
||||
|
||||
<command>
|
||||
<bin>8004</bin>
|
||||
</command>
|
||||
<data extend="data">
|
||||
<command>
|
||||
<bin>8004</bin>
|
||||
</command>
|
||||
<data extend="data">
|
||||
<signatureDataType len="1" cn="获取公私钥标记位">
|
||||
<options>
|
||||
<option cn="索引方式">
|
||||
<bin>00</bin>
|
||||
</option>
|
||||
<option cn="DN 方式">
|
||||
<bin>01</bin>
|
||||
</option>
|
||||
<option cn="通过机构号获取">
|
||||
<bin>02</bin>
|
||||
</option>
|
||||
</options>
|
||||
</signatureDataType>
|
||||
|
||||
<algFlag len="1" :value="algFlag()" cn="算法标记">
|
||||
</algFlag>
|
||||
<DN :if="useDN()" cn="DN 或 DN索引">
|
||||
若上面的标志为1,则此域为证书DN,若为0,则此域为两个字节的证书索引;若为2,该域不存在
|
||||
</DN>
|
||||
|
||||
<signatureDataType len="1" cn="获取公私钥标记位">
|
||||
<options>
|
||||
<option cn="索引方式">
|
||||
<bin>00</bin>
|
||||
</option>
|
||||
<option cn="DN 方式">
|
||||
<bin>01</bin>
|
||||
</option>
|
||||
<option cn="通过机构号获取">
|
||||
<bin>02</bin>
|
||||
</option>
|
||||
</options>
|
||||
</signatureDataType>
|
||||
<organizationNumLen len="2" :if="useOrganization()" :value="bNumberLength()" cn="机构号长度">
|
||||
标志为2 时存在
|
||||
</organizationNumLen>
|
||||
|
||||
<DN :if="useDN()" cn="DN 或 DN索引">
|
||||
若上面的标志为1,则此域为证书DN,若为0,则此域为两个字节的证书索引;若为2,该域不存在
|
||||
</DN>
|
||||
<organizationNum :if="useOrganization()" cn="机构号内容">
|
||||
标志为2 时存在
|
||||
</organizationNum>
|
||||
|
||||
<organizationNumLen len="2" :if="useOrganization()" :value="bNumberLength()" cn="机构号长度">
|
||||
标志为2 时存在
|
||||
</organizationNumLen>
|
||||
|
||||
<organizationNum :if="useOrganization()" cn="机构号内容">
|
||||
标志为2 时存在
|
||||
</organizationNum>
|
||||
<dataLength len="2" :value="dataLen()" cn="待签名数据长度">
|
||||
待签名数据长度
|
||||
</dataLength>
|
||||
|
||||
<hashFlag len="1" :if="null != $packet.data.hash" :value="flag()" cn="外部 hash 标记">
|
||||
</hashFlag>
|
||||
<odata cn="待签名数据">
|
||||
待签名数据
|
||||
</odata>
|
||||
|
||||
<hash len="32" :if="null != $packet.data.hash" cn="外部 hash">
|
||||
</hash>
|
||||
<signatureLen len="2" :value="signLen()" cn="签名的字节长度">
|
||||
签名的字节长度
|
||||
</signatureLen>
|
||||
|
||||
<dataLength len="2" :if="null == $packet.data.hash" :value="dataLen()" cn="待签名数据长度">
|
||||
待签名数据长度
|
||||
</dataLength>
|
||||
<signature :len="signatureLen()" cn="已签名数据">
|
||||
待验签的已签名数据,若为RSA签名则为相应长度的签名数据,若为SM2签名,则前半部分为R.后面半部分为S;
|
||||
</signature>
|
||||
|
||||
<odata cn="待签名数据" :if="null == $packet.data.hash">
|
||||
待签名数据
|
||||
</odata>
|
||||
|
||||
<signatureLen len="2" :value="signLen()" cn="签名的字节长度">
|
||||
签名的字节长度
|
||||
</signatureLen>
|
||||
|
||||
<signature :len="signatureLen()" cn="已签名数据">
|
||||
待验签的已签名数据,若为RSA签名则为相应长度的签名数据,若为SM2签名,则前半部分为R.后面半部分为S;
|
||||
</signature>
|
||||
|
||||
<returnSign len="2" cn="返回证书信息标志">
|
||||
<options>
|
||||
<option cn="不返回">
|
||||
<bin>0000</bin>
|
||||
</option>
|
||||
<option cn="返回">
|
||||
<bin>0001</bin>
|
||||
</option>
|
||||
</options>
|
||||
</returnSign>
|
||||
</data>
|
||||
<returnSign len="2" cn="返回证书信息标志">
|
||||
<options>
|
||||
<option cn="不返回">
|
||||
<bin>0000</bin>
|
||||
</option>
|
||||
<option cn="返回">
|
||||
<bin>0001</bin>
|
||||
</option>
|
||||
</options>
|
||||
</returnSign>
|
||||
</data>
|
||||
|
||||
|
||||
|
||||
</req>
|
||||
<res>
|
||||
</req>
|
||||
<res>
|
||||
|
||||
<command>
|
||||
<bin>8005</bin>
|
||||
</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="DSP 错误">
|
||||
DSP 错误;报告给管理员。
|
||||
<hex>47</hex>
|
||||
</option>
|
||||
<option cn="私钥错误">
|
||||
私钥错误;报告给管理员。
|
||||
<hex>49</hex>
|
||||
</option>
|
||||
<option cn="密钥块长度错误">
|
||||
<hex>76</hex>
|
||||
</option>
|
||||
<option cn="输入数据长度错误">
|
||||
<hex>80</hex>
|
||||
</option>
|
||||
</options>
|
||||
</error>
|
||||
<command>
|
||||
<bin>8005</bin>
|
||||
</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="DSP 错误">
|
||||
DSP 错误;报告给管理员。
|
||||
<hex>47</hex>
|
||||
</option>
|
||||
<option cn="私钥错误">
|
||||
私钥错误;报告给管理员。
|
||||
<hex>49</hex>
|
||||
</option>
|
||||
<option cn="密钥块长度错误">
|
||||
<hex>76</hex>
|
||||
</option>
|
||||
<option cn="输入数据长度错误">
|
||||
<hex>80</hex>
|
||||
</option>
|
||||
</options>
|
||||
</error>
|
||||
|
||||
<infoLen len="2" cn="信息长度" :if="0 != $packet.data.returnSign$option">
|
||||
信息长度
|
||||
</infoLen>
|
||||
<infoLen len="2" cn="信息长度" :if="0 != $packet.data.returnSign$option">
|
||||
信息长度
|
||||
</infoLen>
|
||||
|
||||
<info :len="getInfoLen()" cn="信息" :if="0 != $packet.data.returnSign$option">
|
||||
若发送报文返回证书信息标志位为0,则返回一段垃圾数据,可以不用管
|
||||
若发送报文返回证书信息标志位为1,则返回 CERT_INFO 结构的证书数据
|
||||
</info>
|
||||
<info :len="getInfoLen()" cn="信息" :if="0 != $packet.data.returnSign$option">
|
||||
若发送报文返回证书信息标志位为0,则返回一段垃圾数据,可以不用管
|
||||
若发送报文返回证书信息标志位为1,则返回 CERT_INFO 结构的证书数据
|
||||
</info>
|
||||
|
||||
</data>
|
||||
</data>
|
||||
|
||||
|
||||
|
||||
</res>
|
||||
<script><![CDATA[
|
||||
function algFlag(){
|
||||
if( 'P' == $packet.data.rFlag ) {
|
||||
return ''
|
||||
} else {
|
||||
$packet.data.rFlag
|
||||
}
|
||||
}
|
||||
function flag(){
|
||||
return $packet.data.rFlag;
|
||||
}
|
||||
|
||||
function dataLen(){
|
||||
</res>
|
||||
<script><![CDATA[
|
||||
function dataLen(){
|
||||
def len = $packet.data.odata.length
|
||||
def ret = new byte[2]
|
||||
ret[0] = (byte)(len >> 8 & 0xFF)
|
||||
|
||||
+3
-6
@@ -6,9 +6,6 @@
|
||||
<bin>8005</bin>
|
||||
</command>
|
||||
<data extend="data">
|
||||
<rFlag len="1" required="false" cn="RSA算法标志">
|
||||
可选,存在,则固定值为‘P’
|
||||
</rFlag>
|
||||
|
||||
<DN len="256" cn="证书 DN">
|
||||
X509证书序号
|
||||
@@ -16,13 +13,13 @@
|
||||
|
||||
<hashFlag cn="是否为 hash 模式" len="1" required="false"></hashFlag>
|
||||
|
||||
<hash cn="hash 值" :if="null != $packet.data.hashFlag"></hash>
|
||||
<hash cn="hash 值" :if="'P' == $packet.data.hashFlag"></hash>
|
||||
|
||||
<dataLen :if="null == $packet.data.hashFlag" len="2" format="X" :value="dataLength()" cn="数据长度">
|
||||
<dataLen :if="'P' != $packet.data.hashFlag" len="2" format="X" :value="dataLength()" cn="数据长度">
|
||||
数据长度
|
||||
</dataLen>
|
||||
|
||||
<infoData :if="null == $packet.data.hashFlag" cn="数据">
|
||||
<infoData :if="'P' != $packet.data.hashFlag" cn="数据">
|
||||
数据
|
||||
</infoData>
|
||||
|
||||
|
||||
+4
-6
@@ -6,18 +6,16 @@
|
||||
<bin>8006</bin>
|
||||
</command>
|
||||
<data extend="data">
|
||||
<rFlag len="1" required="false" cn="RSA算法标志">
|
||||
可选,存在,则固定值为‘P’
|
||||
</rFlag>
|
||||
|
||||
<hashFlag cn="是否为 hash 模式" len="1" required="false"></hashFlag>
|
||||
|
||||
<hash cn="hash 值" :if="null != $packet.data.hashFlag"></hash>
|
||||
<hash cn="hash 值" :if="'P' == $packet.data.hashFlag"></hash>
|
||||
|
||||
<originLen :if=" null == $packet.data.hashFlag" len="2" :value="orginLength()" cn="待签名数据长度">
|
||||
<originLen :if="'P' != $packet.data.hashFlag" len="2" :value="orginLength()" cn="待签名数据长度">
|
||||
待签名数据长度
|
||||
</originLen>
|
||||
|
||||
<originData :if="null == $packet.data.hashFlag" cn="待签名数据">
|
||||
<originData :if="'P' != $packet.data.hashFlag" cn="待签名数据">
|
||||
待签名数据
|
||||
</originData>
|
||||
|
||||
|
||||
+16
-4
@@ -7,9 +7,18 @@
|
||||
</command>
|
||||
<data extend="data">
|
||||
|
||||
<dataFlag len="4" cn="数据包标志">
|
||||
0:起始包
|
||||
其他:传入上一个包返回的数据标志
|
||||
<dataFlag len="1" cn="数据包标志">
|
||||
<options>
|
||||
<option cn="起始包">
|
||||
<bin>00</bin>
|
||||
</option>
|
||||
<option cn="中间包">
|
||||
<bin>01</bin>
|
||||
</option>
|
||||
<option cn="结束包">
|
||||
<bin>02</bin>
|
||||
</option>
|
||||
</options>
|
||||
</dataFlag>
|
||||
|
||||
<sqlite3 cn="Sqlite3 查询条件">
|
||||
@@ -66,7 +75,10 @@
|
||||
</error>
|
||||
|
||||
<dataFlag len="4" cn="数据包标志">
|
||||
已返回证书个数
|
||||
0:起始包
|
||||
1:中间包
|
||||
2:结束包
|
||||
(可能hi因为字节对此,后三字节为垃圾值)
|
||||
</dataFlag>
|
||||
|
||||
<certAllNum len="4" cn="证书总数">
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<packet extend="base">
|
||||
<req>
|
||||
|
||||
<command>
|
||||
<bin>8011</bin>
|
||||
</command>
|
||||
<data extend="data">
|
||||
|
||||
<certDn cn="证书dn">
|
||||
</certDn>
|
||||
|
||||
</data>
|
||||
</req>
|
||||
<res>
|
||||
|
||||
<command>
|
||||
<bin>8012</bin>
|
||||
</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="DSP 错误">
|
||||
DSP 错误;报告给管理员。
|
||||
<hex>47</hex>
|
||||
</option>
|
||||
<option cn="私钥错误">
|
||||
私钥错误;报告给管理员。
|
||||
<hex>49</hex>
|
||||
</option>
|
||||
<option cn="密钥块长度错误">
|
||||
<hex>76</hex>
|
||||
</option>
|
||||
<option cn="输入数据长度错误">
|
||||
<hex>80</hex>
|
||||
</option>
|
||||
</options>
|
||||
</error>
|
||||
</data>
|
||||
</res>
|
||||
<script> </script>
|
||||
</packet>
|
||||
@@ -5,9 +5,6 @@
|
||||
<bin>8018</bin>
|
||||
</command>
|
||||
<data extend="data">
|
||||
<rFlag len="1" required="false" cn="RSA标志">
|
||||
可选,存在,则固定值为‘P’
|
||||
</rFlag>
|
||||
|
||||
<DN len="256" cn="证书 DN">
|
||||
X509证书序号
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<packet extend="base">
|
||||
<req>
|
||||
|
||||
<command>
|
||||
<hex>GN</hex>
|
||||
</command>
|
||||
<data extend="data">
|
||||
|
||||
<Esign len="1" cn="E值">
|
||||
<text>1</text>
|
||||
</Esign>
|
||||
|
||||
<keyLen len="4" cn="密钥长度">
|
||||
<text>2048</text>
|
||||
</keyLen>
|
||||
|
||||
|
||||
<sk len="27" cn="私钥索引"></sk>
|
||||
|
||||
<startTime len="8" cn="启用时间"></startTime>
|
||||
|
||||
<endTime len="8" cn="到期时间"></endTime>
|
||||
|
||||
</data>
|
||||
|
||||
|
||||
|
||||
</req>
|
||||
<res>
|
||||
|
||||
<command>
|
||||
<hex>QO</hex>
|
||||
</command>
|
||||
<data>
|
||||
<error len="2" cn="错误码" format="X" :catch="catchError('%s')">
|
||||
<options>
|
||||
<option cn="无错误">
|
||||
<hex>00</hex>
|
||||
</option>
|
||||
<option cn="无效的哈希标识">
|
||||
<hex>05</hex>
|
||||
</option>
|
||||
<option cn="输入数据错">
|
||||
<hex>15</hex>
|
||||
</option>
|
||||
<option cn="DSP 错误">
|
||||
DSP 错误;报告给管理员。
|
||||
<hex>47</hex>
|
||||
</option>
|
||||
<option cn="输入数据长度错误">
|
||||
<hex>80</hex>
|
||||
</option>
|
||||
</options>
|
||||
</error>
|
||||
|
||||
<pk len="270" cn="公钥"></pk>
|
||||
<sk len="2824" cn="私钥"></sk>
|
||||
|
||||
</data>
|
||||
|
||||
|
||||
|
||||
</res>
|
||||
<script> </script>
|
||||
</packet>
|
||||
@@ -0,0 +1 @@
|
||||
~$*
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,16 +1,16 @@
|
||||
{
|
||||
"vars": {
|
||||
"version": "%project.git_branch_version%",
|
||||
"out_path": "./pack"
|
||||
"out_path": "./pack",
|
||||
"target_f1": "./target/sydapi4j-jar-with-dependencies.jar",
|
||||
"target_t1": "%out_path%/sydapi4j-jar-with-dependencies.jar",
|
||||
"target_f2": "./target/sydapi4j.jar",
|
||||
"target_t2": "%out_path%/sydapi4j.jar"
|
||||
},
|
||||
"clear": [
|
||||
{
|
||||
"func": "rm",
|
||||
"func": "rmdir",
|
||||
"path": "%out_path%"
|
||||
},
|
||||
{
|
||||
"func": "rm",
|
||||
"path": "./logs"
|
||||
}
|
||||
],
|
||||
"init": [
|
||||
@@ -31,15 +31,19 @@
|
||||
"path": "%out_path%/doc"
|
||||
}
|
||||
],
|
||||
"dependencies": [{
|
||||
"func" : "pom",
|
||||
"xml" : "%out_path%/jar"
|
||||
}, {
|
||||
"shell" : "mvn dependency:copy-dependencies -DincludeScope=runtime -DoutputDirectory=%out_path%/jar/dependences",
|
||||
"check": "BUILD SUCCESS"
|
||||
}],
|
||||
"gen" : [{
|
||||
"cmd" : "dproto"
|
||||
"shell" : "dproto"
|
||||
}],
|
||||
"build": [
|
||||
{
|
||||
"cmd": "clear"
|
||||
},
|
||||
{
|
||||
"cmd": "init"
|
||||
"cmd" : "init"
|
||||
},
|
||||
{
|
||||
"shell": "mvn package -DskipTests",
|
||||
@@ -47,43 +51,22 @@
|
||||
},
|
||||
{
|
||||
"func": "cp",
|
||||
"from": "./target/sydapi4j.jar",
|
||||
"to": "%out_path%/jar/sydapi4j.jar"
|
||||
"from": "%target_f1%",
|
||||
"to": "%target_t1%"
|
||||
},
|
||||
{
|
||||
"func": "cp",
|
||||
"from": "./target/sydapi4j-jar-with-dependencies.jar",
|
||||
"to": "%out_path%/jar/sydapi4j-jar-with-dependencies.jar"
|
||||
},
|
||||
|
||||
{
|
||||
"shell" : "mvn dependency:copy-dependencies -DincludeScope=runtime -DoutputDirectory=%out_path%/jar/dependences",
|
||||
"check": "BUILD SUCCESS"
|
||||
},
|
||||
{
|
||||
"func": "cp",
|
||||
"from": "./doc",
|
||||
"to": "%out_path%/doc"
|
||||
},
|
||||
{
|
||||
"func": "cp",
|
||||
"from": "./src/test/java/sample",
|
||||
"to": "%out_path%/sample"
|
||||
},
|
||||
{
|
||||
"func": "cp",
|
||||
"from": "./˵Ã÷.txt",
|
||||
"to": "%out_path%/˵Ã÷.txt"
|
||||
"from": "%target_f2%",
|
||||
"to": "%target_t2%"
|
||||
},
|
||||
{
|
||||
"func": "zip",
|
||||
"from": "%out_path%/*",
|
||||
"to": "%out_path%/sydapi-%version%.%project.git_commit_hash%.zip",
|
||||
"vc" : "10M"
|
||||
"from": "%out_path%",
|
||||
"to": "%out_path%/sydapi-%version%.zip"
|
||||
},
|
||||
{
|
||||
"func": "open",
|
||||
"path": "%out_path%/"
|
||||
"path": "%out_path%"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<groupId>com.sunyard</groupId>
|
||||
<artifactId>sydapi4j</artifactId>
|
||||
<version>1.0.2022-SNAPSHOT</version>
|
||||
<version>1.15.20250701</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>sydapi4j</name>
|
||||
@@ -27,10 +27,14 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.houbb</groupId>
|
||||
<artifactId>junitperf</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<scope>test</scope>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.17.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.17.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- <!– https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 –>-->
|
||||
@@ -78,35 +82,14 @@
|
||||
<dependency>
|
||||
<groupId>com.sunyard</groupId>
|
||||
<artifactId>proto</artifactId>
|
||||
<version>1.1.20221215</version>
|
||||
<version>1.0-20220905</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.jmeter</groupId>
|
||||
<artifactId>ApacheJMeter_java</artifactId>
|
||||
<version>5.4.3</version>
|
||||
<scope>provided</scope>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy</artifactId>
|
||||
<version>2.4.15</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcpkix-jdk15on</artifactId>
|
||||
<version>1.65</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>1.65</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.4.M1</version>
|
||||
</dependency>
|
||||
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>club.fullstack</groupId>-->
|
||||
<!--<artifactId>serialize</artifactId>-->
|
||||
@@ -149,8 +132,8 @@
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<source>6</source>
|
||||
<target>6</target>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<compilerId>groovy-eclipse-compiler</compilerId>
|
||||
<verbose>true</verbose>
|
||||
<fork>true</fork>
|
||||
@@ -169,73 +152,57 @@
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<configuration>
|
||||
<reportOutputDirectory>./public/</reportOutputDirectory>
|
||||
<destDir>html</destDir>
|
||||
<additionalOptions>html5</additionalOptions>
|
||||
<excludePackageNames>com.sunyard.SydApi:com.sunyard.inf.*:com.sunyard.cert.*</excludePackageNames>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- <plugin>-->
|
||||
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||
<!-- <artifactId>maven-javadoc-plugin</artifactId>-->
|
||||
<!-- <version>3.1.1</version>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <reportOutputDirectory>./public/</reportOutputDirectory>-->
|
||||
<!-- <destDir>html</destDir>-->
|
||||
<!-- <additionalOptions>html5</additionalOptions>-->
|
||||
<!-- <excludePackageNames>com.sunyard.SydApi:com.sunyard.inf.*:com.sunyard.cert.*</excludePackageNames>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- </plugin>-->
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<!-- <plugin>-->
|
||||
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||
<!-- <artifactId>maven-source-plugin</artifactId>-->
|
||||
<!-- <version>2.4</version>-->
|
||||
|
||||
<!-- 进行package命令时就可以将源码同时进行打包 -->
|
||||
<!-- 所以我们需要绑定source插件到我们default生命周期的package阶段 -->
|
||||
<executions>
|
||||
<execution>
|
||||
<!-- 定义一个阶段,这个阶段是package -->
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- <!– 进行package命令时就可以将源码同时进行打包 –>-->
|
||||
<!-- <!– 所以我们需要绑定source插件到我们default生命周期的package阶段 –>-->
|
||||
<!-- <executions>-->
|
||||
<!-- <execution>-->
|
||||
<!-- <!– 定义一个阶段,这个阶段是package –>-->
|
||||
<!-- <phase>package</phase>-->
|
||||
<!-- <goals>-->
|
||||
<!-- <goal>jar-no-fork</goal>-->
|
||||
<!-- </goals>-->
|
||||
<!-- </execution>-->
|
||||
<!-- </executions>-->
|
||||
<!-- </plugin>-->
|
||||
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<mainClass>com.xxx.uploadFile</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<configuration>
|
||||
<includeScope>runtime</includeScope>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>
|
||||
${project.build.directory}/lib
|
||||
</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- <plugin>-->
|
||||
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||
<!-- <artifactId>maven-dependency-plugin</artifactId>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <includeScope>runtime</includeScope>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- <executions>-->
|
||||
<!-- <execution>-->
|
||||
<!-- <id>copy</id>-->
|
||||
<!-- <phase>package</phase>-->
|
||||
<!-- <goals>-->
|
||||
<!-- <goal>copy-dependencies</goal>-->
|
||||
<!-- </goals>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <outputDirectory>-->
|
||||
<!-- ${project.build.directory}/lib-->
|
||||
<!-- </outputDirectory>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- </execution>-->
|
||||
<!-- </executions>-->
|
||||
<!-- </plugin>-->
|
||||
|
||||
|
||||
<plugin>
|
||||
@@ -243,7 +210,7 @@
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>com.Sample.TestDemo</mainClass>
|
||||
<mainClass>racal.sunyard.main.Version</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
@@ -259,38 +226,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- <plugin>-->
|
||||
<!-- <groupId>org.jetbrains.kotlin</groupId>-->
|
||||
<!-- <artifactId>kotlin-maven-plugin</artifactId>-->
|
||||
<!-- <version>${kotlin.version}</version>-->
|
||||
<!-- <executions>-->
|
||||
<!-- <execution>-->
|
||||
<!-- <id>compile</id>-->
|
||||
<!-- <phase>compile</phase>-->
|
||||
<!-- <goals>-->
|
||||
<!-- <goal>compile</goal>-->
|
||||
<!-- </goals>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <sourceDirs>-->
|
||||
<!-- <source>src/main/java</source>-->
|
||||
<!-- </sourceDirs>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- </execution>-->
|
||||
<!-- <execution>-->
|
||||
<!-- <id>test-compile</id>-->
|
||||
<!-- <phase>test-compile</phase>-->
|
||||
<!-- <goals>-->
|
||||
<!-- <goal>test-compile</goal>-->
|
||||
<!-- </goals>-->
|
||||
<!-- </execution>-->
|
||||
<!-- </executions>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <jvmTarget>1.6</jvmTarget>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- </plugin>-->
|
||||
|
||||
|
||||
</plugins>
|
||||
<!-- 主资源目录 -->
|
||||
<resources>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
const l = require("./log")
|
||||
const os = require("os");
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const util = require('util');
|
||||
const { exec } = require('child_process')
|
||||
|
||||
|
||||
function sync( cmds , options = {}){
|
||||
|
||||
if ( options.detached ) {
|
||||
throw "sync 不支持 detached"
|
||||
}
|
||||
|
||||
options = Object.assign({
|
||||
// cwd : os.tmpdir(),
|
||||
encoding: 'buffer'
|
||||
}, options)
|
||||
|
||||
// 支持多命令
|
||||
let cmd = cmds
|
||||
|
||||
// win 乱码问题
|
||||
let encode = "win32" === os.platform() ? 'cp936' : "utf-8"
|
||||
|
||||
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
let process = exec( cmd , options , function (e, stdout, stderr) {
|
||||
// console.log( e,
|
||||
// iconv.decode( stdout, 'cp936'),
|
||||
// iconv.decode( stderr, 'cp936')
|
||||
// )
|
||||
|
||||
if ( e ) {
|
||||
reject( e )
|
||||
} else {
|
||||
|
||||
|
||||
resolve( stdout.toString() , stderr.toString() )
|
||||
// resolve({
|
||||
// pid : process.pid,
|
||||
// exitCode : process.exitCode,
|
||||
// stdout : stdout.toString(),
|
||||
// stderr : stderr.toString()
|
||||
// })
|
||||
}
|
||||
})
|
||||
console.log( "process", process.pid )
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
var version = ""
|
||||
const project_path = path.join(__dirname, "../")
|
||||
const out_path = path.join(project_path, "public")
|
||||
|
||||
// 用户文档
|
||||
const man = "说明.txt"
|
||||
|
||||
function prepareDir(){
|
||||
|
||||
return new Promise(function (cbok, cberr) {
|
||||
if ( fs.existsSync( out_path ) ){
|
||||
l.i("存在旧文件,清空旧文件")
|
||||
}
|
||||
|
||||
sync("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) {
|
||||
sync('mvn package -DskipTests').then(function (value, error) {
|
||||
|
||||
if ( error ) {
|
||||
throw 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 sync('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 sync("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 zipsample(){
|
||||
return sync("7z a .\\public\\sydapi-"+ version +".zip .\\src\\test\\java\\com\\sunyard\\sydapi\\sample").then(function (value, error) {
|
||||
|
||||
l.d( value )
|
||||
if ( value.indexOf("Everything is Ok") < 0 ){
|
||||
throw new Error("请检查 7z 命令")
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
function zipdoc(){
|
||||
return sync("7z a .\\public\\sydapi-"+ version +".zip " + man).then(function (value, error) {
|
||||
|
||||
l.d( value )
|
||||
if ( value.indexOf("Everything is Ok") < 0 ){
|
||||
throw new Error("请检查 7z 命令")
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function dependencies(){
|
||||
return sync('mvn dependency:copy-dependencies -DincludeScope=runtime -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 )
|
||||
|
||||
sync('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-(?<version>\S+)$/gm.exec(value)
|
||||
l.i( r.groups.version )
|
||||
version = r.groups.version
|
||||
|
||||
return sync('git log -1')
|
||||
|
||||
}).then(function (value) {
|
||||
|
||||
l.d( value )
|
||||
var r = /^commit\s(?<id>\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("<dependencies>")
|
||||
var tail = pom.indexOf("</dependencies>") + 15
|
||||
|
||||
var dependencies = pom.substring( head, tail )
|
||||
fs.writeFileSync( path.join( out_path, "jar", "dependences.xml") , dependencies )
|
||||
|
||||
}).then(function (value) {
|
||||
|
||||
return zipjar()
|
||||
|
||||
}).then(function (value) {
|
||||
|
||||
return zipsample()
|
||||
|
||||
}).then(function (value) {
|
||||
|
||||
return zipdoc()
|
||||
|
||||
}).then(function () {
|
||||
|
||||
l.i("打包完成!")
|
||||
sync('cd .\\public && start .')
|
||||
|
||||
}).catch(function (reason) {
|
||||
|
||||
l.e( reason )
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,5 @@
|
||||
v1.11 版本
|
||||
- 修正不规范接口 GenerateRandom 返回值更改为 String 类型。老版本为 bool 类型,仅于活性检测。
|
||||
|
||||
v1.12 版本
|
||||
- 新增编押验押接口/人行定制接口。
|
||||
@@ -1,141 +0,0 @@
|
||||
package com.Sample;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.proto.Util;
|
||||
import com.sunyard.util.Configure;
|
||||
import java.io.IOException;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
public class TestDemo {
|
||||
public static String sign(SydApi4j api, String certDn, String orgData) {
|
||||
byte[] nakedSign = api.SYD_NakedSignAll(2, orgData.getBytes(), certDn);
|
||||
System.out.println("签名数据:"+ Util.bytes2HexString(nakedSign));
|
||||
return Util.bytes2HexString(nakedSign);
|
||||
}
|
||||
|
||||
public static Boolean signVer(SydApi4j api, String certDn, String orgData, String sign) {
|
||||
boolean nakedVerify = api.SYD_NakedVerifyAll(2, orgData.getBytes(), Util.hexString2Bytes(sign), certDn);
|
||||
System.out.println("验签结果:"+ nakedVerify);
|
||||
return nakedVerify;
|
||||
}
|
||||
|
||||
public static String enData(SydApi4j api, String certDn, String orgData) {
|
||||
RetWrap genSM2 = api.generateDEByDnAll(3, certDn, orgData.getBytes());
|
||||
byte[] cipherKey = (byte[])genSM2.get("CipherKey");
|
||||
System.out.println("加密结果:"+ new String(cipherKey));
|
||||
return new String(cipherKey);
|
||||
}
|
||||
|
||||
public static String deData(SydApi4j api, String certDn, String sign) {
|
||||
RetWrap denSM2 = api.decryptDEByDNAll(3, certDn, sign.getBytes());
|
||||
byte[] oData = (byte[])denSM2.get("oData");
|
||||
System.out.println("解密数据:"+ new String(oData));
|
||||
return new String(oData);
|
||||
}
|
||||
|
||||
public static String detachSign(SydApi4j api, String certDn, String orgData) {
|
||||
String sign = api.detachedSignAll(2, orgData.getBytes(), certDn);
|
||||
System.out.println("detach签名结果:"+ sign);
|
||||
return sign;
|
||||
}
|
||||
|
||||
public static Boolean detachSignVer(SydApi4j api, String orgData, String sign) {
|
||||
boolean signVerify = api.detachedVerifyAll(2, orgData.getBytes(), sign);
|
||||
System.out.println("detach验签:"+ signVerify);
|
||||
return signVerify;
|
||||
}
|
||||
|
||||
public static String snSign(SydApi4j api, String sn, String orgData) {
|
||||
String sign = api.SM2SignCustomized(sn,orgData.getBytes());
|
||||
System.out.println("sn签名结果:"+ sign);
|
||||
return sign;
|
||||
}
|
||||
|
||||
public static Boolean snSignVer(SydApi4j api, String sn,String orgData, String sign) {
|
||||
boolean signVerify = api.SM2VerifyCustomized(sn, orgData.getBytes(), sign);
|
||||
System.out.println("sn验签:"+ signVerify);
|
||||
return signVerify;
|
||||
}
|
||||
|
||||
public static String sm3hash(SydApi4j api,String pk,String orgData) {
|
||||
byte[] hash = api.SM3Hash(pk, orgData.getBytes());
|
||||
System.out.println("hash计算:"+ Util.bytes2HexString(hash));
|
||||
return Util.bytes2HexString(hash);
|
||||
}
|
||||
|
||||
|
||||
public static void testAll(SydApi4j api, String certDn, String orgData) {
|
||||
byte[] nakedSign = api.SYD_NakedSignAll(2, orgData.getBytes(), certDn);
|
||||
System.out.println("签名数据:"+ Util.bytes2HexString(nakedSign));
|
||||
boolean nakedVerify = api.SYD_NakedVerifyAll(2, orgData.getBytes(), nakedSign, certDn);
|
||||
System.out.println("验签结果:"+ nakedVerify);
|
||||
RetWrap genSM2 = api.generateDEByDnAll(3, certDn, orgData.getBytes());
|
||||
byte[] cipherKey = (byte[])genSM2.get("CipherKey");
|
||||
System.out.println("加密结果:"+ new String(cipherKey));
|
||||
RetWrap denSM2 = api.decryptDEByDNAll(3, certDn, cipherKey);
|
||||
byte[] oData = (byte[])denSM2.get("oData");
|
||||
System.out.println("解密数据:"+ new String(oData));
|
||||
String sign = api.detachedSignAll(2, orgData.getBytes(), certDn);
|
||||
System.out.println("detach签名结果:"+ sign);
|
||||
boolean signVerify = api.detachedVerifyAll(2, orgData.getBytes(), sign);
|
||||
System.out.println("detach验签:"+ signVerify);
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
try {
|
||||
String ip = Configure.getKey("ip");
|
||||
System.out.println("ip:"+ ip);
|
||||
int port = Integer.parseInt(Configure.getKey("port"));
|
||||
System.out.println("port:"+ port);
|
||||
int timeout = Integer.parseInt(Configure.getKey("timeout"));
|
||||
System.out.println(""+ timeout);
|
||||
String certDn = Configure.getKey("certDn");
|
||||
System.out.println("certDn:"+ certDn);
|
||||
String signorenData = Configure.getKey("signorenData");
|
||||
System.out.println("signorenData:"+ signorenData);
|
||||
String orgData = Configure.getKey("orgData");
|
||||
System.out.println("orgData:"+ orgData);
|
||||
int type = Integer.parseInt(Configure.getKey("type"));
|
||||
System.out.println("type:"+ type);
|
||||
SydApiBuilder builder = (new SydApiBuilder()).setIp(ip).setPort(port).setTimeout(timeout);
|
||||
SydApi4j api = (SydApi4j)builder.build();
|
||||
switch (type) {
|
||||
case 1:
|
||||
sign(api, certDn, orgData);
|
||||
break;
|
||||
case 2:
|
||||
signVer(api, certDn, orgData, signorenData);
|
||||
break;
|
||||
case 3:
|
||||
enData(api, certDn, orgData);
|
||||
break;
|
||||
case 4:
|
||||
deData(api, certDn, signorenData);
|
||||
break;
|
||||
case 5:
|
||||
detachSign(api, certDn, orgData);
|
||||
break;
|
||||
case 6:
|
||||
detachSignVer(api, orgData, signorenData);
|
||||
break;
|
||||
case 7:
|
||||
snSign(api, certDn, orgData);
|
||||
break;
|
||||
case 8:
|
||||
snSignVer(api, certDn,orgData, signorenData);
|
||||
break;
|
||||
|
||||
case 9:
|
||||
sm3hash(api, certDn,orgData);
|
||||
break;
|
||||
case 0:
|
||||
testAll(api, certDn, orgData);
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,217 +0,0 @@
|
||||
package com.jmeter.test;
|
||||
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.proto.Util;
|
||||
import org.apache.jmeter.config.Arguments;
|
||||
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
|
||||
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
|
||||
import org.apache.jmeter.samplers.SampleResult;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
|
||||
public class Test4Jemter extends AbstractJavaSamplerClient {
|
||||
|
||||
private String SM2dn ;
|
||||
private String RSAdn ;
|
||||
private String ip ;
|
||||
private String ip2 ;
|
||||
private String oData;
|
||||
private String sign;
|
||||
private byte[] orgData;
|
||||
|
||||
private int type;
|
||||
|
||||
private static ThreadLocal<SydApi4j> api;
|
||||
|
||||
|
||||
/**
|
||||
* 定义默认的参数,在jmeter中会自动显示在这里定义的默认参数
|
||||
* @return Arguments对象
|
||||
*/
|
||||
@Override
|
||||
public Arguments getDefaultParameters() {
|
||||
Arguments arguments = new Arguments();
|
||||
arguments.addArgument("SM2dn", "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1");
|
||||
arguments.addArgument("RSAdn", "C=cn,O=CFCA TEST CA,OU=NCS2,OU=Enterprises,CN=041@Z402451000010@ShanDong@00000001");
|
||||
arguments.addArgument("orgData", "12345678");
|
||||
arguments.addArgument("ip", "192.168.0.166");
|
||||
// arguments.addArgument("ip2", "172.16.17.161");
|
||||
arguments.addArgument("type", "1");
|
||||
arguments.addArgument("sign", "12345678");
|
||||
return arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在执行测试之前执行,只执行一次,可以获取传递过来的参数,一般用来做初始化操作
|
||||
* @param context 可以获取jmeter传递过来的参数
|
||||
*/
|
||||
@Override
|
||||
public void setupTest(JavaSamplerContext context) {
|
||||
//对成员变量初始化
|
||||
SM2dn = context.getParameter("SM2dn");
|
||||
RSAdn = context.getParameter("RSAdn");
|
||||
oData = context.getParameter("orgData");
|
||||
ip = context.getParameter("ip");
|
||||
// ip2 = context.getParameter("ip2");
|
||||
type = context.getIntParameter("type");
|
||||
sign = context.getParameter("sign");
|
||||
System.setProperty("com.sunyard.dnsort", "false");
|
||||
api = new ThreadLocal<SydApi4j>() {
|
||||
public SydApi4j initialValue() {
|
||||
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp(ip);
|
||||
final SydApi4j api = (SydApi4j) builder.build();
|
||||
return api;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 真正的测试代码块,jmeter按照配置的逻辑执行该方法
|
||||
* @param javaSamplerContext 上下文对象,可以获取jmeter传递的参数
|
||||
* @return SampleResult对象用于封装结果
|
||||
*/
|
||||
@Override
|
||||
public SampleResult runTest(JavaSamplerContext javaSamplerContext) {
|
||||
SampleResult sr = new SampleResult();
|
||||
//设置标签
|
||||
sr.setSampleLabel("testDemo");
|
||||
//设置开始标志,否则无法统计tps等
|
||||
sr.sampleStart();
|
||||
try {
|
||||
orgData = oData.getBytes(); //SM2裸签
|
||||
//执行业务逻辑
|
||||
switch(type){
|
||||
case 1:
|
||||
api.get().SYD_NakedSign(SM2dn, orgData, (byte[]) null);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(Util.encodeBase64(nakedSign1), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
|
||||
case 2:
|
||||
api.get().SYD_NakedVerify(SM2dn, Util.decodeBase64(sign), orgData, (byte[])null) ;
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(String.valueOf(nakedVerify1), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 3:
|
||||
//RSA裸签
|
||||
api.get().SYD_NakedSign(1, RSAdn,orgData,(byte[])null);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(Util.encodeBase64(nakedSign2), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 4:
|
||||
api.get().SYD_NakedVerify(1, RSAdn,Util.decodeBase64(sign),orgData ,(byte[])null);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(String.valueOf(nakedVerify2), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 5:
|
||||
api.get().detachedSign(1, orgData, SM2dn);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(detSign1, StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 6:
|
||||
api.get().detachedVerify(1, orgData, sign);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(String.valueOf(detV1), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 7:
|
||||
api.get().detachedSign(2,1, orgData, RSAdn);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(detSign2, StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 8:
|
||||
api.get().detachedVerify(2,2, orgData, sign);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(String.valueOf(detV2), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 9:
|
||||
api.get().attachedSignHsm(orgData, SM2dn);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(attSign1, StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 10:
|
||||
api.get().attachedVerify( sign.getBytes());
|
||||
sr.setResponseCodeOK();
|
||||
// sr.setResponseData(String.valueOf(attV1), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 11:
|
||||
api.get().attachedSignRSAHsm(2, orgData, RSAdn);
|
||||
sr.setResponseCodeOK();
|
||||
// sr.setResponseData(attSign2, StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 12:
|
||||
api.get().attachedVerifyRSA(2, sign);
|
||||
sr.setResponseCodeOK();
|
||||
// sr.setResponseData(String.valueOf(attV2), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 13:
|
||||
api.get().generateDE(SM2dn.getBytes(), 3, 1, orgData);
|
||||
// byte[] cipherKey = (byte[]) genSM2.get(SydApi.RET_CIPHER_KEY);
|
||||
sr.setResponseCodeOK();
|
||||
// sr.setResponseData(new String(cipherKey), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 14:
|
||||
api.get().decryptDE(true, 1, SM2dn.getBytes(), sign);;
|
||||
// byte[] oData = (byte[]) denSM2.get("oData");
|
||||
sr.setResponseCodeOK();
|
||||
// sr.setResponseData(new String(oData), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
|
||||
case 15:
|
||||
api.get(). generateDE(RSAdn.getBytes(), 4, 1, orgData);
|
||||
// byte[] cipherKeyRSA = (byte[]) genRSA.get(SydApi.RET_CIPHER_KEY);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(new String(cipherKeyRSA), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 16:
|
||||
api.get().decryptDERSA(true, 1, RSAdn.getBytes(), sign);
|
||||
// byte[] oDataRSA = (byte[]) denRSA.get("oData");
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(new String(oDataRSA), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
default:
|
||||
sr.setResponseCodeOK();
|
||||
sr.setResponseData("请选择测试组", StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
}
|
||||
sr.setSuccessful(true);
|
||||
}catch (SydApiException e){
|
||||
e.printStackTrace();
|
||||
sr.setResponseCode(String.valueOf(e.getRetCode()));
|
||||
sr.setResponseData(e.getMessage(), StandardCharsets.UTF_8.displayName());
|
||||
sr.setSuccessful(false);
|
||||
}finally {
|
||||
sr.sampleEnd();
|
||||
}
|
||||
return sr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试完成后执行,一般用于关闭资源
|
||||
* @param context 上下文对象,可用于获取jmeter传递的参数
|
||||
*/
|
||||
@Override
|
||||
public void teardownTest(JavaSamplerContext context) {
|
||||
System.runFinalization();
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
package com.sunyard;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 管理多线程间对象
|
||||
* 类似 ThreadLocal
|
||||
* @param <T>
|
||||
*/
|
||||
public class MutiThreadHander<T> {
|
||||
|
||||
private static class Handler<T> {
|
||||
private T obj = null;
|
||||
private long creatAt = System.currentTimeMillis();
|
||||
private long lastGetAt = System.currentTimeMillis();
|
||||
|
||||
public Handler(T obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
public T getObj() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
public long getCreatAt() {
|
||||
return creatAt;
|
||||
}
|
||||
|
||||
public long getLastGetAt() {
|
||||
return lastGetAt;
|
||||
}
|
||||
}
|
||||
private final Map<Thread, Handler> handers = new HashMap<Thread, Handler>();
|
||||
private ScheduledExecutorService gcThread = Executors.newScheduledThreadPool(1);
|
||||
|
||||
private long maxLiveMillis = 8 * 3600 * 1000;
|
||||
private long maxIdleMillis = 3600 * 1000;
|
||||
private long checkEveryMillis = 5 * 60 * 1000;
|
||||
|
||||
public MutiThreadHander() {
|
||||
gcThread.scheduleWithFixedDelay(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if ( handers.size() <= 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
Iterator<Map.Entry<Thread, Handler>>it = handers.entrySet().iterator();
|
||||
while ( it.hasNext() ){
|
||||
Map.Entry<Thread, Handler> entry = it.next();
|
||||
|
||||
// check maxLiveMillis
|
||||
if ( entry.getValue().getCreatAt() - now > maxLiveMillis ){
|
||||
synchronized ( handers ){
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// check maxIdleMillis
|
||||
if ( entry.getValue().getLastGetAt() - now > maxIdleMillis ){
|
||||
synchronized ( handers ){
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch ( Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, checkEveryMillis, checkEveryMillis, TimeUnit.MILLISECONDS );
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected T initialValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
synchronized ( handers ) {
|
||||
handers.remove( Thread.currentThread() );
|
||||
}
|
||||
}
|
||||
|
||||
public void set(T obj){
|
||||
synchronized ( handers ) {
|
||||
handers.put( Thread.currentThread() , new Handler(obj));
|
||||
}
|
||||
}
|
||||
|
||||
public T get(){
|
||||
synchronized ( handers ) {
|
||||
Handler hander = handers.get( Thread.currentThread() );
|
||||
if ( null == hander ) {
|
||||
T o = initialValue();
|
||||
hander = new Handler( o );
|
||||
handers.put( Thread.currentThread(), hander );
|
||||
}
|
||||
return (T) hander.getObj();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.sunyard;
|
||||
|
||||
import com.sunyard.inf.cryption.*;
|
||||
|
||||
import com.sunyard.inf.*;
|
||||
import com.sunyard.inf.customize.Syd4DigitalEnvelope;
|
||||
import com.sunyard.inf.customize.SydHAApi;
|
||||
import com.sunyard.inf.customize.SydQNUCApi;
|
||||
import com.sunyard.inf.customize.SydUnionPayApi;
|
||||
@@ -13,9 +12,9 @@ import racal.sunyard.main.SydApiBuilder;
|
||||
* 程序调用接口
|
||||
*/
|
||||
public interface SydApi extends
|
||||
SydRawApi, SydCertApi, SydGenApi, SydSYMApi, SydASYMApi, SydHashApi,
|
||||
SydRawApi, SydCertApi, SydCryptionApi, SydGenApi,
|
||||
SydSVApi, SydHAApi, SydQNUCApi, SydPledge, SydPINOpt,
|
||||
SydManufactureApi, SydZYOption, SydUnionPayApi ,Syd4DigitalEnvelope{
|
||||
SydManufactureApi, SydZYOption, SydUnionPayApi {
|
||||
|
||||
byte ALG_AES = 0x30;
|
||||
byte ALG_SM4 = 0x31;
|
||||
@@ -72,18 +71,6 @@ public interface SydApi extends
|
||||
*/
|
||||
SydApi connect(String ip, int port, String pwd, int connectTimeout, int readTimeout);
|
||||
|
||||
/**
|
||||
* 建立到指定地址和端口号的加密设备的TCP/IP 连接,返回 TCP/IP 连接句柄。
|
||||
* @param ip 加密机 ip
|
||||
* @param port 加密机端口
|
||||
* @param pwd 加密机密码,无密码写 null
|
||||
* @param connectTimeout 网络连接时超时时间
|
||||
* @param readTimeout 网络通信时,socket 超时时间
|
||||
* @param retryWhenNetError 网络失败时重试次数
|
||||
* @return
|
||||
*/
|
||||
SydApi connect(String ip, int port, String pwd, int connectTimeout, int readTimeout , int retryWhenNetError);
|
||||
|
||||
void init(SydApiBuilder builder);
|
||||
|
||||
/**
|
||||
@@ -102,7 +89,6 @@ public interface SydApi extends
|
||||
// 单例可以不实现
|
||||
void error();
|
||||
|
||||
|
||||
/**
|
||||
* 获取加密机cpu,内存,磁盘使用状况
|
||||
*
|
||||
@@ -113,8 +99,4 @@ public interface SydApi extends
|
||||
RetWrap getStatus();
|
||||
|
||||
byte[] directBytes(byte[] data);
|
||||
|
||||
public Object getBindObject();
|
||||
|
||||
public void setBindObject(Object bindObject);
|
||||
}
|
||||
|
||||
@@ -13,134 +13,110 @@ public class SydApiException extends RuntimeException{
|
||||
return retCode;
|
||||
}
|
||||
|
||||
private static String transMsg(int code){
|
||||
String msg = "未定义的错误";
|
||||
switch (code){
|
||||
|
||||
public void transMsg(){
|
||||
switch (this.retCode){
|
||||
case -1:
|
||||
case -2:
|
||||
case -3:
|
||||
msg = "网络错误";
|
||||
this.msg = "网络错误";
|
||||
break;
|
||||
case -4:
|
||||
msg = "返回包的序列号有误";
|
||||
this.msg = "返回包的序列号有误";
|
||||
break;
|
||||
case -5:
|
||||
msg = "返回包的命令码有误";
|
||||
this.msg = "返回包的命令码有误";
|
||||
break;
|
||||
case -6:
|
||||
msg = "输出缓冲区预留太小";
|
||||
this.msg = "输出缓冲区预留太小";
|
||||
break;
|
||||
case -25:
|
||||
msg = "输入的 HASH 值长度应该为 32 个字节";
|
||||
this.msg = "输入的 HASH 值长度应该为 32 个字节";
|
||||
break;
|
||||
case -26:
|
||||
msg = "用户标识超长(应该<=16) ";
|
||||
this.msg = "用户标识超长(应该<=16) ";
|
||||
break;
|
||||
case -27:
|
||||
msg = "数据类型不合法 ";
|
||||
this.msg = "数据类型不合法 ";
|
||||
break;
|
||||
case 33:
|
||||
msg = "检索的数据或密钥不存在";
|
||||
this.msg = "检索的数据或密钥不存在";
|
||||
break;
|
||||
case 4:
|
||||
msg = "DER 编码格式错误(公钥) ";
|
||||
this.msg = "DER 编码格式错误(公钥) ";
|
||||
break;
|
||||
case 21:
|
||||
msg = "输入的数据格式错误 ";
|
||||
this.msg = "输入的数据格式错误 ";
|
||||
break;
|
||||
case 19:
|
||||
msg = "数据解密错(C3) ";
|
||||
this.msg = "数据解密错(C3) ";
|
||||
break;
|
||||
case 2:
|
||||
msg = "签名验证错误 ";
|
||||
this.msg = "签名验证错误 ";
|
||||
break;
|
||||
case 129:
|
||||
msg = "没有该指令";
|
||||
this.msg = "没有该指令";
|
||||
break;
|
||||
|
||||
case 0x8006 : {
|
||||
msg = "输入的数据格式错误";
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x7007 : {
|
||||
msg = "实体白名单未添加";
|
||||
this.msg = "输入的数据格式错误";
|
||||
break;
|
||||
}
|
||||
|
||||
case 32770:
|
||||
msg = "签名验证错误(P7) ";
|
||||
this.msg = "签名验证错误(P7) ";
|
||||
break;
|
||||
|
||||
case 32773:
|
||||
msg = "证书不可信";
|
||||
this.msg = "证书不可信";
|
||||
break;
|
||||
|
||||
case 32884:
|
||||
msg = "证书或签名数据的格式错";
|
||||
this.msg = "证书或签名数据的格式错";
|
||||
break;
|
||||
|
||||
case 36868:
|
||||
msg = "DN 所指向的实体不存在";
|
||||
this.msg = "DN 所指向的实体不存在";
|
||||
break;
|
||||
|
||||
case 40000:
|
||||
msg = "输入的大数据处理异常";
|
||||
this.msg = "输入的大数据处理异常";
|
||||
break;
|
||||
|
||||
case 56300:
|
||||
msg = "证书导入错误";
|
||||
this.msg = "证书导入错误";
|
||||
break;
|
||||
|
||||
case 56307:
|
||||
msg = "证书删除错误";
|
||||
break;
|
||||
|
||||
case 0xC101 :
|
||||
msg = "证书识别异常";
|
||||
this.msg = "证书删除错误";
|
||||
break;
|
||||
default:
|
||||
msg = "未定义的错误";
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void transMsg(){
|
||||
this.msg = transMsg( this.retCode );
|
||||
default:
|
||||
this.msg = "未定义的错误";
|
||||
}
|
||||
}
|
||||
|
||||
public SydApiException(int retCode) {
|
||||
super("SydApiException(" + "code = "+String.format("%04x", retCode) + ")" );
|
||||
super("SydApiException(" + "code = "+String.format("%d", retCode) + ")" );
|
||||
this.retCode = retCode;
|
||||
transMsg();
|
||||
}
|
||||
|
||||
public SydApiException(int retCode, Exception e) {
|
||||
super("SydApiException(" + "code = "+String.format("%04x", retCode) + ")" , e);
|
||||
this.retCode = retCode;
|
||||
transMsg();
|
||||
}
|
||||
|
||||
|
||||
public SydApiException(String msg, int retCode){
|
||||
super("SydApiException(" + String.format(" %04X", retCode) + ":" + ( null == msg ? transMsg(retCode) : msg ) + ")" );
|
||||
this.retCode = retCode;
|
||||
public SydApiException(String msg, int ret, Throwable e){
|
||||
super("SydApiException(" +"code ="+ String.format(" %d", ret) + " : "+"msg ="+ (null == msg ? "未定义的错误" : msg) +")" , e);
|
||||
this.retCode = ret;
|
||||
if (null == msg || "".equals(msg)){
|
||||
transMsg();
|
||||
}else {
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
|
||||
public SydApiException(String msg, int ret, Throwable e) {
|
||||
super("SydApiException(code =" + String.format(" %04x", ret) + " : " + "msg =" + (msg == null ? "未定义的错误" : msg) + ")", e);
|
||||
public SydApiException(String msg, int ret){
|
||||
super("SydApiException(" +"code ="+ String.format(" %d", ret) + " : "+"msg ="+ (null == msg ? "未定义的错误" : msg) +")" );
|
||||
this.retCode = ret;
|
||||
if (msg != null && !"".equals(msg)) {
|
||||
if (null == msg || "".equals(msg)){
|
||||
transMsg();
|
||||
}else {
|
||||
this.msg = msg;
|
||||
} else {
|
||||
this.transMsg();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static SydApiException fromBin( byte[] b , String msg){
|
||||
@@ -159,7 +135,7 @@ public class SydApiException extends RuntimeException{
|
||||
sb.append(Integer.toHexString(this.retCode));
|
||||
sb.append(" ) ");
|
||||
sb.append(" msg = ");
|
||||
sb.append(msg);
|
||||
sb.append(this.msg);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.sunyard.constant;
|
||||
|
||||
/**
|
||||
* 证书用途
|
||||
*/
|
||||
public enum CertUsage {
|
||||
digitalSignature,
|
||||
nonRepudiation,
|
||||
keyEncipherment,
|
||||
dataEncipherment,
|
||||
keyAgreement,
|
||||
keyCertSign,
|
||||
cRLSign,
|
||||
encipherOnly,
|
||||
decipherOnly
|
||||
}
|
||||
@@ -3,10 +3,8 @@ package com.sunyard.inf;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.cert.X509;
|
||||
import com.sunyard.constant.CertUsage;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 证书操作相关接口
|
||||
@@ -103,14 +101,6 @@ public interface SydCertApi {
|
||||
String sign
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有证书
|
||||
* @return
|
||||
* certDNs: 证书DN
|
||||
*/
|
||||
List<String> getAllCert() throws UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* 查询所有证书
|
||||
* @param dataFlag 数据包标志 0:起始包 1:中间包 2:结束包
|
||||
@@ -124,55 +114,20 @@ public interface SydCertApi {
|
||||
*/
|
||||
RetWrap getAllCert(int dataFlag) throws UnsupportedEncodingException;
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有证书
|
||||
* @param dataFlag 数据包标志 0:起始包 1:中间包 2:结束包
|
||||
* @param sqlite 查询条件,默认查询所有"1=1"
|
||||
* @return
|
||||
* dataFlag: 数据包标志 0:起始包 1:中间包 2:结束包
|
||||
* certAllNum: 证书总数
|
||||
* realCertNum: 实际证书个数
|
||||
* dataAttrFlag: 数据包属性标志
|
||||
* certLenMax: 证书最大长度
|
||||
* certDNs: 证书DN
|
||||
*/
|
||||
RetWrap getAllCert(int dataFlag,String sqlite) throws UnsupportedEncodingException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 上传指定证书到加密设备
|
||||
* @param certData 证书的字节数组
|
||||
* @param organizationId 机构号的字节数组
|
||||
* @param us 白名单类型
|
||||
* @return
|
||||
*/
|
||||
RetWrap importCert(byte[] certData, byte[] organizationId, CertUsage... us);
|
||||
RetWrap importCert(byte[] certData, byte[] organizationId);
|
||||
|
||||
|
||||
/**
|
||||
* 从加密设备中删除指定 DN 的公钥证书
|
||||
* @param dn:传入的证书
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean deleteCert(String dn);
|
||||
|
||||
/**
|
||||
* 上传指定证书到加密设备,并在证书前后加上begin和end
|
||||
* @param certData 证书的字节数组
|
||||
* @param organizationId 机构号的字节数组
|
||||
* @param us 白名单类型
|
||||
* @return
|
||||
*/
|
||||
RetWrap importCertAddHT(String certData, byte[] organizationId, CertUsage... us);
|
||||
RetWrap importCertAddHT(String certData, byte[] organizationId);
|
||||
|
||||
|
||||
String getCertByDn(String dn) throws UnsupportedEncodingException;
|
||||
|
||||
String getCertByDn(String dn,int type) throws UnsupportedEncodingException;
|
||||
public String getCertByDn(byte[] dnBytes);
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ interface SydSYMApi {
|
||||
byte[] SYMEncryptData(int nAlg, String seesionKey, int fullmode, byte[] pINdata);
|
||||
|
||||
|
||||
List<byte[]> SYMEncryptDecryptBatchData(int nAlg, String[] seesionKey, int fullmode, List<byte[]> pINdata);
|
||||
// List<byte[]> SYMEncryptDecryptBatchData(int nAlg, String[] seesionKey, int fullmode, List<byte[]> pINdata);
|
||||
|
||||
/**
|
||||
* 用输入的会话密钥,对指定报文数据进行加密处理。
|
||||
|
||||
@@ -1,216 +0,0 @@
|
||||
package com.sunyard.inf;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.cert.X509;
|
||||
|
||||
/**
|
||||
* 不带原文的签名验签
|
||||
*/
|
||||
public 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
|
||||
);
|
||||
|
||||
/**
|
||||
* 人行项目需要RSA支持
|
||||
* 通过指定的私钥对指定的原始数据编制带公钥证书的数字签名(遵循PKCS#7)
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sCertDN 签名者证书 DN
|
||||
* @return 签名数据
|
||||
*/
|
||||
public String SYD_DetachedSign(
|
||||
int rFlag,
|
||||
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)
|
||||
* 待签名的原始数据将在接口内部进行不带公钥的 sm3 ,然后做 Detach 签名
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sCertDN 签名者证书 DN
|
||||
* @return 签名数据
|
||||
*/
|
||||
String sm3WithoutPKDetachedSign(byte[] orgData, String sCertDN);
|
||||
|
||||
/**
|
||||
* 对指定的原始数据核验其带公钥证书签名(PKCS#7)
|
||||
* 原始数据将在接口内部进行无公钥的 sm3 ,然后做 Detach 验签
|
||||
*
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sign 签名数据
|
||||
* @return 验签是否通过
|
||||
*/
|
||||
boolean sm3WithoutPKDetachedVerify(byte[] orgData, 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
|
||||
);
|
||||
|
||||
//SM2与RSA兼容
|
||||
public String detachedSignAll(int rFlag,byte[] orgData, String sCertDN);
|
||||
|
||||
|
||||
//SM2与RSA兼容
|
||||
public boolean detachedVerifyAll(int rFlag,byte[] orgData, String sign);
|
||||
|
||||
/**
|
||||
* 带公钥证书与签名属性的数字签名(遵循 PKCS#7)
|
||||
* @param dataType 数据类型:0,hash 模式,1为非hash模式
|
||||
* @param orgData 当为hash模式时,值为hash值,当为非hash模式时,值为数据
|
||||
* @param keyTag 密钥对应的索引号
|
||||
* @return 签名的 DER 编码
|
||||
*/
|
||||
public byte[] detachedSign(
|
||||
int dataType,
|
||||
byte[] orgData,
|
||||
int keyTag
|
||||
);
|
||||
public String detachedSign(int rFlag,int dataType, byte[] orgData, String sCertDN);
|
||||
|
||||
/**
|
||||
* 带公钥证书的PKCS#7数字签名(序列号)
|
||||
* @param dataType 数据类型:0,hash 模式,1为非hash模式
|
||||
* @param orgData 当为hash模式时,值为hash值,当为非hash模式时,值为要签名的信息
|
||||
* @param certificateNo X509证书序号
|
||||
* @return 符合PKCS7标准的签名结果
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* 对指定的原始数据核验其带公钥证书签名(PKCS#7)
|
||||
* 数据模式可选 DATA_HASH 或 DATA_ORIGIN
|
||||
*
|
||||
*
|
||||
* @param rFlag RSA标识
|
||||
* @param dataType 输入的数据为 HASH 后的数据 DATA_HASH = 0 ,输入的数据为原始数据库 DATA_ORIGIN = 1
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sign 签名数据
|
||||
* @return 验签是否通过
|
||||
*/
|
||||
boolean detachedVerify(
|
||||
int rFlag,
|
||||
int dataType,
|
||||
byte[] orgData,
|
||||
String sign);
|
||||
|
||||
/**
|
||||
* 带公钥证书与签名属性的数字签名验签(遵循 PKCS#7)
|
||||
* @param dataType 数据类型:0,hash 模式,1为非hash模式
|
||||
* @param orgData 当为hash模式时,值为hash值,当为非hash模式时,值为数据
|
||||
* @param sign 已签名数据
|
||||
* @return 是否正确
|
||||
*/
|
||||
boolean detachedVerify(
|
||||
int dataType,
|
||||
byte[] orgData,
|
||||
byte[] sign);
|
||||
|
||||
/**
|
||||
* 对指定的原始数据核验其带公钥证书签名(PKCS#7)返回证书信息
|
||||
* 数据模式可选 DATA_HASH 或 DATA_ORIGIN
|
||||
*
|
||||
* @param dataType 输入的数据为 HASH 后的数据 DATA_HASH = 0 ,输入的数据为原始数据库 DATA_ORIGIN = 1
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sign 签名数据
|
||||
* @return 证书
|
||||
*/
|
||||
X509 detachedVerifyAndGetX509(int dataType,
|
||||
byte[] orgData,
|
||||
String sign);
|
||||
|
||||
/**
|
||||
* 计算SM3散列值
|
||||
* @param packSn 消息块号,0=仅一块,1=第一块,2=中间块,3=最后块
|
||||
* @param userId 用户 ID,只对“消息块号”为 0、1 时有效
|
||||
* @param publicKey 公钥的 DER 编码
|
||||
* @param msg 二进制的消息块
|
||||
* @param filterData 过渡消息数据,只对“消息块号”为 2、3 时有效
|
||||
* @return
|
||||
* filterData: 过渡消息数据,只对“消息块号”为 2、1 时有效
|
||||
* hash: hash
|
||||
*/
|
||||
RetWrap SM3Hash(int packSn, String userId, byte[] publicKey, byte[] msg, byte[] filterData);
|
||||
|
||||
}
|
||||
@@ -132,18 +132,6 @@ public interface SydGenApi {
|
||||
*/
|
||||
RetWrap SM2GenSessionKey(String publicKey);
|
||||
|
||||
|
||||
/**
|
||||
* 此函数用于会话密钥的产生,用于发起端。
|
||||
* 加密机产生随机会话密钥,输出两类密文:
|
||||
* 1、 RSA公钥加密的密文,用于密钥的传递。
|
||||
* 2、 本地 LMK 加密,用于本地应用数据的加解密。
|
||||
*
|
||||
* @param publicKey 公钥串,DER 编码,HEX 格式。
|
||||
* @return CipherKey 公钥加密的会话密钥,DER 编码,HEX 格式, SessionKey 本地LMK 加密的会话密钥,HEX 格式 , KCV 会话密钥的检验值,HEX 格式,长度为 16H
|
||||
*/
|
||||
RetWrap RSAGenSessionKey(String publicKey);
|
||||
|
||||
/**
|
||||
* 生成数字信封
|
||||
* @param publicKey 公钥
|
||||
@@ -238,9 +226,7 @@ public interface SydGenApi {
|
||||
* SessionKey 本地LMK 加密的会话密钥,HEX 格式, 本地 LMK 加密的会话密钥长度,HEX 格式(不包括第 1 个字符),一般为 33 个 Bytes。默认输入值为缓冲区的大小。
|
||||
* KCV 会话密钥的检验值,HEX 格式,长度为 32H。
|
||||
*/
|
||||
RetWrap generateDEByDn(String certSerial, byte[] oData);
|
||||
|
||||
RetWrap generateDEByDnRSA(int alg,String certSerial, byte[] oData);
|
||||
RetWrap generateDEByDn(String certSerial, String oData);
|
||||
|
||||
/**
|
||||
* 产生对称密钥,通过公钥加密生成网联格式的数字信封。
|
||||
@@ -254,7 +240,7 @@ public interface SydGenApi {
|
||||
* SessionKey 本地LMK 加密的会话密钥,HEX 格式, 本地 LMK 加密的会话密钥长度,HEX 格式(不包括第 1 个字符),一般为 33 个 Bytes。默认输入值为缓冲区的大小。
|
||||
* KCV 会话密钥的检验值,HEX 格式,长度为 32H。
|
||||
*/
|
||||
RetWrap generateDE(byte[] certSerial, int alg, int model, byte[] oData);
|
||||
RetWrap generateDE(byte[] certSerial, int alg, int model, String oData);
|
||||
|
||||
/**
|
||||
* 产生对称密钥,通过公钥加密生成网联格式的数字信封。
|
||||
@@ -322,8 +308,8 @@ public interface SydGenApi {
|
||||
* KCV 会话密钥的检验值,HEX 格式,长度为 36H。
|
||||
* orgCode 如果有机构码的话会返回机构码
|
||||
*/
|
||||
RetWrap decryptDEByDN(String certSerial, byte[] pCipherKey);
|
||||
RetWrap decryptDEByDNRSA(int alg,String certSerial, byte[] pCipherKey);
|
||||
RetWrap decryptDEByDN(String certSerial, String pCipherKey);
|
||||
|
||||
/**
|
||||
* 接收用私钥解密数字信封,还原对称密钥。
|
||||
*
|
||||
@@ -339,21 +325,6 @@ public interface SydGenApi {
|
||||
*/
|
||||
RetWrap decryptDE(boolean pFlag, int model, byte[] certSerial, String pCipherKey);
|
||||
|
||||
/**
|
||||
* 接收用RSA私钥解密数字信封,还原对称密钥。
|
||||
*
|
||||
* @param pFlag 输入。 p标识,如果为true,则传入R
|
||||
* @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 decryptDERSA(boolean pFlag, int model, byte[] certSerial, String pCipherKey);
|
||||
|
||||
/**
|
||||
* 产生要求长度的随即数据串,可用于身份认证
|
||||
*
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
package com.sunyard.inf;
|
||||
|
||||
import com.sunyard.SydApiException;
|
||||
|
||||
/**
|
||||
* 不经过 CA 授信
|
||||
* 直接使用公私钥对签名验签
|
||||
*/
|
||||
interface SydNakedSVApi {
|
||||
/**
|
||||
* 使用指定的证书 DN,从加密设备获取对应的私钥证书,对指定的原始数据编制裸签名(遵循 PKCS#1)
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sCertDN 签名者证书 DN
|
||||
* @return 签名数据
|
||||
*/
|
||||
public byte[] SYD_NakedSign(
|
||||
byte[] orgData,
|
||||
String sCertDN
|
||||
);
|
||||
/**
|
||||
* 使用指定的证书 DN,从加密设备获取对应的私钥证书,对指定的原始数据编制裸签名(遵循 PKCS#1)
|
||||
* 人行项目增加RSA
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sCertDN 签名者证书 DN
|
||||
* @return 签名数据
|
||||
*/
|
||||
public byte[] SYD_NakedSign(
|
||||
int rFlag,
|
||||
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
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* 使用指定的证书 DN,对指定的原始数据编制裸验签(遵循PKCS#1)
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sign 签名数据
|
||||
* @param sCertDN 签名者证书 DN
|
||||
* @return 验签是否通过
|
||||
*/
|
||||
public boolean SYD_NakedVerify(
|
||||
int rFlag,
|
||||
byte[] orgData,
|
||||
byte[] sign,
|
||||
String sCertDN
|
||||
);
|
||||
|
||||
/**
|
||||
* 使用指定的证书 DN,从加密设备获取对应的私钥证书,对指定的原始数据编制裸签名(遵循 PKCS#1)
|
||||
* @param rFlag 摘要算法 1—DIGEST_ALGO_MD5 M
|
||||
* 2—DIGEST_ALGO_SHA1 S
|
||||
* 3—DIGEST_ALGO_SHA256 R
|
||||
* 4-SM2 国密证书,SM3算法
|
||||
* S代表RSA-SHA1进行签名,如果为R代表RSA-SHA256进行签名,如果为M代表RSA-MD5进行签名
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sCertDN 签名者证书 DN
|
||||
* @return 签名数据
|
||||
*/
|
||||
public byte[] SYD_NakedSignAll(
|
||||
int rFlag,
|
||||
byte[] orgData,
|
||||
String sCertDN
|
||||
);
|
||||
|
||||
/**
|
||||
* 使用指定的证书 DN,对指定的原始数据编制裸验签(遵循PKCS#1)
|
||||
* @param rFlag 摘要算法 1—DIGEST_ALGO_MD5 M
|
||||
* * 2—DIGEST_ALGO_SHA1 S
|
||||
* * 3—DIGEST_ALGO_SHA256 R
|
||||
* 4-SM2 国密证书,SM3算法
|
||||
* * S代表RSA-SHA1进行签名,如果为R代表RSA-SHA256进行签名,如果为M代表RSA-MD5进行签名
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sign 签名数据
|
||||
* @param sCertDN 签名者证书 DN
|
||||
* @return 验签是否通过
|
||||
*/
|
||||
public boolean SYD_NakedVerifyAll(
|
||||
int rFlag,
|
||||
byte[] orgData,
|
||||
byte[] sign,
|
||||
String sCertDN
|
||||
);
|
||||
|
||||
/**
|
||||
* 使用指定的证书 DN,对指定的原始数据编制裸验签(遵循PKCS#1) 安徽农信定制接口
|
||||
* @param cert 上传证书
|
||||
* @param rFlag 摘要算法 1—DIGEST_ALGO_MD5 M
|
||||
* * 2—DIGEST_ALGO_SHA1 S
|
||||
* * 3—DIGEST_ALGO_SHA256 R
|
||||
* 4-SM2 国密证书,SM3算法
|
||||
* * S代表RSA-SHA1进行签名,如果为R代表RSA-SHA256进行签名,如果为M代表RSA-MD5进行签名
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sign 签名数据
|
||||
* @param sCertDN 签名者证书 DN
|
||||
* @return 验签是否通过
|
||||
*/
|
||||
public boolean SYD_NakedVerifyAll4NX (
|
||||
String cert,
|
||||
int rFlag,
|
||||
byte[] orgData,
|
||||
byte[] sign,
|
||||
String sCertDN
|
||||
) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,9 +3,6 @@ package com.sunyard.inf;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.cert.X509;
|
||||
import com.sunyard.inf.sva.SydAttachedSVApi;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* 签名验签相关接口
|
||||
@@ -14,5 +11,389 @@ public interface SydSVApi extends SydNakedSVApi, SydAttachedSVApi, SydDetachedSV
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 不经过 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私钥签名
|
||||
* 用户id默认为1234567812345678
|
||||
* 签名结果R/S序列串先进行der编码,再进行base64编码
|
||||
*
|
||||
* @param flag 私钥标志位,当为1时第二个参数传入存储私钥的索引,当为0时第二个参数传入私钥
|
||||
* @param privateKey 当私钥标志位为1时传入存储私钥的索引,当为0时传入私钥
|
||||
* @param publicKey 公钥
|
||||
* @param orgData 要签名的信息
|
||||
* @return 签名结果
|
||||
*/
|
||||
String SM2SignC(int flag, String privateKey, byte[] publicKey, byte[] orgData);
|
||||
String SM2SignC(int flag, String pUserID, String privateKey, byte[] publicKey, byte[] orgData);
|
||||
/**
|
||||
* 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验签
|
||||
* 用户id默认为1234567812345678
|
||||
*
|
||||
* @param publicKey 公钥的 DER 编码
|
||||
* @param orgData 要签名的信息
|
||||
* @param base64Sign 计算的签名,签名结果R/S序列串先进行der编码,再进行base64编码后的结果
|
||||
* @return true 验签成功,false 验签失败
|
||||
*/
|
||||
boolean SM2Verify(byte[] publicKey, byte[] orgData, String base64Sign);
|
||||
|
||||
/**
|
||||
* 采用 SM2 算法,用指定的公钥对指定的原始数据进行数字签名验证。
|
||||
* @param certNo id 用于计算SM3-HASH
|
||||
* @param nOrgDataType 原始数据类型 0 : hash 1 : 原数据,用1.2.3章节限定符亦可
|
||||
* @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
|
||||
);
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名(遵循 PKCS#7)
|
||||
* 使用指定的证书 DN,从加密设备获取对应的私钥证书,对指定的原始数据编制带公钥证书的数字签名(遵循 PKCS#7)。
|
||||
*
|
||||
* @param orgData 待签名数据
|
||||
* @param sCertDN 证书DN
|
||||
* @return
|
||||
* 符合PKCS7标准的签名结果
|
||||
*/
|
||||
String attachedSign(byte[] orgData, String sCertDN);
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||||
*
|
||||
* @param sign 已签名数据
|
||||
* @return true 验签通过 false 验签失败
|
||||
*/
|
||||
boolean attachedVerify(String sign);
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||||
*
|
||||
* @param sign 已签名数据
|
||||
* @return 成功返回签名的原数据,失败则报错
|
||||
*/
|
||||
String attachedVerifyRD(String sign);
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||||
*
|
||||
* @param sign 已签名数据
|
||||
* @return
|
||||
* 若发送报文返回证书信息标志位为0,则返回已签名数据,
|
||||
* 若发送报文返回证书信息标志位为1,则返回CERT_INFO结构的证书数据
|
||||
*/
|
||||
X509 attachedVerifyAndGetX509(String sign);
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||||
*
|
||||
* @param sign 已签名数据
|
||||
* @return
|
||||
* 若发送报文返回证书信息标志位为0,则返回已签名数据,
|
||||
* 若发送报文返回证书信息标志位为1,则返回CERT_INFO结构的证书数据
|
||||
*/
|
||||
RetWrap attachedVerifyAndGetAll(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)
|
||||
* 待签名的原始数据将在接口内部进行不带公钥的 sm3 ,然后做 Detach 签名
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sCertDN 签名者证书 DN
|
||||
* @return 签名数据
|
||||
*/
|
||||
String sm3WithoutPKDetachedSign(byte[] orgData, String sCertDN);
|
||||
|
||||
/**
|
||||
* 对指定的原始数据核验其带公钥证书签名(PKCS#7)
|
||||
* 原始数据将在接口内部进行无公钥的 sm3 ,然后做 Detach 验签
|
||||
*
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sign 签名数据
|
||||
* @return 验签是否通过
|
||||
*/
|
||||
boolean sm3WithoutPKDetachedVerify(byte[] orgData, 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
|
||||
);
|
||||
|
||||
/**
|
||||
* 带公钥证书与签名属性的数字签名(遵循 PKCS#7)
|
||||
* @param dataType 数据类型:0,hash 模式,1为非hash模式
|
||||
* @param orgData 当为hash模式时,值为hash值,当为非hash模式时,值为数据
|
||||
* @param keyTag 密钥对应的索引号
|
||||
* @return 签名的 DER 编码
|
||||
*/
|
||||
public byte[] detachedSign(
|
||||
int dataType,
|
||||
byte[] orgData,
|
||||
int keyTag
|
||||
);
|
||||
|
||||
/**
|
||||
* 带公钥证书的PKCS#7数字签名(序列号)
|
||||
* @param dataType 数据类型:0,hash 模式,1为非hash模式
|
||||
* @param orgData 当为hash模式时,值为hash值,当为非hash模式时,值为要签名的信息
|
||||
* @param certificateNo X509证书序号
|
||||
* @return 符合PKCS7标准的签名结果
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* 带公钥证书与签名属性的数字签名验签(遵循 PKCS#7)
|
||||
* @param dataType 数据类型:0,hash 模式,1为非hash模式
|
||||
* @param orgData 当为hash模式时,值为hash值,当为非hash模式时,值为数据
|
||||
* @param sign 已签名数据
|
||||
* @return 是否正确
|
||||
*/
|
||||
boolean detachedVerify(
|
||||
int dataType,
|
||||
byte[] orgData,
|
||||
byte[] sign);
|
||||
|
||||
/**
|
||||
* 对指定的原始数据核验其带公钥证书签名(PKCS#7)返回证书信息
|
||||
* 数据模式可选 DATA_HASH 或 DATA_ORIGIN
|
||||
*
|
||||
* @param dataType 输入的数据为 HASH 后的数据 DATA_HASH = 0 ,输入的数据为原始数据库 DATA_ORIGIN = 1
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sign 签名数据
|
||||
* @return 证书
|
||||
*/
|
||||
X509 detachedVerifyAndGetX509(int dataType,
|
||||
byte[] orgData,
|
||||
String sign);
|
||||
|
||||
/**
|
||||
* 计算SM3散列值
|
||||
* @param packSn 消息块号,0=仅一块,1=第一块,2=中间块,3=最后块
|
||||
* @param userId 用户 ID,只对“消息块号”为 0、1 时有效
|
||||
* @param publicKey 公钥的 DER 编码
|
||||
* @param msg 二进制的消息块
|
||||
* @param filterData 过渡消息数据,只对“消息块号”为 2、3 时有效
|
||||
* @return
|
||||
* filterData: 过渡消息数据,只对“消息块号”为 2、1 时有效
|
||||
* hash: hash
|
||||
*/
|
||||
RetWrap SM3Hash(int packSn, String userId, byte[] publicKey, byte[] msg, byte[] filterData);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
package com.sunyard.inf.cryption;
|
||||
|
||||
public interface SydASYMApi {
|
||||
/**
|
||||
* 非对称加解密接口
|
||||
*/
|
||||
/**
|
||||
* 用指定的 SM2 公钥对指定的密文数据进行加密。
|
||||
*
|
||||
* @param publicKey 公钥钥串,DER 编码,HEX 格式。
|
||||
* @param pOrgData 加密的数据。
|
||||
* @return 加密的数据 base64 编码。
|
||||
*/
|
||||
String SM2Encrypt(
|
||||
byte[] publicKey,
|
||||
byte[] pOrgData
|
||||
);
|
||||
|
||||
/**
|
||||
* 用指定的 SM2 公钥对指定的密文数据进行加密。
|
||||
*
|
||||
* @param publicKey 公钥钥串,DER 编码,HEX 格式。
|
||||
* @param pOrgData 加密的数据。
|
||||
* @return 加密的数据 der 编码。
|
||||
*/
|
||||
byte[] SYD_SM2_Encrypt(byte[] publicKey, byte[] pOrgData);
|
||||
|
||||
|
||||
/**
|
||||
* 用指定的 SM2 公钥对指定的密文数据进行加密。
|
||||
* 输出的sm2密文结构为C1C2C3格式
|
||||
* @param publicKey 公钥钥串,DER 编码,HEX 格式。
|
||||
* @param pOrgData 加密的数据。
|
||||
* @return 加密的数据 base64 编码。
|
||||
*/
|
||||
String SM2EncryptOrder(byte[] publicKey, byte[] pOrgData);
|
||||
|
||||
|
||||
/**
|
||||
* 通过使用者 ID 所对应的私钥对指定的密文数据进行解密。
|
||||
*
|
||||
* @param userId 使用者的 ID,最大长度为 16 位数字,右对齐。
|
||||
* @param pEnData 加密的数据,base64 编码。
|
||||
* @return 明文数据。
|
||||
*/
|
||||
byte[] SM2DecryptC(String userId, String pEnData);
|
||||
|
||||
/**
|
||||
* 使用外部私钥解密
|
||||
* @param sk LMK下加密的私钥
|
||||
* @param enData 密文数据(base64 编码)
|
||||
* @return 解密结果
|
||||
*/
|
||||
byte[] SM2Decrypt(byte[] sk, String enData);
|
||||
|
||||
/**
|
||||
* 使用外部私钥解密
|
||||
* @param sk LMK下加密的私钥
|
||||
* @param enData 密文数据(DER 编码)
|
||||
* @return 解密结果
|
||||
*/
|
||||
byte[] SYD_SM2_Decrypt(byte[] sk, byte[] enData);
|
||||
|
||||
/**
|
||||
* 通过使用者 ID 所对应的私钥对指定的密文数据进行解密。
|
||||
* 输入的sm2密文结构为C1C2C3格式
|
||||
* @param userId 使用者的 ID,最大长度为 16 位数字,右对齐。
|
||||
* @param enData 加密的数据,base64 编码。
|
||||
* @param keyType 密钥类型,0:签名证书, 1:加密证书。
|
||||
* @return 明文数据。
|
||||
*/
|
||||
byte[] SM2DecryptOrder(String userId, String enData, int keyType);
|
||||
|
||||
/**
|
||||
* 用指定的 RSA 私钥对指定的密文数据进行加密。
|
||||
*
|
||||
* @param publicKey 私钥串,DER 编码,HEX 格式。
|
||||
* @param pOrgData 加密的数据。
|
||||
* @return 加密的数据 base64 编码。
|
||||
*/
|
||||
String RSAEncrypt(
|
||||
String publicKey,
|
||||
byte[] pOrgData
|
||||
);
|
||||
|
||||
/**
|
||||
* 通过使用者 ID 所对应的私钥对指定的密文数据进行解密。
|
||||
*
|
||||
* @param userId 使用者的 ID,最大长度为 16 位数字,右对齐。
|
||||
* @param pEnData 加密的数据,base64 编码。
|
||||
* @return 明文数据。
|
||||
*/
|
||||
byte[] RSADecryptC(
|
||||
String userId,
|
||||
String pEnData
|
||||
) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* 使用外部私钥解密
|
||||
* @param sk
|
||||
* @param enData
|
||||
* @return
|
||||
*/
|
||||
public byte[] RSADecrypt(String sk, String enData) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* 非对称公钥加密
|
||||
* @param alg 算法标识,0 = RSA 1 = SM2
|
||||
* @param pk 公钥的 DER 编码
|
||||
* @param data 数据
|
||||
* @return 公钥加密的密文的 DER 编码(对于 RSA 算法,数据类型为 BIT).
|
||||
*/
|
||||
public byte[] encryptByPk(int alg, String pk, byte[] data);
|
||||
|
||||
/**
|
||||
* 非对称私钥解密
|
||||
* @param alg 算法标识:0 = RSA 1 = SM2
|
||||
* @param sk 私钥值,LMK下加密的私钥
|
||||
* @param data 密文数据(DER 编码)
|
||||
* @return 公钥加密的密文的 DER 编码(对于 RSA 算法,数据类型为 BIT)
|
||||
*/
|
||||
public byte[] decryptBySk(int alg, String sk, byte[] data);
|
||||
|
||||
|
||||
/**
|
||||
* 非对称私钥解密
|
||||
* @param alg 算法标识:0 = RSA 1 = SM2
|
||||
* @param userId 16位机构号
|
||||
* @param data 密文数据(DER 编码)
|
||||
* @return 公钥加密的密文的 DER 编码(对于 RSA 算法,数据类型为 BIT).
|
||||
*/
|
||||
public byte[] decryptBySkC(int alg, String userId, byte[] data);
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package com.sunyard.inf.cryption;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
|
||||
/**
|
||||
* Hash 算法接口
|
||||
*/
|
||||
public interface SydHashApi {
|
||||
|
||||
/**
|
||||
* 计算SM3散列值
|
||||
* @param sn 证书序号
|
||||
* @param userId 用户ID
|
||||
* @param msg 原始数据,二进制的消息块
|
||||
* @return
|
||||
*/
|
||||
// byte[] SM3HashSNaId(String sn, String userId, byte[] msg);
|
||||
|
||||
/**
|
||||
* 输入对指定的原始数据和公钥,通过 SM3 算法计算数据的散列值。
|
||||
* @param publicKey 公钥的 DER 编码(可以为空)
|
||||
* @param msg 原始数据,二进制的消息块
|
||||
* @param block 消息块标志
|
||||
* @param mac 上一轮 mac 值,当 mac 不是 null,长度不为 0,则直接从第二包开始。
|
||||
* @return HASH 值,32 个 Bytes.
|
||||
*/
|
||||
byte[] SM3Hash(String publicKey, byte[] msg, int block, byte[] mac);
|
||||
|
||||
/**
|
||||
* 计算SM3散列值
|
||||
* @param publicKey 公钥的 DER 编码 (03420004 开头)
|
||||
* @param userId 用户ID
|
||||
* @param msg 原始数据,二进制的消息块
|
||||
* @return
|
||||
*/
|
||||
byte[] SM3Hash(String publicKey, String userId, byte[] msg);
|
||||
|
||||
/**
|
||||
* 输入对指定的原始数据和公钥,通过 SM3 算法计算数据的散列值。
|
||||
*
|
||||
* @param publicKey 公钥(可以为空)
|
||||
* @param msg 原始数据
|
||||
* @return HASH 值,32 个 Bytes.
|
||||
*/
|
||||
byte[] SM3Hash(String publicKey, byte[] msg);
|
||||
|
||||
|
||||
/**
|
||||
* 输入对指定的原始数据 (无公钥),通过 SM3 算法计算数据的散列值。
|
||||
*
|
||||
* @param msg 原始数据
|
||||
* @return HASH 值,32 个 Bytes.
|
||||
*/
|
||||
byte[] SM3Hash(byte[] msg);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
public RetWrap countHash(int hashType, int packSn, byte[] msg, byte[] filterData);
|
||||
|
||||
public byte[] itHash(int hashType, byte[] orgData);
|
||||
}
|
||||
@@ -1,282 +0,0 @@
|
||||
package com.sunyard.inf.cryption;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
/**
|
||||
* 对称加解密接口
|
||||
*/
|
||||
public interface SydSYMApi {
|
||||
|
||||
/**
|
||||
* E0 指令复合接口
|
||||
* @param isEn 指定加解密,true为加密,false为解密
|
||||
* @param nAlg 密钥模式,当isEn为true时,默认为SM4加密,0为DES加密,1为AES256 加密。当isEn为false时,默认为SM4解密,0为DES解密,1为AES256解密
|
||||
* @param seesionKey 密钥
|
||||
* @param roundmod 轮模式,密钥加密模式:1=ECB,2=CBC,3=CFB,4=OFB
|
||||
* @param fullMode 填充模式:0为饥饿模式,1为贪婪模式
|
||||
* @param pInData 消息数据
|
||||
* @param iv IV
|
||||
* @param block 消息块号
|
||||
* @return
|
||||
* iv: IV 数据域
|
||||
* msg_all: 消息数据
|
||||
*/
|
||||
RetWrap SYMEnDeData(Boolean isEn, int nAlg, String seesionKey, int roundmod, int fullMode, byte[] pInData, byte[] iv, int block);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用输入的会话密钥,对指定报文数据进行加密处理。填充模式为1
|
||||
*
|
||||
* @param nAlg 算法标识., 0x00:3DES,0x01:SM4。
|
||||
* @param seesionKey 本地LMK 加密的会话密钥,HEX 格式
|
||||
* @param pINdata 要加密的报文明文。必须是 8 或16 的倍数。
|
||||
* @return 输出的报文密文, 长度为报文明文 + 16
|
||||
*/
|
||||
byte[] SYMEncryptData(int nAlg, String seesionKey, byte[] pINdata);
|
||||
|
||||
/**
|
||||
* 对指定报文数据进行SM4加密
|
||||
* @param type 密钥类型。0: ZEK,1: TEK
|
||||
* @param userId 生成密钥时的机构号。
|
||||
* @param index 密钥索引
|
||||
* @param data 待加密的数据
|
||||
* @return
|
||||
*/
|
||||
byte[] SYMSM4EncDataByIndex(int type, String userId, String index, byte[] data);
|
||||
|
||||
/**
|
||||
* 用输入的会话密钥,对指定报文数据进行加密处理。
|
||||
*
|
||||
* @param nAlg 算法标识.,0x00:3DES,0x01:SM4。
|
||||
* @param seesionKey 本地LMK 加密的会话密钥,HEX 格式
|
||||
* @param fullmode 填充模式:0为饥饿模式,1为贪婪模式
|
||||
* @param pINdata 要加密的报文明文。必须是 8 或16 的倍数。
|
||||
* @return 输出的报文密文, 长度为报文明文 + 16
|
||||
*/
|
||||
byte[] SYMEncryptData(int nAlg, String seesionKey, int fullmode, byte[] pINdata);
|
||||
|
||||
|
||||
// List<byte[]> SYMEncryptDecryptBatchData(int nAlg, String[] seesionKey, int fullmode, List<byte[]> pINdata);
|
||||
|
||||
/**
|
||||
* 用输入的会话密钥,对指定报文数据进行加密处理。
|
||||
*
|
||||
* @param nAlg 算法标识.,0x00:3DES,0x01:SM4。
|
||||
* @param seesionKey 本地LMK 加密的会话密钥,HEX 格式
|
||||
* @param pInData 要加密的报文明文。必须是 8 或16 的倍数。
|
||||
* @return 输出的报文密文, 长度为报文明文 + 16
|
||||
*/
|
||||
byte[] SYMEncryptData_nofill(int nAlg, String seesionKey, byte[] pInData);
|
||||
|
||||
|
||||
/**
|
||||
* 用输入的会话密钥,对指定报文数据进行解密处理。填充模式为1
|
||||
*
|
||||
* @param nAlg 算法标识.0x00:3DES,0x01:SM4。
|
||||
* @param seesionKey 本地LMK 加密的会话密钥,HEX 格式
|
||||
* @param pINdata 要解密的报文密文。长度必须是8 或16 的倍数。
|
||||
* @return 输出的报文明文。
|
||||
*/
|
||||
byte[] SYMDecryptData(int nAlg, String seesionKey, byte[] pINdata);
|
||||
|
||||
/**
|
||||
* 用输入的会话密钥,对指定报文数据进行解密处理。
|
||||
*
|
||||
* @param nAlg 算法标识.,0x00:3DES,0x01:SM4。
|
||||
* @param seesionKey 本地LMK 加密的会话密钥,HEX 格式
|
||||
* @param fullmode 填充模式:0为饥饿模式,1为贪婪模式
|
||||
* @param pINdata 要解密的报文密文。长度必须是8 或16 的倍数。
|
||||
* @return 输出的报文明文。
|
||||
*/
|
||||
byte[] SYMDecryptData(int nAlg, String seesionKey, int fullmode, byte[] pINdata);
|
||||
|
||||
/**
|
||||
* 用输入的会话密钥,对指定报文数据进行解密处理。
|
||||
*
|
||||
* @param nAlg 算法标识.,0x00:3DES,0x01:SM4。
|
||||
* @param seesionKey 本地LMK 加密的会话密钥,HEX 格式
|
||||
* @param pInData 要解密的报文密文。长度必须是8 或16 的倍数。
|
||||
* @return 输出的报文明文。
|
||||
*/
|
||||
byte[] SYMDecryptData_nofill(int nAlg, String seesionKey, byte[] pInData);
|
||||
|
||||
/**
|
||||
* 加解密数据(E1)
|
||||
* @param nAlg 密钥模式,默认为SM4解密,0:DES加密,1:AES256 解密
|
||||
* @param seesionKey 密钥
|
||||
* @param inputPath 输入消息数据的文件路径
|
||||
* @param outputPath 输出消息数据的文件路径
|
||||
* @return
|
||||
*/
|
||||
boolean SYMDecryptDataWithFile(int nAlg, String seesionKey, String inputPath, String outputPath) throws Exception;
|
||||
|
||||
/**
|
||||
* 使用SM4算法进行加密,其中加密模式为CBC,
|
||||
* Ⅳ使用缺省值0X 00000000000000000000000000000000,
|
||||
* 补位模式为 PKCS5 PADDING 。
|
||||
* @param keyType 密钥类型 0: ZEK,1: TEK
|
||||
* @param key 密钥
|
||||
* @param inType 输入消息类型 0:二进制 1:扩展十六进制
|
||||
* @param outType 输出消息类型 0:二进制 1:扩展十六进制
|
||||
* @param inFilePath 需要加密的数据文件所在的路径
|
||||
* @param outFilePath 加密后的密文数据将要保存的文件路径
|
||||
* @return 加密是否成功。false为失败,true为成功
|
||||
*/
|
||||
boolean SM4EncryptFileDataCBC(int keyType, String key, int inType, int outType, String inFilePath, String outFilePath);
|
||||
|
||||
/**
|
||||
* 使用SM4算法进行加密,其中加密模式为CBC,
|
||||
* Ⅳ使用缺省值0X 00000000000000000000000000000000,
|
||||
* 补位模式为 PKCS5 PADDING 。
|
||||
* @param keyType 密钥类型 0: ZEK,1: TEK
|
||||
* @param key 密钥
|
||||
* @param inType 输入消息类型 0:二进制 1:扩展十六进制
|
||||
* @param outType 输出消息类型 0:二进制 1:扩展十六进制
|
||||
* @param msg 消息数据
|
||||
* @return 输出的报文密文
|
||||
*/
|
||||
byte[] SM4EncryptDataCBC(int keyType, String key, int inType, int outType, byte[] msg);
|
||||
|
||||
/**
|
||||
* 使用SM4算法进行解密,其中加密模式为CBC,
|
||||
* Ⅳ使用缺省值0X 00000000000000000000000000000000,
|
||||
* 补位模式为 PKCS5 PADDING 。
|
||||
* @param keyType 密钥类型 0: ZEK,1: TEK
|
||||
* @param key 密钥
|
||||
* @param inType 输入消息类型 0:二进制 1:扩展十六进制
|
||||
* @param outType 输出消息类型 0:二进制 1:扩展十六进制
|
||||
* @param inFilePath 加密后的密文数据将要保存的文件路径
|
||||
* @param outFilePath 解密后的数据文件所在的路径
|
||||
* @return 解密是否成功。false为失败,true为成功
|
||||
*/
|
||||
boolean SM4DecryptFileDataCBC(int keyType, String key, int inType, int outType, String inFilePath, String outFilePath) throws UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* 使用SM4算法进行解密,其中加密模式为CBC,
|
||||
* Ⅳ使用缺省值0X 00000000000000000000000000000000,
|
||||
* 补位模式为 PKCS5 PADDING 。
|
||||
* @param keyType 密钥类型 0: ZEK,1: TEK
|
||||
* @param key 密钥
|
||||
* @param inType 输入消息类型 0:二进制 1:扩展十六进制
|
||||
* @param outType 输出消息类型 0:二进制 1:扩展十六进制
|
||||
* @param msg 加密后的消息数据
|
||||
* @return 输出的报文明文
|
||||
*/
|
||||
byte[] SM4DecryptDataCBC(int keyType, String key, int inType, int outType, byte[] msg);
|
||||
|
||||
/**
|
||||
* 用输入的会话密钥,对指定报文数据进行加密处理。
|
||||
*
|
||||
* @param nAlg 算法标识.,0x00:3DES,0x01:SM4。
|
||||
* @param seesionKey 本地LMK 加密的会话密钥,HEX 格式
|
||||
* @param pINdata 要加密的报文明文。必须是 8 或16 的倍数。
|
||||
* @return 输出的报文密文, 长度为报文明文 + 16
|
||||
*/
|
||||
byte[] SYMEncryptDataCBC(int nAlg, String seesionKey, byte[] pINdata);
|
||||
|
||||
/**
|
||||
* 用输入的会话密钥,对指定报文数据进行加密处理。
|
||||
*
|
||||
* @param nAlg 算法标识.,0x00:3DES,0x01:SM4。
|
||||
* @param seesionKey 本地LMK 加密的会话密钥,HEX 格式
|
||||
* @param fullmode 填充模式:0为饥饿模式,1为贪婪模式
|
||||
* @param pInData 要加密的报文明文。必须是 8 或16 的倍数。
|
||||
* @return 输出的报文密文, 长度为报文明文 + 16
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* 用输入的会话密钥,对指定报文数据进行解密处理。
|
||||
*
|
||||
* @param nAlg 算法标识.,0x00:3DES,0x01:SM4。
|
||||
* @param seesionKey 本地LMK 加密的会话密钥,HEX 格式
|
||||
* @param fullmode 填充模式:0为饥饿模式,1为贪婪模式
|
||||
* @param pInData 要解密的报文密文。长度必须是8 或16 的倍数。
|
||||
* @return 输出的报文明文。
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* 对称加密数据
|
||||
* @param key 索引地址,指示用户密钥存储区的27位地址
|
||||
* @param intPutData 消息数据
|
||||
* @return
|
||||
* iv: IV 数据域
|
||||
* msg_all: 消息数据
|
||||
*/
|
||||
public String SYMEncrytByKeyIndex( String key, String intPutData);
|
||||
|
||||
/**
|
||||
* 对称解密数据
|
||||
* @param key 索引地址,指示用户密钥存储区的27位地址
|
||||
* @param intPutData 消息数据
|
||||
* @return 消息数据
|
||||
*/
|
||||
public String SYMDecrytByKeyIndex(String key,String intPutData);
|
||||
|
||||
//通过索引读取对称秘钥
|
||||
RetWrap readKey(String index);
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.sunyard.inf.customize;
|
||||
/**
|
||||
* 上清所数字信封类接口
|
||||
*/
|
||||
public interface Syd4DigitalEnvelope {
|
||||
|
||||
/**
|
||||
* 产生对称密钥,通过清算所公钥证书加密生成数字信封。
|
||||
* 上清所
|
||||
* @param pcDnEN: 清算所的公钥证书
|
||||
* @param pcDnSign:会员的私钥证书
|
||||
* @param pcData: 明文数据。
|
||||
* @return pcSignData: 签名数字信封
|
||||
*/
|
||||
public String SYD_SignDigitalEnvelope (String pcDnEN, String pcDnSign, byte[] pcData);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 利用清算所公钥证书对签名数据进行验签。接收用会员的私钥证书解密数字信封,还原原文。
|
||||
* 上清所
|
||||
* @param pcDnDe: 会员的私钥证书
|
||||
* @param pcDnVerify: 清算所公钥证书
|
||||
* @param pcSignData: 签名数字信封数据。
|
||||
* @return pcData:原数据
|
||||
*/
|
||||
public byte[] SYD_VerifyDigitalEnveloe(String pcDnDe, String pcDnVerify, String pcSignData );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -117,16 +117,9 @@ public interface SydHAApi {
|
||||
* @param nOrgDataType 签名数据类型,SydApi.DATA_ORIGIN(1) 原始数据 SydApi.DATA_HASH(0) : hash 后的类型
|
||||
* @param publicKey 公钥串,DER编码,HEX格式
|
||||
* @param orgData 待签名的原始数据,“签名数据类型”为 0 时:HASH 值。“签名数据类型”为 1 时:要签名的信息
|
||||
* @param sign S+R
|
||||
* @param base64Sign 签名数据 (DER 编码 + Base64 编码)
|
||||
* @return 验签是否通过
|
||||
*/
|
||||
public boolean SM2Verify(
|
||||
int nOrgDataType,
|
||||
byte[] publicKey,
|
||||
byte[] orgData,
|
||||
byte[] sign
|
||||
);
|
||||
|
||||
public boolean SM2Verify(
|
||||
int nOrgDataType,
|
||||
byte[] publicKey,
|
||||
|
||||
@@ -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<String, Object> packet = new HashMap<String, Object>();
|
||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||
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<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");
|
||||
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<String, Object> packet = new HashMap<String, Object>();
|
||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||
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<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");
|
||||
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<String, Object> packet = new HashMap<String, Object>();
|
||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||
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<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");
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,212 +0,0 @@
|
||||
package com.sunyard.inf.sva;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.cert.X509;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* 带原文的签名验签
|
||||
*/
|
||||
public interface SydAttachedSVApi {
|
||||
|
||||
/**
|
||||
* sm2私钥签名
|
||||
* 用户id默认为1234567812345678
|
||||
* 签名结果R/S序列串先进行der编码,再进行base64编码
|
||||
*
|
||||
* @param flag 私钥标志位,当为1时第二个参数传入存储私钥的索引,当为0时第二个参数传入私钥
|
||||
* @param privateKey 当私钥标志位为1时传入存储私钥的索引,当为0时传入私钥
|
||||
* @param publicKey 公钥
|
||||
* @param orgData 要签名的信息
|
||||
* @return 签名结果
|
||||
*/
|
||||
byte[] SM2SignC(int flag, String privateKey, byte[] publicKey, byte[] orgData);
|
||||
byte[] SM2SignC(int flag, String pUserID, String privateKey, byte[] publicKey, byte[] orgData);
|
||||
/**
|
||||
* 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验签
|
||||
* 用户id默认为1234567812345678
|
||||
*
|
||||
* @param publicKey 公钥的 DER 编码
|
||||
* @param orgData 要签名的信息
|
||||
* @param base64Sign 计算的签名,签名结果R/S序列串先进行der编码,再进行base64编码后的结果
|
||||
* @return true 验签成功,false 验签失败
|
||||
*/
|
||||
boolean SM2Verify(byte[] publicKey, byte[] orgData, String base64Sign);
|
||||
|
||||
/**
|
||||
* 采用 SM2 算法,用指定的公钥对指定的原始数据进行数字签名验证。
|
||||
* @param certNo id 用于计算SM3-HASH
|
||||
* @param nOrgDataType 原始数据类型 0 : hash 1 : 原数据,用1.2.3章节限定符亦可
|
||||
* @param publicKey 公钥
|
||||
* @param orgData 原始数据
|
||||
* @param sign base64 格式的签名
|
||||
* @return true 验签通过 false 验签失败
|
||||
*/
|
||||
boolean SM2Verify(
|
||||
String certNo,
|
||||
int nOrgDataType,
|
||||
byte[] publicKey,
|
||||
byte[] orgData,
|
||||
byte[] 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
|
||||
);
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名(遵循 PKCS#7)
|
||||
* 使用指定的证书 DN,从加密设备获取对应的私钥证书,对指定的原始数据编制带公钥证书的数字签名(遵循 PKCS#7)。
|
||||
*
|
||||
* @param orgData 待签名数据
|
||||
* @param sCertDN 证书DN
|
||||
* @return
|
||||
* 符合PKCS7标准的签名结果
|
||||
*/
|
||||
String attachedSign(byte[] orgData, String sCertDN) throws UnsupportedEncodingException;
|
||||
byte[] attachedSignC(byte[] orgData, String sCertDN);
|
||||
|
||||
|
||||
/**
|
||||
* 人行项目需要需要支持RSA
|
||||
* 带公钥证书与原始数据的数字签名(遵循 PKCS#7)
|
||||
* 使用指定的证书 DN,从加密设备获取对应的私钥证书,对指定的原始数据编制带公钥证书的数字签名(遵循 PKCS#7)。
|
||||
*
|
||||
* @param orgData 待签名数据
|
||||
* @param sCertDN 证书DN
|
||||
* @return
|
||||
* 符合PKCS7标准的签名结果
|
||||
*/
|
||||
String attachedSignRSA(int rFlag,byte[] orgData, String sCertDN) throws UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||||
*
|
||||
* @param sign 已签名数据
|
||||
* @return true 验签通过 false 验签失败
|
||||
*/
|
||||
boolean attachedVerify(String sign);
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||||
*
|
||||
* @param sign 已签名数据
|
||||
* @return true 验签通过 false 验签失败
|
||||
*/
|
||||
boolean attachedVerifyRSA(int rFlag,String sign);
|
||||
|
||||
|
||||
boolean attachedVerify(byte[] sign);
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||||
*
|
||||
* @param sign 已签名数据
|
||||
* @return 成功返回签名的原数据,失败则报错
|
||||
*/
|
||||
byte[] attachedVerifyRD(byte[] sign);
|
||||
byte[] attachedVerifyRD(String sign);
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||||
*
|
||||
* @param sign 已签名数据
|
||||
* @return
|
||||
* 若发送报文返回证书信息标志位为0,则返回已签名数据,
|
||||
* 若发送报文返回证书信息标志位为1,则返回CERT_INFO结构的证书数据
|
||||
*/
|
||||
X509 attachedVerifyAndGetX509(byte[] sign);
|
||||
X509 attachedVerifyAndGetX509(String sign);
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||||
*
|
||||
* @param sign 已签名数据
|
||||
* @return
|
||||
* 若发送报文返回证书信息标志位为0,则返回已签名数据,
|
||||
* 若发送报文返回证书信息标志位为1,则返回CERT_INFO结构的证书数据
|
||||
*/
|
||||
RetWrap attachedVerifyAndGetAll(byte[] sign);
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
package com.sunyard.inf.sva;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.cert.X509;
|
||||
|
||||
/**
|
||||
* 不带原文的签名验签
|
||||
*/
|
||||
public 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)
|
||||
* 待签名的原始数据将在接口内部进行不带公钥的 sm3 ,然后做 Detach 签名
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sCertDN 签名者证书 DN
|
||||
* @return 签名数据
|
||||
*/
|
||||
String sm3WithoutPKDetachedSign(byte[] orgData, String sCertDN);
|
||||
|
||||
/**
|
||||
* 对指定的原始数据核验其带公钥证书签名(PKCS#7)
|
||||
* 原始数据将在接口内部进行无公钥的 sm3 ,然后做 Detach 验签
|
||||
*
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sign 签名数据
|
||||
* @return 验签是否通过
|
||||
*/
|
||||
boolean sm3WithoutPKDetachedVerify(byte[] orgData, 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
|
||||
);
|
||||
|
||||
/**
|
||||
* 带公钥证书与签名属性的数字签名(遵循 PKCS#7)
|
||||
* @param dataType 数据类型:0,hash 模式,1为非hash模式
|
||||
* @param orgData 当为hash模式时,值为hash值,当为非hash模式时,值为数据
|
||||
* @param keyTag 密钥对应的索引号
|
||||
* @return 签名的 DER 编码
|
||||
*/
|
||||
public byte[] detachedSign(
|
||||
int dataType,
|
||||
byte[] orgData,
|
||||
int keyTag
|
||||
);
|
||||
|
||||
/**
|
||||
* 带公钥证书的PKCS#7数字签名(序列号)
|
||||
* @param dataType 数据类型:0,hash 模式,1为非hash模式
|
||||
* @param orgData 当为hash模式时,值为hash值,当为非hash模式时,值为要签名的信息
|
||||
* @param certificateNo X509证书序号
|
||||
* @return 符合PKCS7标准的签名结果
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* 带公钥证书与签名属性的数字签名验签(遵循 PKCS#7)
|
||||
* @param dataType 数据类型:0,hash 模式,1为非hash模式
|
||||
* @param orgData 当为hash模式时,值为hash值,当为非hash模式时,值为数据
|
||||
* @param sign 已签名数据
|
||||
* @return 是否正确
|
||||
*/
|
||||
boolean detachedVerify(
|
||||
int dataType,
|
||||
byte[] orgData,
|
||||
byte[] sign);
|
||||
|
||||
/**
|
||||
* 对指定的原始数据核验其带公钥证书签名(PKCS#7)返回证书信息
|
||||
* 数据模式可选 DATA_HASH 或 DATA_ORIGIN
|
||||
*
|
||||
* @param dataType 输入的数据为 HASH 后的数据 DATA_HASH = 0 ,输入的数据为原始数据库 DATA_ORIGIN = 1
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sign 签名数据
|
||||
* @return 证书
|
||||
*/
|
||||
X509 detachedVerifyAndGetX509(int dataType,
|
||||
byte[] orgData,
|
||||
String sign);
|
||||
|
||||
/**
|
||||
* 计算SM3散列值
|
||||
* @param packSn 消息块号,0=仅一块,1=第一块,2=中间块,3=最后块
|
||||
* @param userId 用户 ID,只对“消息块号”为 0、1 时有效
|
||||
* @param publicKey 公钥的 DER 编码
|
||||
* @param msg 二进制的消息块
|
||||
* @param filterData 过渡消息数据,只对“消息块号”为 2、3 时有效
|
||||
* @return
|
||||
* filterData: 过渡消息数据,只对“消息块号”为 2、1 时有效
|
||||
* hash: hash
|
||||
*/
|
||||
RetWrap SM3Hash(int packSn, String userId, byte[] publicKey, byte[] msg, byte[] filterData);
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.sunyard.inf.sva;
|
||||
|
||||
/**
|
||||
* 不经过 CA 授信
|
||||
* 直接使用公私钥对签名验签
|
||||
*/
|
||||
public 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
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
package com.sunyard.log;
|
||||
|
||||
public interface ILogFactory {
|
||||
ILogger getLogger(Class cls);
|
||||
}
|
||||
package com.sunyard.log;
|
||||
|
||||
public interface ILogFactory {
|
||||
ILogger getLogger(Class var1);
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.sunyard.log;
|
||||
|
||||
public interface ILogger {
|
||||
|
||||
public int getCurrentLogLevel();
|
||||
|
||||
public void error(String msg, Object ...params);
|
||||
public void info(String msg, Object ...params);
|
||||
public void debug(String msg, Object ...params);
|
||||
|
||||
}
|
||||
package com.sunyard.log;
|
||||
|
||||
public interface ILogger {
|
||||
int getCurrentLogLevel();
|
||||
|
||||
void error(String var1, Object... var2);
|
||||
|
||||
void info(String var1, Object... var2);
|
||||
|
||||
void debug(String var1, Object... var2);
|
||||
|
||||
boolean isDebugEnabled();
|
||||
}
|
||||
|
||||
@@ -1,118 +1,101 @@
|
||||
package com.sunyard.log;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class SydLogFactory implements ILogFactory {
|
||||
// 日期格式
|
||||
private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
// 日志目录
|
||||
public static String pcLogPath = "./sydapi-logs/";
|
||||
|
||||
// 日志名
|
||||
public static final String logName = "sydapi-log";
|
||||
|
||||
// 日志级别
|
||||
public static int iLogLevel = 0;
|
||||
|
||||
// 日志队列
|
||||
private static ConcurrentLinkedQueue<SydLogInfo> queue = new ConcurrentLinkedQueue<SydLogInfo>();
|
||||
|
||||
// 调试标记
|
||||
public static boolean debug = false;
|
||||
|
||||
// 后台打印进程
|
||||
private static Executor executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
static {
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String logFileName = "";
|
||||
FileOutputStream logFos = null;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
|
||||
if (queue.isEmpty()) {
|
||||
// 释放 CPU
|
||||
Thread.sleep(500);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 有日志
|
||||
// 确认日期
|
||||
String mayLogFileName = String.format("%s_%s.log", logName, format.format( new Date()));
|
||||
if ( ! logFileName.equals( mayLogFileName ) ) {
|
||||
logFileName = mayLogFileName;
|
||||
if ( null != logFos ) {
|
||||
logFos.flush();
|
||||
logFos.close();
|
||||
}
|
||||
File folder = new File( pcLogPath );
|
||||
if ( ! folder.exists() ) {
|
||||
folder.mkdirs();
|
||||
}
|
||||
|
||||
File f = new File( pcLogPath, logFileName );
|
||||
if ( ! f.exists() ) {
|
||||
f.createNewFile();
|
||||
}
|
||||
logFos = new FileOutputStream( f , true);
|
||||
}
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
SydLogInfo info = queue.poll();
|
||||
logFos.write(String.format("[%d:%s <%s-%d>] %s\r\n",
|
||||
info.getLevel(),
|
||||
format.format( new Date(info.getDatatime()) ),
|
||||
info.getTname(),
|
||||
info.getTid(),
|
||||
info.getMsg()
|
||||
).getBytes()
|
||||
);
|
||||
}
|
||||
logFos.flush();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
closeFileOutputStream(logFos);
|
||||
logFileName = "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static void closeFileOutputStream(FileOutputStream fos){
|
||||
if ( null != fos ) {
|
||||
try {
|
||||
fos.flush();
|
||||
}catch (Exception e) {
|
||||
//pass
|
||||
}
|
||||
|
||||
try {
|
||||
fos.close();
|
||||
}catch (Exception e) {
|
||||
//pass
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SydLogFactory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILogger getLogger(Class cls) {
|
||||
return new SydLogger(queue);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.sunyard.log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class SydLogFactory implements ILogFactory {
|
||||
private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
public static String pcLogPath = "./sydapi-logs/";
|
||||
public static final String logName = "sydapi-log";
|
||||
public static int iLogLevel = 0;
|
||||
private static ConcurrentLinkedQueue<SydLogInfo> queue = new ConcurrentLinkedQueue();
|
||||
public static boolean debug = false;
|
||||
private static Executor executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
static {
|
||||
executor.execute(new Runnable() {
|
||||
public void run() {
|
||||
String logFileName = "";
|
||||
FileOutputStream logFos = null;
|
||||
|
||||
while(true) {
|
||||
while(true) {
|
||||
while(true) {
|
||||
try {
|
||||
if (SydLogFactory.queue.isEmpty()) {
|
||||
Thread.sleep(500L);
|
||||
} else {
|
||||
String mayLogFileName = String.format("%s_%s.log", "sydapi-log", SydLogFactory.format.format(new Date()));
|
||||
if (!logFileName.equals(mayLogFileName)) {
|
||||
logFileName = mayLogFileName;
|
||||
if (logFos != null) {
|
||||
logFos.flush();
|
||||
logFos.close();
|
||||
}
|
||||
|
||||
File folder = new File(SydLogFactory.pcLogPath);
|
||||
if (!folder.exists()) {
|
||||
folder.mkdirs();
|
||||
}
|
||||
|
||||
File f = new File(SydLogFactory.pcLogPath, logFileName);
|
||||
if (!f.exists()) {
|
||||
f.createNewFile();
|
||||
}
|
||||
|
||||
logFos = new FileOutputStream(f, true);
|
||||
}
|
||||
|
||||
while(!SydLogFactory.queue.isEmpty()) {
|
||||
SydLogInfo info = (SydLogInfo)SydLogFactory.queue.poll();
|
||||
logFos.write(String.format("[%d:%s <%s-%d>] %s\r\n", info.getLevel(), SydLogFactory.format.format(new Date(info.getDatatime())), info.getTname(), info.getTid(), info.getMsg()).getBytes());
|
||||
}
|
||||
|
||||
logFos.flush();
|
||||
}
|
||||
} catch (Exception var9) {
|
||||
Exception e = var9;
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
SydLogFactory.closeFileOutputStream(logFos);
|
||||
logFileName = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void closeFileOutputStream(FileOutputStream fos) {
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.flush();
|
||||
} catch (Exception var2) {
|
||||
}
|
||||
|
||||
try {
|
||||
fos.close();
|
||||
} catch (Exception var1) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private SydLogFactory() {
|
||||
}
|
||||
|
||||
public ILogger getLogger(Class cls) {
|
||||
return new SydLogger(queue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,48 @@
|
||||
package com.sunyard.log;
|
||||
|
||||
|
||||
public class SydLogInfo {
|
||||
private int level;
|
||||
private long datatime;
|
||||
private String tname;
|
||||
private long tid;
|
||||
private String msg;
|
||||
private Object[] objects;
|
||||
|
||||
public SydLogInfo(int level, String msg, Object[] objects) {
|
||||
this.level = level;
|
||||
this.msg = msg;
|
||||
this.objects = objects;
|
||||
this.datatime = System.currentTimeMillis();
|
||||
this.tname = Thread.currentThread().getName();
|
||||
this.tid = Thread.currentThread().getId();
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public long getDatatime() {
|
||||
return datatime;
|
||||
}
|
||||
|
||||
public String getTname() {
|
||||
return tname;
|
||||
}
|
||||
|
||||
public long getTid() {
|
||||
return tid;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public Object[] getObjects() {
|
||||
return objects;
|
||||
}
|
||||
}
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.sunyard.log;
|
||||
|
||||
public class SydLogInfo {
|
||||
private int level;
|
||||
private long datatime;
|
||||
private String tname;
|
||||
private long tid;
|
||||
private String msg;
|
||||
private Object[] objects;
|
||||
|
||||
public SydLogInfo(int level, String msg, Object[] objects) {
|
||||
this.level = level;
|
||||
this.msg = msg;
|
||||
this.objects = objects;
|
||||
this.datatime = System.currentTimeMillis();
|
||||
this.tname = Thread.currentThread().getName();
|
||||
this.tid = Thread.currentThread().getId();
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
public long getDatatime() {
|
||||
return this.datatime;
|
||||
}
|
||||
|
||||
public String getTname() {
|
||||
return this.tname;
|
||||
}
|
||||
|
||||
public long getTid() {
|
||||
return this.tid;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return this.msg;
|
||||
}
|
||||
|
||||
public Object[] getObjects() {
|
||||
return this.objects;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,47 @@
|
||||
package com.sunyard.log;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class SydLogger implements ILogger{
|
||||
|
||||
private ConcurrentLinkedQueue<SydLogInfo> queue;
|
||||
|
||||
SydLogger(ConcurrentLinkedQueue<SydLogInfo> queue) {
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
public void debug(String msg, Object... params) {
|
||||
if (SydLogFactory.iLogLevel == 3) {
|
||||
this.queue.add(new SydLogInfo(3, msg, params));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void info(String msg, Object... params) {
|
||||
if (SydLogFactory.iLogLevel >= 2) {
|
||||
this.queue.add(new SydLogInfo(2, msg, params));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void error(String msg, Object... params) {
|
||||
if (SydLogFactory.iLogLevel >= 1) {
|
||||
this.queue.add(new SydLogInfo(1, msg, params));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentLogLevel() {
|
||||
return SydLogFactory.iLogLevel;
|
||||
}
|
||||
|
||||
}
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.sunyard.log;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class SydLogger implements ILogger {
|
||||
private ConcurrentLinkedQueue<SydLogInfo> queue;
|
||||
|
||||
SydLogger(ConcurrentLinkedQueue<SydLogInfo> queue) {
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String msg, Object... params) {
|
||||
if (SydLogFactory.iLogLevel == 3) {
|
||||
this.queue.add(new SydLogInfo(3, msg, params));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return SydLogFactory.iLogLevel == 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg, Object... params) {
|
||||
if (SydLogFactory.iLogLevel >= 2) {
|
||||
this.queue.add(new SydLogInfo(2, msg, params));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg, Object... params) {
|
||||
if (SydLogFactory.iLogLevel >= 1) {
|
||||
this.queue.add(new SydLogInfo(1, msg, params));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentLogLevel() {
|
||||
return SydLogFactory.iLogLevel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.sunyard.pool;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 到加密机的链接信息
|
||||
*/
|
||||
public class HsmLinkInfo {
|
||||
private String pcIp;
|
||||
private int iPort;
|
||||
private int iConnectTimeOut;
|
||||
private int iDealTimeOut;
|
||||
|
||||
|
||||
public HsmLinkInfo(String pcIp, int iPort, int iConnectTimeOut, int iDealTimeOut) {
|
||||
this.pcIp = pcIp;
|
||||
this.iPort = iPort;
|
||||
this.iConnectTimeOut = iConnectTimeOut;
|
||||
this.iDealTimeOut = iDealTimeOut;
|
||||
}
|
||||
|
||||
public static HsmLinkInfo[] mutiHsmLinkInfo(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iAllDealTimeOut) {
|
||||
if (null == pcIpList &&
|
||||
null == iPortList &&
|
||||
pcIpList.length != iPortList.length) {
|
||||
throw new IllegalArgumentException("入参错误");
|
||||
}
|
||||
|
||||
if ( iAllDealTimeOut < pcIpList.length) {
|
||||
throw new IllegalArgumentException("入参错误");
|
||||
}
|
||||
|
||||
// 交易时间进行处理
|
||||
int iDealTimeOut = iAllDealTimeOut / pcIpList.length;
|
||||
|
||||
|
||||
HsmLinkInfo[]hsms = new HsmLinkInfo[ pcIpList.length ];
|
||||
for ( int i = 0 ; i < pcIpList.length ; i++ ) {
|
||||
hsms[ i ] = new HsmLinkInfo( pcIpList[i], iPortList[i], iConnectTimeOut, iDealTimeOut );
|
||||
}
|
||||
|
||||
return hsms;
|
||||
}
|
||||
|
||||
|
||||
public String getPcIp() {
|
||||
return pcIp;
|
||||
}
|
||||
|
||||
public int getiPort() {
|
||||
return iPort;
|
||||
}
|
||||
|
||||
public int getiConnectTimeOut() {
|
||||
return iConnectTimeOut;
|
||||
}
|
||||
|
||||
public int getiDealTimeOut() {
|
||||
return iDealTimeOut;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.sunyard.pool;
|
||||
|
||||
public class ObjectInPool<T> {
|
||||
|
||||
private T object;
|
||||
private long lasUseAt = System.currentTimeMillis();
|
||||
|
||||
public ObjectInPool(T object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public T getObjectForCheck() {
|
||||
return this.object;
|
||||
}
|
||||
|
||||
public void updateLastUseTime(){
|
||||
this.lasUseAt = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public T getObject() {
|
||||
this.lasUseAt = System.currentTimeMillis();
|
||||
return this.object;
|
||||
}
|
||||
|
||||
public long getLasUseAt() {
|
||||
return this.lasUseAt;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.sunyard.pool;
|
||||
|
||||
public class PoolConfig {
|
||||
|
||||
// 最大空闲时间
|
||||
private long maxIdle = 5 * 60 *1000; // 5 分钟
|
||||
|
||||
// 最大无用时间
|
||||
private long maxUseless = 30 * 60 * 1000; // 30 分钟
|
||||
|
||||
public long getMaxIdle() {
|
||||
return maxIdle;
|
||||
}
|
||||
|
||||
public void setMaxIdle(long maxIdle) {
|
||||
this.maxIdle = maxIdle;
|
||||
}
|
||||
|
||||
public long getMaxUseless() {
|
||||
return maxUseless;
|
||||
}
|
||||
|
||||
public void setMaxUseless(long maxUseless) {
|
||||
this.maxUseless = maxUseless;
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package com.sunyard.pool;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.proxy.ProxyInvocationHandler;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
|
||||
private HsmLinkInfo[] linkInfos;
|
||||
|
||||
public SydApiPool(HsmLinkInfo[] linkInfos) {
|
||||
this.linkInfos = linkInfos;
|
||||
}
|
||||
|
||||
protected SydApi initialValue() {
|
||||
SydApi4j[] apis = new SydApi4j[this.linkInfos.length];
|
||||
boolean connected = false;
|
||||
|
||||
for(int i = 0; i < apis.length; ++i) {
|
||||
HsmLinkInfo info = this.linkInfos[i];
|
||||
|
||||
try {
|
||||
apis[i] = (SydApi4j)(new SydApi4j()).connect(info.getPcIp(), info.getiPort(), (String)null, info.getiConnectTimeOut(), info.getiDealTimeOut());
|
||||
connected = true;
|
||||
} catch (Exception var6) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!connected) {
|
||||
throw new SydApiException("连接错误", -1);
|
||||
} else {
|
||||
ProxyInvocationHandler proxyInvocationHandler = new ProxyInvocationHandler(apis, this.linkInfos, false);
|
||||
return proxyInvocationHandler.getProxy();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean check(SydApi s) {
|
||||
boolean ret = super.check(s);
|
||||
if (!ret) {
|
||||
return false;
|
||||
} else {
|
||||
ProxyInvocationHandler o = (ProxyInvocationHandler)s.getBindObject();
|
||||
|
||||
try {
|
||||
SydApi4j[] hsms = o.getApis();
|
||||
boolean canUse = false;
|
||||
int length = hsms.length;
|
||||
|
||||
for(int i = 0; i < length; ++i) {
|
||||
if (null != hsms[i]) {
|
||||
try {
|
||||
synchronized(hsms[i]) {
|
||||
hsms[i].GenerateRandom(1);
|
||||
canUse = true;
|
||||
}
|
||||
} catch (Exception var12) {
|
||||
hsms[i] = null;
|
||||
}
|
||||
} else {
|
||||
HsmLinkInfo[] infos = o.getApisInfos();
|
||||
HsmLinkInfo info = infos[i];
|
||||
|
||||
try {
|
||||
hsms[i] = (SydApi4j)(new SydApi4j()).connect(info.getPcIp(), info.getiPort(), (String)null, info.getiConnectTimeOut(), info.getiDealTimeOut());
|
||||
canUse = true;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return canUse;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void free(SydApi o) {
|
||||
if (null != o) {
|
||||
o.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
package com.sunyard.pool;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ThreadBasedConnectPool<T> {
|
||||
|
||||
// ThreadLocal
|
||||
private final Map<Thread, ObjectInPool<T>> map = new HashMap<Thread, ObjectInPool<T>>();
|
||||
|
||||
// 守护
|
||||
private final ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(1);
|
||||
|
||||
// 配置
|
||||
private PoolConfig config;
|
||||
|
||||
public ThreadBasedConnectPool(final PoolConfig config) {
|
||||
this.config = config;
|
||||
threadPool.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 检测和回收逻辑
|
||||
Iterator<Map.Entry<Thread, ObjectInPool<T>>> it = map.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<Thread, ObjectInPool<T>> entry = it.next();
|
||||
ObjectInPool<T> oip = entry.getValue();
|
||||
|
||||
if (System.currentTimeMillis() - oip.getLasUseAt() < config.getMaxIdle()) {
|
||||
// 空闲时间不足,免检。
|
||||
continue;
|
||||
}
|
||||
|
||||
if (System.currentTimeMillis() - oip.getLasUseAt() > config.getMaxUseless()) {
|
||||
// 长时间未使用,回收链接
|
||||
|
||||
it.remove();
|
||||
|
||||
try {
|
||||
free(oip.getObject());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean checkPass = false;
|
||||
try {
|
||||
checkPass = check(entry.getValue().getObjectForCheck());
|
||||
} catch (Exception e) {
|
||||
checkPass = false;
|
||||
}
|
||||
finally {
|
||||
}
|
||||
|
||||
if ( ! checkPass) {
|
||||
// 检查未通过
|
||||
it.remove();
|
||||
|
||||
try {
|
||||
free(oip.getObject());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}, config.getMaxIdle(), config.getMaxIdle(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public ThreadBasedConnectPool() {
|
||||
this(new PoolConfig());
|
||||
}
|
||||
|
||||
// 继承 初始化
|
||||
protected T initialValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// 保活接口
|
||||
protected boolean check(T o) {
|
||||
return null != o;
|
||||
}
|
||||
|
||||
// 释放
|
||||
protected void free(T o) {
|
||||
}
|
||||
|
||||
|
||||
// 获取
|
||||
public T get() {
|
||||
ObjectInPool<T> o = map.get(Thread.currentThread());
|
||||
if (null != o) {
|
||||
return o.getObject();
|
||||
}
|
||||
|
||||
return setInitialValue();
|
||||
}
|
||||
|
||||
// 设置
|
||||
public void set(T o) {
|
||||
map.put(Thread.currentThread(), new ObjectInPool<T>(o));
|
||||
}
|
||||
|
||||
// 清除
|
||||
public void remove() {
|
||||
map.remove(Thread.currentThread());
|
||||
}
|
||||
|
||||
protected void afterInit(ObjectInPool oip, T value ){
|
||||
|
||||
}
|
||||
|
||||
private T setInitialValue() {
|
||||
T value = initialValue();
|
||||
ObjectInPool opi = new ObjectInPool<T>(value);
|
||||
map.put(Thread.currentThread(), opi);
|
||||
afterInit( opi , value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
package com.sunyard.proxy;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.log.ILogFactory;
|
||||
import com.sunyard.log.ILogger;
|
||||
import com.sunyard.pool.HsmLinkInfo;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiMuti;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ProxyInvocationHandler implements InvocationHandler {
|
||||
|
||||
private static Map<String, SydApiException> innerFuncs = new HashMap<String, SydApiException>();
|
||||
|
||||
static {
|
||||
innerFuncs.put("connect", new SydApiException("集群连接模式,不需要该连接", 0));
|
||||
}
|
||||
|
||||
private SydApi4j[] apis;
|
||||
private HsmLinkInfo[] apisInfos;
|
||||
private boolean isShortLinkMode = true;
|
||||
|
||||
|
||||
public ProxyInvocationHandler(SydApi4j[] apis) {
|
||||
this.apis = apis;
|
||||
}
|
||||
|
||||
public ProxyInvocationHandler(SydApi4j[] apis, HsmLinkInfo[] info, boolean isShortLinkMode) {
|
||||
this.apis = apis;
|
||||
this.apisInfos = info;
|
||||
this.isShortLinkMode = isShortLinkMode;
|
||||
}
|
||||
|
||||
public SydApi4j[] getApis() {
|
||||
return apis;
|
||||
}
|
||||
|
||||
|
||||
public HsmLinkInfo[] getApisInfos() {
|
||||
return apisInfos;
|
||||
}
|
||||
|
||||
public SydApi getProxy() {
|
||||
SydApi api = (SydApi) Proxy.newProxyInstance(
|
||||
SydApi4j.class.getClassLoader(),
|
||||
new Class[]{SydApi.class},
|
||||
this
|
||||
);
|
||||
api.setBindObject( this );
|
||||
return api;
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
|
||||
if (null != apis && isShortLinkMode) {
|
||||
for (SydApi4j api4j : this.apis) {
|
||||
try {
|
||||
if (null != api4j) {
|
||||
api4j.disconnect();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//处理代理实例并返回结果
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
SydApiException le = null;
|
||||
|
||||
if ("disconnect".equals(method.getName())) {
|
||||
this.disconnect();
|
||||
}
|
||||
|
||||
// 屏蔽部分非业务接口
|
||||
if ("connect".equals(method.getName())) {
|
||||
throw new RuntimeException("不允许使用此接口");
|
||||
}
|
||||
if (innerFuncs.containsKey(method.getName())) {
|
||||
innerFuncs.get(method.getName());
|
||||
}
|
||||
|
||||
|
||||
if ("deleteCert".equals(method.getName()) || "SYD_Get_X509_CertInfo_HA".equals(method.getName())) {
|
||||
for (SydApi4j api : apis) {
|
||||
if (null == api) {
|
||||
if ("deleteCert".equals(method.getName())) {
|
||||
throw new SydApiException("删除失败",56307);
|
||||
} else {
|
||||
throw new SydApiException("导入失败",56300);
|
||||
}
|
||||
}
|
||||
try {
|
||||
|
||||
Object ret = method.invoke(api, args);
|
||||
if ( ret instanceof Boolean ) {
|
||||
if ( ! ( Boolean ) ret ) {
|
||||
throw new RuntimeException("结果错误");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SydApiException e) {
|
||||
if ("deleteCert".equals(method.getName())) {
|
||||
throw new SydApiException("删除失败",56307);
|
||||
} else {
|
||||
throw new SydApiException("导入失败",56300);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (SydApi4j api : apis) {
|
||||
if (null == api) {
|
||||
continue;
|
||||
}
|
||||
if ( isShortLinkMode ) {
|
||||
try {
|
||||
|
||||
return method.invoke(api, args);
|
||||
|
||||
} catch (SydApiException e) {
|
||||
le = e;
|
||||
if (e.getRetCode() < 0) {
|
||||
continue;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
synchronized (api) {
|
||||
try {
|
||||
return method.invoke(api, args);
|
||||
|
||||
} catch (SydApiException e) {
|
||||
le = e;
|
||||
if (e.getRetCode() < 0) {
|
||||
continue;
|
||||
}
|
||||
throw e;
|
||||
} catch ( Exception e ) {
|
||||
ILogFactory factory = SydApi4j.getLogFactory();
|
||||
if ( null != factory ) {
|
||||
ILogger logger = factory.getLogger(ProxyInvocationHandler.class);
|
||||
logger.error( "调用方法 {} 失败", method.getName() );
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw le;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package com.sunyard.util;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.proto.R;
|
||||
import com.sunyard.proto.Util;
|
||||
import org.bouncycastle.asn1.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class ASN1Util {
|
||||
|
||||
public static byte[] alignSignDer(byte[] der) {
|
||||
String base64 = Util.encodeBase64(der);
|
||||
return SYMUtil.base64SignAsDerSign(base64);
|
||||
}
|
||||
public static RetWrap takeOutOriginDataFromPKCS7Sign(String sign) throws IOException {
|
||||
RetWrap ret = new RetWrap();
|
||||
|
||||
ASN1Sequence seq = ASN1Sequence.getInstance( Util.decodeBase64( sign ) );
|
||||
ASN1TaggedObject tag = (ASN1TaggedObject) seq.getObjectAt(1).toASN1Primitive();
|
||||
ASN1Sequence seq2 = (ASN1Sequence) tag.getObject();
|
||||
ASN1Sequence seq3 = null;
|
||||
try {
|
||||
seq3 = (ASN1Sequence) seq2.getObjectAt( 2 ).toASN1Primitive();
|
||||
ASN1TaggedObject tag2 = (ASN1TaggedObject) seq3.getObjectAt( 1 );
|
||||
DEROctetString o = (DEROctetString) tag2.getObject();
|
||||
ret.put( "orgData", o.getOctets() );
|
||||
} catch (Exception e) {
|
||||
}
|
||||
ASN1TaggedObject tag3 = (ASN1TaggedObject) seq2.getObjectAt(3).toASN1Primitive();
|
||||
ASN1Sequence seq4 = (ASN1Sequence) tag3.getObject();
|
||||
ret.put("cert", CertUtil.encodeBase64(seq4.getEncoded()));
|
||||
|
||||
ASN1Sequence seq5 = (ASN1Sequence) seq4.getObjectAt( 0 ).toASN1Primitive();
|
||||
ASN1Sequence seq6 = (ASN1Sequence) seq5.getObjectAt( 6 ).toASN1Primitive();
|
||||
DERBitString pk = (DERBitString) seq6.getObjectAt( 1 ).toASN1Primitive();
|
||||
ret.put("pk", pk.getEncoded() );
|
||||
|
||||
ASN1Encodable[] elements = seq3.toArray();
|
||||
ASN1Encodable[] elements2 = new ASN1Encodable[ elements.length - 1];
|
||||
for ( int i = 0; i < elements.length -1 ; i++ ){
|
||||
elements2[i] = elements[i];
|
||||
}
|
||||
|
||||
BeanUtil.setProperty( seq3, "elements", elements2);
|
||||
|
||||
ret.put("sign", Util.encodeBase64(seq.getEncoded()) );
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String addOriginDataToPKCS7Sign( byte[] originData, String sign) throws IOException {
|
||||
ASN1Sequence seq = ASN1Sequence.getInstance( Util.decodeBase64( sign ) );
|
||||
ASN1TaggedObject tag = (ASN1TaggedObject) seq.getObjectAt(1).toASN1Primitive();
|
||||
ASN1Sequence seq2 = (ASN1Sequence) tag.getObject();
|
||||
ASN1Sequence seq3 = (ASN1Sequence) seq2.getObjectAt( 2 ).toASN1Primitive();
|
||||
|
||||
ASN1Encodable[] elements = seq3.toArray();
|
||||
ASN1Encodable[] elements2 = new ASN1Encodable[ elements.length + 1];
|
||||
for ( int i = 0; i < elements.length ; i++ ){
|
||||
elements2[i] = elements[i];
|
||||
}
|
||||
|
||||
elements2[ elements.length ] = new DERTaggedObject(true, 0, new DEROctetString( originData ));
|
||||
|
||||
BeanUtil.setProperty( seq3, "elements", elements2);
|
||||
|
||||
return Util.encodeBase64(seq.getEncoded());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
package com.sunyard.util;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.constant.CertUsage;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.security.Security;
|
||||
import java.security.cert.CertificateEncodingException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class CertUtil {
|
||||
public static String encodeBase64(byte[] data) {
|
||||
return new BASE64Encoder().encode(data);
|
||||
}
|
||||
|
||||
static {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
}
|
||||
|
||||
public static X509Certificate convertToX509Cert(String certificateString) throws CertificateException, NoSuchProviderException {
|
||||
// X509Certificate certificate = null;
|
||||
// CertificateFactory cf = null;
|
||||
// try {
|
||||
// if (certificateString != null && !certificateString.trim().isEmpty()) {
|
||||
// certificateString = certificateString.replace("-----BEGIN CERTIFICATE-----\n", "")
|
||||
// .replace("-----END CERTIFICATE-----", ""); // NEED FOR PEM FORMAT CERT STRING
|
||||
// byte[] certificateData = Base64.decode(certificateString);
|
||||
// cf = CertificateFactory.getInstance("X509");
|
||||
// certificate = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(certificateData));
|
||||
// }
|
||||
// } catch (CertificateException e) {
|
||||
// throw new CertificateException(e);
|
||||
// }
|
||||
// return certificate;
|
||||
CertificateFactory CF = CertificateFactory.getInstance("X.509", "BC"); // 从证书工厂中获取X.509的单例类
|
||||
return (X509Certificate) CF.generateCertificate(new ByteArrayInputStream(certificateString.getBytes())); // 将文件流的证书转化为证书类
|
||||
}
|
||||
|
||||
public static String convertToPem(X509Certificate cert) throws CertificateEncodingException {
|
||||
|
||||
String cert_begin = "-----BEGIN CERTIFICATE-----\n";
|
||||
String end_cert = "\n-----END CERTIFICATE-----";
|
||||
|
||||
byte[] derCert = cert.getEncoded();
|
||||
String pemCertPre = new String(Base64.encode(derCert, true));
|
||||
String pemCert = cert_begin + pemCertPre + end_cert;
|
||||
return pemCert;
|
||||
// StringWriter sw = new StringWriter();
|
||||
// PemWriter pw = new PemWriter(sw);
|
||||
// try {
|
||||
// pw.writeObject(new JcaMiscPEMGenerator(cert));
|
||||
// }catch ( Exception e ) {
|
||||
// e.printStackTrace();
|
||||
// }finally {
|
||||
// if (null == pw) {
|
||||
// try {
|
||||
// pw.close();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return sw.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断正式是否是国密证书
|
||||
*
|
||||
* @param cert 证书 base64 字符
|
||||
* @return true 国密, false 非国密
|
||||
*/
|
||||
public static boolean isSM2Cert(String cert) {
|
||||
String pemCert;
|
||||
if(cert.contains("-----BEGIN CERTIFICATE-----")){
|
||||
pemCert =cert;
|
||||
}else {
|
||||
String cert_begin = "-----BEGIN CERTIFICATE-----\n";
|
||||
String end_cert = "\n-----END CERTIFICATE-----";
|
||||
pemCert = cert_begin + cert + end_cert;
|
||||
}
|
||||
X509Certificate certificate = null;
|
||||
try {
|
||||
certificate = convertToX509Cert(pemCert);
|
||||
} catch (Exception e) {
|
||||
throw new SydApiException( 0xC101, e );
|
||||
}
|
||||
String signAlg = certificate.getSigAlgName();
|
||||
return signAlg.toUpperCase().indexOf("SM2") >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断 p7 是否是国密证书签的
|
||||
*
|
||||
* @param pkcs7 pkcs7
|
||||
* @return true 国密, false 非国密
|
||||
*/
|
||||
public static boolean isSignedBySM2Cert(String pkcs7) throws IOException, CertificateException, NoSuchProviderException {
|
||||
RetWrap ret = ASN1Util.takeOutOriginDataFromPKCS7Sign(pkcs7);
|
||||
//return isSM2Cert((String) ret.get("cert"));
|
||||
String cert =(String) ret.get("cert");
|
||||
if(cert.contains("-----BEGIN CERTIFICATE-----")){
|
||||
return isSM2Cert(cert);
|
||||
}else{
|
||||
String cert_begin = "-----BEGIN CERTIFICATE-----\n";
|
||||
String end_cert = "\n-----END CERTIFICATE-----";
|
||||
String pemCert = cert_begin + cert + end_cert;
|
||||
return isSM2Cert(pemCert);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean certUsageCheck(String cert , CertUsage... us ) throws CertificateException, NoSuchProviderException {
|
||||
if ( null == us || us.length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
X509Certificate certificate = convertToX509Cert(cert);
|
||||
boolean[] usage = certificate.getKeyUsage();
|
||||
|
||||
if ( null == usage ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean checkRet = true;
|
||||
Set<Integer> uset = new HashSet<Integer>();
|
||||
for ( CertUsage u : us ) {
|
||||
uset.add( u.ordinal() );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < usage.length; i++ ) {
|
||||
if ( usage[ i ] ) {
|
||||
checkRet &= uset.contains( i );
|
||||
}
|
||||
}
|
||||
|
||||
return checkRet;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.sunyard.util;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Configure {
|
||||
public static String getKey(String key) throws IOException {
|
||||
Properties p = new Properties();
|
||||
InputStream in = new FileInputStream("./sunyard.properties");
|
||||
InputStreamReader sr = new InputStreamReader(in, "UTF-8");
|
||||
p.load(sr);
|
||||
String value = p.getProperty(key).trim();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.sunyard.util;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class DnUtil {
|
||||
|
||||
|
||||
public static LinkedHashMap<String, String> dnToMap(String dn) {
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
||||
String[] kvs = dn.split(",");
|
||||
for (String kv : kvs) {
|
||||
String[] ps = kv.split("=");
|
||||
map.put(ps[0].trim(), ps[1].trim());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static String verifyDn(String dn) {
|
||||
if ( "true".equals(System.getProperty("com.sunyard.dnsort", "true"))) {
|
||||
if (dn.startsWith("C=") || dn.startsWith("c=")) {
|
||||
return dn;
|
||||
}
|
||||
// 反转顺序
|
||||
String[] kvs = dn.split(",");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (String kv : kvs) {
|
||||
|
||||
if (sb.length() > 0) {
|
||||
sb.insert(0, ",");
|
||||
}
|
||||
sb.insert(0, kv);
|
||||
|
||||
// if ( sb.length() > 0 ) {
|
||||
// sb.append(",");
|
||||
// }
|
||||
// sb.append( key + "=" + map.get( key ) );
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
else return dn;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
package org.bouncycastle.cms;
|
||||
|
||||
import com.sunyard.SydApiException;
|
||||
import org.bouncycastle.asn1.*;
|
||||
import org.bouncycastle.asn1.cms.ContentInfo;
|
||||
import org.bouncycastle.asn1.cms.EncryptedContentInfo;
|
||||
import org.bouncycastle.asn1.cms.OriginatorInfo;
|
||||
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class SydCmsUtil {
|
||||
|
||||
public static Object readContentInfo(
|
||||
byte[] input) {
|
||||
ASN1InputStream is = new ASN1InputStream(input);
|
||||
Object v = null;
|
||||
try {
|
||||
v = is.readObject();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, Object> getEncryptedContentInfo(ASN1Encodable obj){
|
||||
Map<String, Object>map = new HashMap<String, Object>();
|
||||
ASN1Sequence seq = ASN1Sequence.getInstance(obj );
|
||||
if (seq.size() < 2)
|
||||
{
|
||||
throw new IllegalArgumentException("Truncated Sequence Found");
|
||||
}
|
||||
|
||||
ASN1ObjectIdentifier contentType = (ASN1ObjectIdentifier)seq.getObjectAt(0);
|
||||
map.put( "contentType", contentType );
|
||||
|
||||
AlgorithmIdentifier contentEncryptionAlgorithm = AlgorithmIdentifier.getInstance(
|
||||
seq.getObjectAt(1));
|
||||
|
||||
map.put( "contentEncryptionAlgorithm", contentEncryptionAlgorithm );
|
||||
|
||||
if (seq.size() > 2)
|
||||
{
|
||||
ASN1OctetString encryptedContent = ASN1OctetString.getInstance(
|
||||
(ASN1TaggedObject)seq.getObjectAt(2), false);
|
||||
map.put( "encryptedContent", encryptedContent );
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Map<String, Object> getOriginatorInfo(ASN1TaggedObject obj,
|
||||
boolean explicit){
|
||||
Map<String, Object>map = new HashMap<String, Object>();
|
||||
ASN1Sequence seq = ASN1Sequence.getInstance(obj, explicit);
|
||||
switch (seq.size())
|
||||
{
|
||||
case 0: // empty
|
||||
break;
|
||||
case 1:
|
||||
ASN1TaggedObject o = (ASN1TaggedObject)seq.getObjectAt(0);
|
||||
switch (o.getTagNo())
|
||||
{
|
||||
case 0 :
|
||||
ASN1Set certs = ASN1Set.getInstance(o, false);
|
||||
map.put("certs", certs);
|
||||
break;
|
||||
case 1 :
|
||||
ASN1Set crls = ASN1Set.getInstance(o, false);
|
||||
map.put("crls", crls);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Bad tag in OriginatorInfo: " + o.getTagNo());
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
ASN1Set certs = ASN1Set.getInstance((ASN1TaggedObject)seq.getObjectAt(0), false);
|
||||
map.put("certs", certs);
|
||||
ASN1Set crls = ASN1Set.getInstance((ASN1TaggedObject)seq.getObjectAt(1), false);
|
||||
map.put("crls", crls);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("OriginatorInfo too big");
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public static ContentInfo getContentInfo( byte[] input ) {
|
||||
Object content = readContentInfo( input );
|
||||
ASN1Sequence seq = ASN1Sequence.getInstance( content );
|
||||
return new ContentInfo(seq);
|
||||
}
|
||||
|
||||
public static Map<String, Object> readCmsInfo( byte[] input ) throws CMSException {
|
||||
Map<String, Object>map = new HashMap<String, Object>();
|
||||
|
||||
Object content = readContentInfo( input );
|
||||
ASN1Sequence seq = ASN1Sequence.getInstance( content );
|
||||
ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) seq.getObjectAt(0);
|
||||
map.put("oid", oid);
|
||||
|
||||
seq = ASN1Sequence.getInstance((ASN1TaggedObject) seq.getObjectAt(1), true);
|
||||
|
||||
int index = 0;
|
||||
|
||||
ASN1Integer version = (ASN1Integer)seq.getObjectAt(index++);
|
||||
map.put( "version", version );
|
||||
|
||||
Object tmp = seq.getObjectAt(index++);
|
||||
|
||||
if (tmp instanceof ASN1TaggedObject)
|
||||
{
|
||||
OriginatorInfo originatorInfo = OriginatorInfo.getInstance((ASN1TaggedObject)tmp, false);
|
||||
// Map<String, Object>originatorInfo = getOriginatorInfo((ASN1TaggedObject)tmp, false);
|
||||
map.put( "originatorInfo", originatorInfo );
|
||||
tmp = seq.getObjectAt(index++);
|
||||
}
|
||||
|
||||
ASN1Set recipientInfos = ASN1Set.getInstance(tmp);
|
||||
map.put( "recipientInfos", recipientInfos );
|
||||
|
||||
EncryptedContentInfo encryptedContentInfo = EncryptedContentInfo.getInstance( seq.getObjectAt(index++) );
|
||||
// Map<String, Object> encryptedContentInfo = getEncryptedContentInfo(seq.getObjectAt(index++));
|
||||
map.put( "encryptedContentInfo", encryptedContentInfo );
|
||||
|
||||
if(seq.size() > index)
|
||||
{
|
||||
ASN1Set unprotectedAttrs = ASN1Set.getInstance((ASN1TaggedObject)seq.getObjectAt(index), false);
|
||||
map.put( "unprotectedAttrs", unprotectedAttrs );
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package racal.sunyard.main;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BytesList {
|
||||
private List<byte[]> bytes = new ArrayList<byte[]>();
|
||||
|
||||
public BytesList(){
|
||||
|
||||
}
|
||||
|
||||
public BytesList(byte[] b){
|
||||
this.append( b );
|
||||
}
|
||||
|
||||
public void append( byte[] b ) {
|
||||
bytes.add( b );
|
||||
}
|
||||
|
||||
public byte[] toBytes(){
|
||||
int len = 0;
|
||||
|
||||
if(1== bytes.size()){
|
||||
return bytes.get(0);
|
||||
}
|
||||
|
||||
for ( byte[] b : bytes ) {
|
||||
len += b.length;
|
||||
}
|
||||
|
||||
if ( 0 == len ) {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
byte[] buff = new byte[ len ];
|
||||
int idx = 0;
|
||||
for ( byte[] b : bytes ) {
|
||||
System.arraycopy( b, 0, buff, idx, b.length );
|
||||
idx += b.length;
|
||||
}
|
||||
return buff;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,42 +0,0 @@
|
||||
package racal.sunyard.main;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.proxy.ProxyInvocationHandler;
|
||||
|
||||
public class SydApiClusterBuilder {
|
||||
|
||||
public static SydApi SYD_Short_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int allDealTimeOut) {
|
||||
if (pcIpList.length != iPortList.length) {
|
||||
throw new IllegalArgumentException("ip与端口数量不一致");
|
||||
}
|
||||
SydApi4j[] apis = new SydApi4j[pcIpList.length];
|
||||
int iDealTimeOut = allDealTimeOut / pcIpList.length;
|
||||
boolean connected = false;
|
||||
SydApi4j sydApi4j = new SydApi4j();
|
||||
for (int i = 0; i < pcIpList.length; i++) {
|
||||
try {
|
||||
apis[i] = (SydApi4j) sydApi4j.connect(pcIpList[i], iPortList[i], null, iConnectTimeOut, iDealTimeOut);
|
||||
connected = true;
|
||||
} catch (Exception e) {
|
||||
// 忽略错误
|
||||
// log.error("网络连接错误 {} {} - 忽略", pcIpList[i], iPortList[i]);
|
||||
}
|
||||
|
||||
}
|
||||
if (!connected) {
|
||||
// TODO
|
||||
throw new SydApiException("连接错误", -1);
|
||||
}
|
||||
|
||||
|
||||
// hsms = apis;
|
||||
// isShortLinkMode = true;
|
||||
|
||||
|
||||
|
||||
ProxyInvocationHandler proxyInvocationHandler = new ProxyInvocationHandler(apis);
|
||||
return proxyInvocationHandler.getProxy();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package racal.sunyard.main;
|
||||
|
||||
public class SydApiMuti extends SydApi4j {
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package racal.sunyard.main;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.pool.HsmLinkInfo;
|
||||
import com.sunyard.pool.SydApiPool;
|
||||
|
||||
public class SydApiPoolBuilder {
|
||||
private SydApiPool pool;
|
||||
public SydApiPoolBuilder(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iDealTimeOut){
|
||||
this(pcIpList, iPortList, iConnectTimeOut, iDealTimeOut, true);
|
||||
}
|
||||
public SydApiPoolBuilder(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iDealTimeOut, boolean warmup) {
|
||||
HsmLinkInfo[] linkInfo = HsmLinkInfo.mutiHsmLinkInfo(pcIpList, iPortList, iConnectTimeOut, iDealTimeOut);
|
||||
this.pool = new SydApiPool(linkInfo);
|
||||
if ( warmup ) {
|
||||
this.warmUp(pcIpList, iPortList, iConnectTimeOut, iDealTimeOut);
|
||||
}
|
||||
}
|
||||
|
||||
public SydApi build() {
|
||||
return (SydApi)this.pool.get();
|
||||
}
|
||||
|
||||
public SydApiPool getPool() {
|
||||
return pool;
|
||||
}
|
||||
|
||||
private void warmUp(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iDealTimeOut) {
|
||||
// SydApi4j api = null;
|
||||
SydApi api = null;
|
||||
try {
|
||||
// api = new SydApi4j();
|
||||
api = SydApiClusterBuilder.SYD_Short_Connect_Ex(pcIpList, iPortList, iConnectTimeOut, iDealTimeOut);
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
if (null != api) {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package racal.sunyard.main;
|
||||
|
||||
public interface SydHashApiTest {
|
||||
|
||||
/**
|
||||
* 计算SM3散列值
|
||||
* @param sn 证书序号
|
||||
* @param userId 用户ID
|
||||
* @param msg 原始数据,二进制的消息块
|
||||
* @return
|
||||
*/
|
||||
byte[] SM3HashSNaId(String sn, String userId, byte[] msg);
|
||||
|
||||
/**
|
||||
* 输入对指定的原始数据和公钥,通过 SM3 算法计算数据的散列值。
|
||||
* @param publicKey 公钥的 DER 编码(可以为空)
|
||||
* @param msg 原始数据,二进制的消息块
|
||||
* @param block 消息块标志
|
||||
* @param mac 上一轮 mac 值,当 mac 不是 null,长度不为 0,则直接从第二包开始。
|
||||
* @return HASH 值,32 个 Bytes.
|
||||
*/
|
||||
byte[] SM3Hash(String publicKey, byte[] msg, int block, byte[] mac);
|
||||
|
||||
/**
|
||||
* 计算SM3散列值
|
||||
* @param publicKey 公钥的 DER 编码 (03420004 开头)
|
||||
* @param userId 用户ID
|
||||
* @param msg 原始数据,二进制的消息块
|
||||
* @return
|
||||
*/
|
||||
byte[] SM3Hash(String publicKey, String userId, byte[] msg);
|
||||
|
||||
/**
|
||||
* 输入对指定的原始数据和公钥,通过 SM3 算法计算数据的散列值。
|
||||
*
|
||||
* @param publicKey 公钥(可以为空)
|
||||
* @param msg 原始数据
|
||||
* @return HASH 值,32 个 Bytes.
|
||||
*/
|
||||
byte[] SM3Hash(String publicKey, byte[] msg);
|
||||
|
||||
|
||||
/**
|
||||
* 输入对指定的原始数据 (无公钥),通过 SM3 算法计算数据的散列值。
|
||||
*
|
||||
* @param msg 原始数据
|
||||
* @return HASH 值,32 个 Bytes.
|
||||
*/
|
||||
byte[] SM3Hash(byte[] msg);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.sunyard.sydapi;
|
||||
|
||||
import org.junit.Test;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
/**
|
||||
* 传化签名验签demo
|
||||
* */
|
||||
public class ChuanhuaDemo1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 调试模式
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
// 建立链接(单台)
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.0.100", 8889, null, 1000);
|
||||
|
||||
try {
|
||||
|
||||
final String testSN1 = "1004282451";
|
||||
final String testSN2 = "1004282452";
|
||||
|
||||
byte[] testData = "1234567812345678信达雅SUNYARDsunyard".getBytes("UTF-8");
|
||||
|
||||
System.out.println("\n\n----- 用指定的证书私钥对指定的数据进行数字签名。 -----");
|
||||
String signPri = api.netSign(testSN1, testData);
|
||||
System.out.print("sign : ");
|
||||
System.out.println(signPri);
|
||||
// 验签传原始数据
|
||||
System.out.println("\n\n----- 用指定的证书私钥对指定的数据进行数字验证。 -----");
|
||||
if (api.netVerify(testSN1, testData, signPri)) {
|
||||
System.out.println("验证通过");
|
||||
} else {
|
||||
System.out.println("验证失败");
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
api.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package com.sunyard.sydapi;
|
||||
|
||||
import com.sunyard.proto.Util;
|
||||
import org.junit.Assert;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
|
||||
/**
|
||||
* 传化国密加解密demo
|
||||
* */
|
||||
public class ChuanhuaDemo2 {
|
||||
|
||||
/*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 void main(String[] args){
|
||||
|
||||
// 调试模式
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
// 建立链接(单台)
|
||||
// SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.0.100", 8889, null, 1000);
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.18.59", 8889, null, 1000);
|
||||
|
||||
|
||||
try{
|
||||
|
||||
// final String testSN1 = "1004282451";//签名
|
||||
// final String testSN2 = "1004282452";//加密
|
||||
final String userId = "1747";
|
||||
|
||||
byte[] testData = "1234567812345678信达雅SUNYARDsunyard@!#$%^加密s".getBytes("GBK");
|
||||
|
||||
String pk = api.SM2GetPublicKeyC(userId, 1);
|
||||
System.out.println("pk= " + pk);
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 SM2 -----");
|
||||
String sdata = api.SM2Encrypt(Util.hexString2Bytes(pk), testData);
|
||||
System.out.println("加密后的数据: " + sdata);
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 SM2 -----");
|
||||
byte[] data = api.SM2DecryptC(userId, sdata);
|
||||
Assert.assertArrayEquals(testData, data);
|
||||
System.out.println("解密后的数据: " + new String(data));
|
||||
// write("./data.txt",data);
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,11 @@ public class ShangTest {
|
||||
|
||||
assert ret;
|
||||
|
||||
sign = api.SYD_DetachedSign(testData, dn);
|
||||
ret = api.SYD_DetachedVerify( testData, sign );
|
||||
|
||||
assert ret;
|
||||
|
||||
}
|
||||
|
||||
public void end(){
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
package com.sunyard.sydapi.loadrunner.raw;
|
||||
|
||||
/*
|
||||
* LoadRunner Java script. (Build: _build_number_)
|
||||
*
|
||||
* Script Description:
|
||||
*
|
||||
*/
|
||||
|
||||
import lrapi.lr;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
import com.sunyard.proto.Util;
|
||||
import com.sunyard.SydApi;
|
||||
|
||||
public class Actions
|
||||
{
|
||||
|
||||
private static final String inHexData = "67c6697351ff4aec29cdbaabf2fbe346";
|
||||
|
||||
private static String pk ;
|
||||
private static String sk ;
|
||||
private SydApi api;
|
||||
|
||||
|
||||
|
||||
public int init() throws Throwable {
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp("192.168.1.123");
|
||||
api = builder.build();
|
||||
|
||||
this.pk = api.SM2GetPublicKeyC("123", 0 );
|
||||
this.sk = api.SM2GetPrivateKeyC("123");
|
||||
|
||||
return 0;
|
||||
}//end of init
|
||||
|
||||
|
||||
public int action() throws Throwable {
|
||||
lr.start_transaction("auto");//设置事务开始点
|
||||
|
||||
try {
|
||||
|
||||
System.out.println("begin SYD_Sign_P1");
|
||||
byte[] sign = this.api.SM2SignC( 0 , sk, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData) );
|
||||
System.out.println("sign=" + Util.bytes2HexString( sign ));
|
||||
|
||||
System.out.println("begin SYD_Verify_P1");
|
||||
boolean pass = api.SM2Verify(1, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData), sign );
|
||||
System.out.println("验签结果 " + pass);
|
||||
System.out.println("end SYD_Verify_P1");
|
||||
|
||||
} finally {
|
||||
lr.end_transaction("auto", lr.AUTO);//设置事务结束点
|
||||
}
|
||||
|
||||
return 0;
|
||||
}//end of action
|
||||
|
||||
|
||||
public int end() throws Throwable {
|
||||
return 0;
|
||||
}//end of end
|
||||
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
|
||||
Actions actions = new Actions();
|
||||
actions.init();
|
||||
actions.action();
|
||||
actions.end();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
package com.sunyard.sydapi.loadrunner.raw_uid;
|
||||
|
||||
/*
|
||||
* LoadRunner Java script. (Build: _build_number_)
|
||||
*
|
||||
* Script Description:
|
||||
*
|
||||
*/
|
||||
|
||||
import lrapi.lr;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
import com.sunyard.proto.Util;
|
||||
import com.sunyard.SydApi;
|
||||
|
||||
public class Actions
|
||||
{
|
||||
|
||||
private static final String inHexData = "67c6697351ff4aec29cdbaabf2fbe346";
|
||||
private static final String uid = "8765432187654321";
|
||||
|
||||
private static String pk ;
|
||||
private static String sk ;
|
||||
private SydApi api;
|
||||
|
||||
|
||||
|
||||
public int init() throws Throwable {
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp("192.168.1.123");
|
||||
api = builder.build();
|
||||
|
||||
this.pk = api.SM2GetPublicKeyC("123", 0 );
|
||||
this.sk = api.SM2GetPrivateKeyC("123");
|
||||
|
||||
return 0;
|
||||
}//end of init
|
||||
|
||||
|
||||
public int action() throws Throwable {
|
||||
lr.start_transaction("auto");//设置事务开始点
|
||||
|
||||
try {
|
||||
|
||||
System.out.println("begin SYD_Sign_P1");
|
||||
byte[] sign = this.api.SM2SignC( 0, uid , sk, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData) );
|
||||
System.out.println("sign=" + Util.bytes2HexString( sign ));
|
||||
|
||||
System.out.println("begin SYD_Verify_P1");
|
||||
boolean pass = api.SM2Verify( uid, 1, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData), sign );
|
||||
System.out.println("验签结果 " + pass);
|
||||
System.out.println("end SYD_Verify_P1");
|
||||
|
||||
} finally {
|
||||
lr.end_transaction("auto", lr.AUTO);//设置事务结束点
|
||||
}
|
||||
|
||||
return 0;
|
||||
}//end of action
|
||||
|
||||
|
||||
public int end() throws Throwable {
|
||||
return 0;
|
||||
}//end of end
|
||||
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
|
||||
Actions actions = new Actions();
|
||||
actions.init();
|
||||
actions.action();
|
||||
actions.end();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
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;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import static com.sunyard.sydapi.util.PrintUtil.printByteArray;
|
||||
import static com.sunyard.sydapi.util.PrintUtil.printRetWrap;
|
||||
|
||||
/**
|
||||
* 农行北分海淀支行-军队资金集中收付系统
|
||||
*/
|
||||
public class ABCNorthBranch {
|
||||
|
||||
SydApi4j api;
|
||||
|
||||
// SM2密钥索引
|
||||
String SM2PrivateKeyTag = "111111111111115100000000001";
|
||||
// SM2公钥
|
||||
String SM2PublicKey = null;
|
||||
// SM2私钥
|
||||
String SM2PrivateKey = null;
|
||||
|
||||
// SM4密钥索引
|
||||
String SM4PrivateKeyTag = "000000000000000100011111111";
|
||||
// SM4密钥
|
||||
String SM4Key = null;
|
||||
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
api = (SydApi4j) new SydApi4j().connect("61.164.40.82", 8889, null, 5000);
|
||||
|
||||
SM2PublicKey = api.SM2GetPublicKeyC(SM2PrivateKeyTag);
|
||||
SM2PrivateKey = api.SM2GetPrivateKeyC(SM2PrivateKeyTag);
|
||||
|
||||
|
||||
SM4Key = new String((byte[]) api.readKey(SM4PrivateKeyTag).get("key"));
|
||||
|
||||
System.out.println("=========================================密钥获取完成=========================================");
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
try {
|
||||
this.api.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// A4
|
||||
@Test
|
||||
public void testComposeKey() {
|
||||
String[] strs = {"583034303438393445374238444531323942344646344546393838394535364132", "583934443335443836454631463332313344353543343738323246383744333835"};
|
||||
RetWrap rw = api.composeKey("000", strs);
|
||||
|
||||
printRetWrap(rw);
|
||||
}
|
||||
|
||||
|
||||
// 测试通过
|
||||
// 74
|
||||
@Test
|
||||
public void testSM2SignC2() {
|
||||
String thisOrgData = "FFFFFFFFFFFFFFFF";
|
||||
|
||||
String s = api.SM2SignC(1, SM2PrivateKeyTag, Util.hexString2Bytes(SM2PublicKey), thisOrgData.getBytes());
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 74
|
||||
@Test
|
||||
public void testSM2SignC3() {
|
||||
String thisOrgData = "FFFFFFFFFFFFFFFF";
|
||||
|
||||
String s = api.SM2SignC(0, SM2PrivateKey, Util.hexString2Bytes(SM2PublicKey), thisOrgData.getBytes());
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
// 75
|
||||
@Test
|
||||
public void testSM2SignAndVerify() {
|
||||
String orgData = "11111111111111";
|
||||
|
||||
// 这里,不管是签名还是验签,都需要在外部做一次hash。
|
||||
byte[] hash = api.SM3Hash(SM2PublicKey, orgData.getBytes());
|
||||
|
||||
/**
|
||||
* 用私钥签名(外部私钥)
|
||||
* @param nOrgDataType 签名数据类型,0 : hash 1 : 原数据
|
||||
* @param privateKey LMK34-35 下加密的私钥
|
||||
* @param orgData “签名数据类型”为 0 时:HASH 值。“签名数据类型”为 1 时:要签名的信息
|
||||
* @return 签名的 base64 编码
|
||||
*/
|
||||
String s = api.SM2Sign(SydApi.DATA_HASH, Util.hexString2Bytes(SM2PrivateKey), hash);
|
||||
|
||||
// 这里的签名结果已经符合条件了,不需要做转换
|
||||
System.out.println("签名结果: " + s);
|
||||
System.out.println("decBase64:" + Util.bytes2HexString(Util.decodeBase64(s)));
|
||||
/**
|
||||
* 用指定的公钥对指定的原始数据进行数字签名验证(PKCS#1)
|
||||
* @param nOrgDataType 签名数据类型,SydApi.DATA_ORIGIN(1) 原始数据 SydApi.DATA_HASH(0) : hash 后的类型
|
||||
* @param publicKey 公钥串,DER编码,HEX格式
|
||||
* @param orgData 待签名的原始数据,“签名数据类型”为 0 时:HASH 值。“签名数据类型”为 1 时:要签名的信息
|
||||
* @param base64Sign 签名数据 (DER 编码 + Base64 编码)
|
||||
* @return 验签是否通过
|
||||
*/
|
||||
boolean b = api.SM2Verify(SydApi.DATA_HASH, Util.hexString2Bytes(SM2PublicKey), hash, s);
|
||||
System.out.println("验签结果: " + b);
|
||||
}
|
||||
|
||||
|
||||
// 测试通过
|
||||
// 75
|
||||
@Test
|
||||
public void testSM2Verify3() {
|
||||
|
||||
String thisOrgData = "FFFFFFFFFFFFFFFF";
|
||||
|
||||
String s = api.SM2SignC(1, SM2PrivateKeyTag, Util.hexString2Bytes(SM2PublicKey), thisOrgData.getBytes());
|
||||
|
||||
System.out.println(s);
|
||||
boolean b = api.SM2Verify(Util.hexString2Bytes(SM2PublicKey), thisOrgData.getBytes(), s);
|
||||
System.out.println(b);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// E0
|
||||
@Test
|
||||
public void testSM4EncryptDataCBC() {
|
||||
String msg = "1111111111111111111111";
|
||||
byte[] bytes = api.SM4EncryptDataCBC(0, SM4Key, 0, 0, msg.getBytes());
|
||||
printByteArray(bytes);
|
||||
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// E0
|
||||
@Test
|
||||
public void testSM4DecryptDataCBC() {
|
||||
String msg = "11111111111";
|
||||
byte[] bytes = api.SM4EncryptDataCBC(0, SM4Key, 0, 0, msg.getBytes());
|
||||
|
||||
byte[] bytes1 = api.SM4DecryptDataCBC(0, SM4Key, 0, 0, bytes);
|
||||
|
||||
printByteArray(bytes1, false);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// E0
|
||||
@Test
|
||||
public void testSM4EncryptFileDataCBC() {
|
||||
|
||||
String inFilePath = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\in1.txt";
|
||||
String outFilePath = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\in2.txt";
|
||||
boolean b = api.SM4EncryptFileDataCBC(0, SM4Key, 0, 0, inFilePath, outFilePath);
|
||||
System.out.println(b);
|
||||
}
|
||||
|
||||
|
||||
// 测试通过
|
||||
// E0
|
||||
@Test
|
||||
public void testSM4DecryptFileDataCBC() throws UnsupportedEncodingException {
|
||||
|
||||
String outFilePath = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\in2.txt";
|
||||
String outFilePath2 = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\out1.txt";
|
||||
boolean b = api.SM4DecryptFileDataCBC(0, SM4Key, 0, 0, outFilePath, outFilePath2);
|
||||
System.out.println(b);
|
||||
}
|
||||
|
||||
// LF
|
||||
@Test
|
||||
public void testReadKey() {
|
||||
RetWrap retWrap = api.readKey(SM4PrivateKeyTag);
|
||||
printRetWrap(retWrap);
|
||||
}
|
||||
|
||||
// QQ
|
||||
@Test
|
||||
public void testSM2GetPublicKeyC3() {
|
||||
|
||||
String s = api.SM2GetPublicKeyC(SM2PrivateKeyTag);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
// QP
|
||||
@Test
|
||||
public void testSM2GetPrivateKeyC() {
|
||||
String s = api.SM2GetPrivateKeyC(SM2PrivateKeyTag);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.github.houbb.junitperf.core.annotation.JunitPerfConfig;
|
||||
import com.github.houbb.junitperf.core.rule.JunitPerfRule;
|
||||
import com.sunyard.RetWrap;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.sunyard.sydapi.util.PrintUtil.printRetWrap;
|
||||
|
||||
public class CertTest {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
//System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.1.129", 8889, null, 1000);
|
||||
try{
|
||||
List<String>dns = api.getAllCert();
|
||||
System.out.println(Arrays.toString( dns.toArray() ) );
|
||||
// String sql=" certtype in (0,2) "; //签名解密
|
||||
// String sql2=" certtype in (1,3) "; //验签加密
|
||||
//
|
||||
// ArrayList<String> m_certs =new ArrayList<String>();
|
||||
// //查出证书总数,一次次的拿出来
|
||||
// RetWrap allCert = api.getAllCert(0);
|
||||
// printRetWrap(allCert);
|
||||
// Integer allnum = (Integer) allCert.get("certAllNum");//总数
|
||||
// List<String> certs = (List<String>)allCert.get("certDNs");//部分证书列表
|
||||
// System.out.println(certs.toString());
|
||||
// m_certs.addAll(certs);
|
||||
// int loop = allnum%16;//循环次数
|
||||
// for (int i = 1; i < loop; i++) {
|
||||
// RetWrap partCert= api.getAllCert(16*i);
|
||||
// List<String> partcerts = (List<String>)partCert.get("certDNs");
|
||||
// m_certs.addAll(partcerts);
|
||||
// }
|
||||
// System.out.println("证书:"+m_certs);
|
||||
// System.out.println("aa"+m_certs.get(20));
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
api.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
// 测试参数
|
||||
// private static final int threads = 1;
|
||||
// private static final long duration = 120000;
|
||||
// private static final long warmUp = 30000;
|
||||
//
|
||||
//
|
||||
// @Rule
|
||||
// public JunitPerfRule junitPerfRule = new JunitPerfRule();
|
||||
// SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.1.129",8889,null,3000);
|
||||
//
|
||||
//
|
||||
// @BeforeClass
|
||||
// public static void init() throws UnsupportedEncodingException {
|
||||
// System.out.println("begin");
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @AfterClass
|
||||
// public static void after() {
|
||||
// System.out.println("all over");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration)
|
||||
// public void getAllCert(){
|
||||
// try {
|
||||
// api.getAllCert(0);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.proto.Util;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import com.github.houbb.junitperf.core.annotation.JunitPerfConfig;
|
||||
import com.github.houbb.junitperf.core.rule.JunitPerfRule;
|
||||
import org.junit.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class P1P7Test {
|
||||
// 全局配置
|
||||
private static final String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
|
||||
// 测试参数
|
||||
private static final int threads = 1;
|
||||
private static final long duration = 120000;
|
||||
private static final long warmUp = 30000;
|
||||
|
||||
// 原始数据
|
||||
private static final byte[] data1k = new byte[ 1024 * 4];
|
||||
|
||||
private static final byte[] data1m = new byte[ 1024 * 1024 ];
|
||||
|
||||
|
||||
// 临时数据
|
||||
private static String pk = null;
|
||||
private static String dm_1k;
|
||||
private static String dm_1m = null;
|
||||
private static byte[] p1sign_1k;
|
||||
private static byte[] p1sign_1m = null;
|
||||
private static String p7dsign_1k;
|
||||
private static String p7dsign_1m = null;
|
||||
private static String p7asign_1k;
|
||||
private static String p7asign_1m = null;
|
||||
|
||||
@Rule
|
||||
public JunitPerfRule junitPerfRule = new JunitPerfRule();
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.0.200",8889,null,3000);
|
||||
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws UnsupportedEncodingException {
|
||||
System.out.println("begin");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void after() {
|
||||
System.out.println("all over");
|
||||
}
|
||||
|
||||
@Test
|
||||
@JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration)
|
||||
public void p1_sign_1k(){
|
||||
p1sign_1k= api.SYD_NakedSign(data1k, dn);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration)
|
||||
public void p1_verify_1k(){
|
||||
api.SYD_NakedVerify( data1k, p1sign_1k, dn );
|
||||
}
|
||||
|
||||
@Test
|
||||
@JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration)
|
||||
public void p7a_sign_1k() throws UnsupportedEncodingException {
|
||||
p7asign_1k = api.attachedSign(data1k, dn);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration)
|
||||
public void p7a_verify_1k(){
|
||||
api.attachedVerifyAndGetAll( p7asign_1k );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration)
|
||||
public void p7d_sign_1k(){
|
||||
p7dsign_1k = api.sm3AndDetachedSign(data1k, pk, dn);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration)
|
||||
public void p7d_verify_1k(){
|
||||
api.sm3AndDetachedVerify(data1k, pk, p7dsign_1k );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration)
|
||||
public void dm_aen_1k() {
|
||||
dm_1k = String.valueOf(api.generateDEByDn(dn, data1k));
|
||||
}
|
||||
|
||||
@Test
|
||||
@JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration)
|
||||
public void dm_de_1k() {
|
||||
api.decryptDEByDN(dn, Util.hexString2Bytes(dm_1k));
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.proto.Util;
|
||||
import com.sunyard.util.ASN1Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class RSASignVertify {
|
||||
private static final String RSADN = "C=cn,O=CFCA TEST CA,OU=CIPSTEST,OU=Units,CN=041@3CIPSCNSHCLR@CN000000129@00000018";
|
||||
private static final byte[] orgData={1,2,3,4,5,6};
|
||||
private static final String SM2DN = "C=CN,O=123,OU=23,OU=23,CN=32";
|
||||
|
||||
// public p1
|
||||
// p7attach
|
||||
// p7detach
|
||||
public static void main(String[] args) throws IOException {
|
||||
//System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
//long startTime = System.currentTimeMillis(); //设置系统时间
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp("172.16.18.59");
|
||||
SydApi4j api = (SydApi4j) builder.build();
|
||||
|
||||
|
||||
//
|
||||
// byte[] nakedSign = api.SYD_NakedSign(1,orgData,RSADN);
|
||||
// System.out.println("nakedSign"+nakedSign);
|
||||
// byte[] sm2Sign = api.SYD_NakedSign(orgData,SM2DN);
|
||||
// System.out.println("sm2Sign:"+sm2Sign);
|
||||
//
|
||||
// boolean nakedVerify = api.SYD_NakedVerify(1, orgData, nakedSign, RSADN);
|
||||
// System.out.println(nakedVerify);
|
||||
// boolean nakedVerify2 = api.SYD_NakedVerify( orgData, sm2Sign, SM2DN);
|
||||
// System.out.println(nakedVerify2);
|
||||
|
||||
// String attachedSign = api.attachedSign(orgData, SM2DN);
|
||||
// //System.out.println(attachedSign);
|
||||
// boolean attachedVerify = api.attachedVerify(attachedSign);
|
||||
// System.out.println(attachedVerify);
|
||||
//
|
||||
// String attachedSign2 = api.attachedSign(1,orgData, RSADN);
|
||||
// String attachedSign3 = api.attachedSign(2,orgData, RSADN);
|
||||
// String attachedSign4 = api.attachedSign(3,orgData, RSADN);
|
||||
// System.out.println("签名1:"+attachedSign2);
|
||||
// System.out.println("签名2:"+attachedSign3);
|
||||
// System.out.println("签名3:"+attachedSign4);
|
||||
// boolean attachedVerify2 = api.attachedVerify(attachedSign2);
|
||||
// RetWrap retWrap = ASN1Util.takeOutOriginDataFromPKCS7Sign(attachedSign2);
|
||||
// System.out.println(attachedVerify2);
|
||||
// byte[] orgData = (byte[]) retWrap.get("orgData");
|
||||
// String cert = (String) retWrap.get("cert");
|
||||
// System.out.println(Util.bytes2HexString(orgData));
|
||||
// System.out.println(Util.bytes2HexString(Util.decodeBase64(cert)));
|
||||
// System.out.println("证书:"+Util.bytes2HexString(Util.encodeBase64(RSADN.getBytes("GBK")).getBytes("GBK")));
|
||||
|
||||
String detachedSign = api.detachedSign(1, orgData, SM2DN);
|
||||
System.out.println(detachedSign);
|
||||
String detachedSign2 = api.detachedSign(1,0, orgData, RSADN);
|
||||
System.out.println(detachedSign2);
|
||||
boolean detachedVerify = api.detachedVerify(1, orgData, detachedSign);
|
||||
boolean detachedVerify2 = api.detachedVerify(1,0, orgData, detachedSign2);
|
||||
System.out.println(detachedVerify);
|
||||
System.out.println(detachedVerify2);
|
||||
|
||||
// String RSAsign = api.attachedSign(1, orgData.getBytes("GBK"), RSADN);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,415 +0,0 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.cert.X509;
|
||||
import com.sunyard.proto.Util;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
|
||||
/**
|
||||
* 上清例子
|
||||
*/
|
||||
public class Shanqing {
|
||||
|
||||
SydApi4j api;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
// 通过设置debug的属性开启debug,如果不设置则默认不打开
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
api = (SydApi4j) new SydApi4j().connect("192.168.0.200", 8889, null, 1000);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
try {
|
||||
this.api.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程演示
|
||||
*/
|
||||
@Test
|
||||
public void testProcess() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = new byte[2 * 1024 * 1024];
|
||||
|
||||
// 签名
|
||||
String sign = api.attachedSign(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
// 生成数字信封
|
||||
RetWrap retWrap = api.generateDEByDn(dn, sign.getBytes());
|
||||
byte[] cipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
System.out.println("数字信封: " + new String(cipherKey));
|
||||
|
||||
// 解密数字信封
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, cipherKey);
|
||||
byte[] oData = (byte[]) retWrap1.get("oData");
|
||||
System.out.println("原数据: " + retWrap1.get("oData"));
|
||||
|
||||
// 验签
|
||||
RetWrap verify = api.attachedVerifyAndGetAll(oData);
|
||||
if (verify != null) {
|
||||
System.out.println("x509公钥: " + Util.bytes2HexString(((X509) verify.get("x509")).getPubKey()));
|
||||
System.out.println("签名原数据: " + Util.bytes2HexString((byte[]) (verify.get("oData"))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// 测试通过
|
||||
// 73
|
||||
@Test
|
||||
public void testSM2ConfirmSessionKeyC() {
|
||||
|
||||
String userId = "8012";
|
||||
byte[] data = "12343242".getBytes();
|
||||
|
||||
// 通过用户id获取公钥
|
||||
String pk = api.SM2GetPublicKeyC(userId, SydApi.FOR_ENCRYPT);
|
||||
|
||||
// 生成数字信封
|
||||
RetWrap retWrap = api.SM2GenSessionKey(pk);
|
||||
printRetWrap(retWrap);
|
||||
String cipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
String sessionKey = (String) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
String kcv = (String) retWrap.get(SydApi.RET_KCV);
|
||||
|
||||
// 使用生成的对称密钥加密数据
|
||||
byte[] dataEnc = api.SYMEncryptData(SydApi.NALG_SM4, sessionKey, data);
|
||||
|
||||
// 解密数字信封
|
||||
RetWrap retWrap1 = api.SM2ConfirmSessionKeyC(userId, cipherKey);
|
||||
printRetWrap(retWrap1);
|
||||
sessionKey = (String) retWrap1.get(SydApi.RET_SESSION_KEY);
|
||||
kcv = (String) retWrap1.get(SydApi.RET_KCV);
|
||||
|
||||
// 使用解密出来的对称密钥解密数据
|
||||
byte[] bytes1 = api.SYMDecryptData(SydApi.NALG_SM4, sessionKey, dataEnc);
|
||||
System.out.println("解密后的数据:" + new String(bytes1));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDetachedSignAndVerify1() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String orgData = "111111213323143243243";
|
||||
|
||||
|
||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
System.out.println("签名结果 hex : " + Util.bytes2HexString(Util.decodeBase64(sign)));
|
||||
|
||||
boolean verify = api.attachedVerify(sign);
|
||||
System.out.println("验签结果: " + verify);
|
||||
Assert.assertTrue(verify);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDetachedSignAndVerify2() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String orgData = "111111213323143243243";
|
||||
|
||||
|
||||
String sign = api.attachedSignSoft(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
System.out.println("签名结果 hex: " + Util.bytes2HexString(Util.decodeBase64(sign)));
|
||||
|
||||
boolean verify = api.attachedVerify(sign);
|
||||
System.out.println("验签结果: " + verify);
|
||||
Assert.assertTrue(verify);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDetachedSignAndVerify3() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = new byte[3 * 1024];
|
||||
|
||||
String sign = api.attachedSign(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
System.out.println("签名结果 hex: " + Util.bytes2HexString(Util.decodeBase64(sign)));
|
||||
|
||||
boolean verify = api.attachedVerify(sign);
|
||||
System.out.println("验签结果: " + verify);
|
||||
Assert.assertTrue(verify);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetachedSignAndVerify8() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = new byte[8 * 1024];
|
||||
|
||||
String sign = api.attachedSign(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
System.out.println("签名结果 hex: " + Util.bytes2HexString(Util.decodeBase64(sign)));
|
||||
|
||||
boolean verify = api.attachedVerify(sign);
|
||||
System.out.println("验签结果: " + verify);
|
||||
Assert.assertTrue(verify);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 8018
|
||||
@Test
|
||||
public void testAttachedSignAndVerify() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String orgData = "111111213323143243243";
|
||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
System.out.println("签名结果 hex : " + Util.bytes2HexString(Util.decodeBase64(sign)));
|
||||
|
||||
boolean verify = api.attachedVerify(sign);
|
||||
System.out.println("验签结果: " + verify);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyGetX509() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = "111111213323143243243".getBytes();
|
||||
String sign = api.attachedSign(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
|
||||
X509 verify = api.attachedVerifyAndGetX509(sign);
|
||||
System.out.println("验签结果: " + Util.bytes2HexString(verify.getPubKey()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyRD() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String orgData = "111111213323143243243";
|
||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
byte[] verify = api.attachedVerifyRD(sign);
|
||||
System.out.println("验签结果: " + Util.bytes2HexString(verify));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyGetAll() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = "111111213323143243243".getBytes();
|
||||
String sign = api.attachedSign(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
RetWrap verify = api.attachedVerifyAndGetAll(sign);
|
||||
if (verify != null) {
|
||||
System.out.println("x509公钥: " + Util.bytes2HexString(((X509) verify.get("x509")).getPubKey()));
|
||||
System.out.println("签名原数据: " + verify.get("oData"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyGetAll8k() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = new byte[ 8 * 1024 ];
|
||||
String sign = api.attachedSign(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
RetWrap verify = api.attachedVerifyAndGetAll(sign);
|
||||
if (verify != null) {
|
||||
System.out.println("x509公钥: " + Util.bytes2HexString(((X509) verify.get("x509")).getPubKey()));
|
||||
System.out.println("签名原数据: " + verify.get("oData"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyGetX509C() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = "111111213323143243243".getBytes();
|
||||
byte[] sign = api.attachedSignC(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
X509 verify = api.attachedVerifyAndGetX509(sign);
|
||||
System.out.println("验签结果: " + Util.bytes2HexString(verify.getPubKey()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyRDC() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String orgData = "111111213323143243243";
|
||||
byte[] sign = api.attachedSignC(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
byte[] verify = api.attachedVerifyRD(sign);
|
||||
System.out.println("验签结果: " + Util.bytes2HexString(verify));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyGetAllC() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = "111111213323143243243".getBytes();
|
||||
byte[] sign = api.attachedSignC(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
|
||||
RetWrap verify = api.attachedVerifyAndGetAll(sign);
|
||||
if (verify != null) {
|
||||
System.out.println("x509公钥: " + Util.bytes2HexString(((X509) verify.get("x509")).getPubKey()));
|
||||
System.out.println("签名原数据: " + verify.get("oData"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptDE54k12() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] oData = new byte[4 * 1024];
|
||||
|
||||
RetWrap retWrap = api.generateDEByDnHsm(dn, oData);
|
||||
byte[] CipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] sessionKey = (byte[]) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDNSoft(dn, new String(CipherKey));
|
||||
printRetWrap(retWrap1);
|
||||
byte[] deData = (byte[]) retWrap1.get("oData");
|
||||
Assert.assertArrayEquals(deData, oData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptDE54k21() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] oData = new byte[4 * 1024];
|
||||
|
||||
RetWrap retWrap = api.generateDEByDnSoft(dn, oData);
|
||||
byte[] CipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] sessionKey = (byte[]) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDNHsm(dn, new String(CipherKey));
|
||||
printRetWrap(retWrap1);
|
||||
byte[] deData = (byte[]) retWrap1.get("oData");
|
||||
Assert.assertArrayEquals(deData, oData);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecryptDE54k() throws UnsupportedEncodingException {
|
||||
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] oData = new byte[4 * 1024];
|
||||
|
||||
RetWrap retWrap = api.generateDEByDn(dn, oData);
|
||||
byte[] CipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] sessionKey = (byte[]) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, CipherKey);
|
||||
printRetWrap(retWrap1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecryptDE54kr() throws UnsupportedEncodingException {
|
||||
String dn = "CN=YCCA@黄金交易所@Zhuangj@1,OU=Individual-2,OU=YCCA,O=CFCA OCA1,C=CN";
|
||||
byte[] oData = new byte[4 * 1024];
|
||||
|
||||
RetWrap retWrap = api.generateDEByDn(dn, oData);
|
||||
byte[] CipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] sessionKey = (byte[]) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, CipherKey);
|
||||
printRetWrap(retWrap1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecryptDE520M() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] oData = new byte[20 * 1024 * 1024];
|
||||
|
||||
RetWrap retWrap = api.generateDEByDn(dn, oData);
|
||||
byte[] CipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] sessionKey = (byte[]) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, CipherKey);
|
||||
printRetWrap(retWrap1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptDE58k() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] oData = new byte[8 * 1024];
|
||||
|
||||
RetWrap retWrap = api.generateDEByDn(dn, oData);
|
||||
byte[] CipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] sessionKey = (byte[]) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, CipherKey);
|
||||
printRetWrap(retWrap1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptDE5() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] oData = "00001111222233".getBytes();
|
||||
|
||||
RetWrap retWrap = api.generateDEByDn(dn, oData);
|
||||
byte[] CipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] sessionKey = (byte[]) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, CipherKey);
|
||||
printRetWrap(retWrap1);
|
||||
}
|
||||
|
||||
|
||||
// 测试通过
|
||||
// 76
|
||||
@Test
|
||||
public void testSM3Hash() {
|
||||
String orgData = "FFFFFFFFFFFFFFFF";
|
||||
|
||||
byte[] hash = api.SM3Hash(orgData.getBytes());
|
||||
|
||||
System.out.println("hash:" + Util.bytes2HexString(hash));
|
||||
}
|
||||
|
||||
|
||||
// =============================工具方法==============================================
|
||||
|
||||
public static void printRetWrap(RetWrap rw) {
|
||||
printRetWrap(rw, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出
|
||||
*
|
||||
* @param rw
|
||||
*/
|
||||
public static void printRetWrap(RetWrap rw, boolean flag) {
|
||||
for (String s : rw.keySet()) {
|
||||
|
||||
Object o = rw.get(s);
|
||||
if (o instanceof String) {
|
||||
System.out.println(s + ":" + o);
|
||||
} else if (o instanceof byte[]) {
|
||||
if (flag) {
|
||||
System.out.println(s + ": " + Util.bytes2HexString((byte[]) o));
|
||||
} else {
|
||||
System.out.println(s + ": " + new String((byte[]) o));
|
||||
}
|
||||
} else {
|
||||
System.out.println(s + ":" + o);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
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.161", 8889, 1000);
|
||||
SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.17.162", 8889, 1000);
|
||||
|
||||
SydApi4j api = (SydApi4j) new SydApi4j();
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
public class Test8011 {
|
||||
|
||||
private static final String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
|
||||
// private static final String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
// private static final String dn = "1004282451";
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.18.59", 8889, null, 1000);
|
||||
|
||||
try {
|
||||
|
||||
boolean sign = api.deleteCert(dn);
|
||||
System.out.println(sign);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -22,7 +22,7 @@ public class TestBatchData {
|
||||
List<byte[]> pINdata = new ArrayList<byte[]>();
|
||||
pINdata.add("12345678".getBytes());
|
||||
|
||||
List<byte[]> datas = api.SYMEncryptDecryptBatchData(0x8, keys, 1, pINdata);
|
||||
// List<byte[]> datas = api.SYMEncryptDecryptBatchData(0x8, keys, 1, pINdata);
|
||||
|
||||
// boolean pass = api.SM2Verify( 1, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData), sign );
|
||||
}
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.constant.CertUsage;
|
||||
import com.sunyard.util.CertUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.security.cert.CertificateException;
|
||||
|
||||
public class TestCertUtil {
|
||||
|
||||
|
||||
private static String readCert(String cert){
|
||||
InputStream is = TestCertUtil.class.getResourceAsStream(cert);
|
||||
byte[] data = new byte[0];
|
||||
try {
|
||||
data = new byte[is.available()];
|
||||
is.read( data );
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new String( data );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case1() throws CertificateException, NoSuchProviderException {
|
||||
Assert.assertTrue(
|
||||
CertUtil.isSM2Cert(readCert("/x509/c1.crt"))
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case2() throws CertificateException, NoSuchProviderException {
|
||||
Assert.assertTrue(
|
||||
CertUtil.isSM2Cert(readCert("/x509/c2.crt"))
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case3() throws CertificateException, NoSuchProviderException {
|
||||
|
||||
CertUtil.isSM2Cert(readCert("/x509/c3.crt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case4() throws CertificateException, NoSuchProviderException {
|
||||
Assert.assertTrue(
|
||||
CertUtil.isSM2Cert(readCert("/x509/c4.crt"))
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case5() throws CertificateException, NoSuchProviderException {
|
||||
Assert.assertFalse(
|
||||
CertUtil.isSM2Cert(readCert("/x509/c5.crt"))
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case6() throws CertificateException, NoSuchProviderException {
|
||||
Assert.assertTrue(
|
||||
CertUtil.isSM2Cert(readCert("/x509/c6.crt"))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void certtype1() throws CertificateException, NoSuchProviderException {
|
||||
Assert.assertTrue(
|
||||
CertUtil.certUsageCheck( readCert("/x509/c1.crt") , CertUsage.digitalSignature , CertUsage.nonRepudiation )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void certtype2() throws CertificateException, NoSuchProviderException {
|
||||
Assert.assertTrue(
|
||||
CertUtil.certUsageCheck( readCert("/x509/c2.crt") , CertUsage.keyEncipherment )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void certtype4() throws CertificateException, NoSuchProviderException {
|
||||
Assert.assertTrue(
|
||||
CertUtil.certUsageCheck( readCert("/x509/c4.crt") , CertUsage.keyEncipherment )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void certtype5() throws CertificateException, NoSuchProviderException {
|
||||
Assert.assertTrue(
|
||||
CertUtil.certUsageCheck( readCert("/x509/c5.crt") )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void certtype6() throws CertificateException, NoSuchProviderException {
|
||||
Assert.assertTrue(
|
||||
CertUtil.certUsageCheck( readCert("/x509/c6.crt") , CertUsage.digitalSignature , CertUsage.nonRepudiation)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TestE0 {
|
||||
|
||||
private SydApi4j api;
|
||||
private byte[] data = new byte[ 0x501 ];
|
||||
private byte[] iv = new byte[ 32 ];
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
// 通过设置debug的属性开启debug,如果不设置则默认不打开
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
api = (SydApi4j) new SydApi4j().connect("172.16.18.59", 8889, null, 1000, 1000, 2);
|
||||
Arrays.fill( iv, (byte) 0x38 );
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
try {
|
||||
this.api.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void t1(){
|
||||
String sessionKeyByLMK = "X12345678123456781234567812345678";
|
||||
long start = System.currentTimeMillis();
|
||||
RetWrap retWrap = this.api.SYMEnDeData(true, 1, sessionKeyByLMK, 1, 1, data, iv, 0);
|
||||
byte[] enData = (byte[]) retWrap.get("msg_all");
|
||||
retWrap = this.api.SYMEnDeData(false, 1, sessionKeyByLMK, 1, 1, enData, iv, 0);
|
||||
byte[] oData = (byte[]) retWrap.get("msg_all");
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println( "耗时=" + ( end - start ) );
|
||||
Assert.assertArrayEquals( oData, data );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,297 +1,297 @@
|
||||
//package com.sunyard.sydapi.test;
|
||||
//
|
||||
//import com.sunyard.RetWrap;
|
||||
//import com.sunyard.SydApi;
|
||||
//import com.sunyard.cert.X509;
|
||||
//import com.sunyard.proto.Util;
|
||||
//import org.junit.After;
|
||||
//import org.junit.Before;
|
||||
//import org.junit.Test;
|
||||
//import racal.sunyard.main.SydApi4j;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.Base64;
|
||||
//
|
||||
//import static com.sunyard.sydapi.util.PrintUtil.printRetWrap;
|
||||
//
|
||||
///**
|
||||
// * 甘肃银行数字货币
|
||||
// */
|
||||
//public class TestGSYH {
|
||||
//
|
||||
// SydApi4j api;
|
||||
// // 对方加密证书sn
|
||||
// String sn = "1004282452";
|
||||
// // 自己签名证书sn
|
||||
// String sn1 = "1004282451";
|
||||
//
|
||||
// @Before
|
||||
// public void before() {
|
||||
// // 通过设置debug的属性开启debug,如果不设置则默认不打开
|
||||
// System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
// api = (SydApi4j) new SydApi4j().connect("61.164.40.82", 8889, null, 1000);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @After
|
||||
// public void after() {
|
||||
// try {
|
||||
// this.api.disconnect();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void test02() {
|
||||
// Base64.Encoder encoder = Base64.getEncoder();
|
||||
// Base64.Decoder decoder = Base64.getDecoder();
|
||||
//
|
||||
// // 2.
|
||||
// String data = "1111111111111111";
|
||||
// // 随机生成对称密钥,由指定的公钥加密生成数字信封
|
||||
// RetWrap retWrap = api.generateDEbyGS(sn, SydApi.ALG_SM4);
|
||||
// String sessionKey = (String) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
//
|
||||
// // sm4加密账号等数据
|
||||
// byte[] dataEnc = api.SYMEncryptData(SydApi.NALG_SM4, sessionKey, data.getBytes());
|
||||
// // base64转码
|
||||
// byte[] dataEncBs64 = encoder.encode(dataEnc);
|
||||
//
|
||||
// System.out.println("dataEncBs64: " + Util.bytes2HexString(dataEncBs64));
|
||||
//
|
||||
// // 将sm2加密后的数据进行base64转码
|
||||
// String cipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
// byte[] cipherKeyBs64 = encoder.encode(cipherKey.getBytes());
|
||||
//
|
||||
// // 3.
|
||||
// // 报文正文
|
||||
// String msg = "12313146464564";
|
||||
// // 对报文正文签名(内部会计算hash)
|
||||
// String msgSign = api.netGSSign(sn1, msg.getBytes());
|
||||
// // base64转码
|
||||
// byte[] msgSignBs64 = encoder.encode(msgSign.getBytes());
|
||||
//
|
||||
//
|
||||
// // -------------下面为城银清算步骤-----------------
|
||||
// // 7.
|
||||
// // base64解码
|
||||
// byte[] msgSignB = decoder.decode(msgSignBs64);
|
||||
// // 对报文验签
|
||||
// boolean b = api.netGSVerify(sn1, msg.getBytes(), new String(msgSignB));
|
||||
// System.out.println("验签结果: " + b);
|
||||
//
|
||||
// // 8.
|
||||
// byte[] cipherKeyB = decoder.decode(cipherKeyBs64);
|
||||
// // 解密数字信封获取对称密钥
|
||||
// RetWrap retWrap1 = api.decryptDE(sn, new String(cipherKeyB));
|
||||
// sessionKey = (String) retWrap1.get(SydApi.RET_SESSION_KEY);
|
||||
//
|
||||
// // 9.
|
||||
// // 使用对称密钥解密报文
|
||||
// dataEnc = decoder.decode(dataEncBs64);
|
||||
// byte[] bytes1 = api.SYMDecryptData(SydApi.NALG_SM4, sessionKey, dataEnc);
|
||||
// System.out.println("data: " + new String(bytes1));
|
||||
// }
|
||||
//
|
||||
// // 测试通过
|
||||
// // 8017
|
||||
// @Test
|
||||
// public void testGetX509CertFileBySN() {
|
||||
// String sn2 = "3C93000000000025";
|
||||
//
|
||||
// /**
|
||||
// * 通过证书序号 sn 获取的 X509 证书文件。
|
||||
// * @param sn sn,证书序号
|
||||
// * @param nCertType 证书类型,0:签名证书, 1:加密证书
|
||||
// * @return base64 编码的证书
|
||||
// */
|
||||
// String s = api.GetX509CertFileBySN(sn2, SydApi.FOR_SIGN);
|
||||
// System.out.println(s);
|
||||
//
|
||||
// /**
|
||||
// * 输入 X509 格式的证书,获取证书信息。
|
||||
// * @param pCert base64 编码的证书
|
||||
// * @return 证书信息类
|
||||
// * 证书信息类,包含:颁发者DN、 证书序列号、 证书主题、证书有效期的起始时间、证书有效期的终止时间、DER编码的公钥。
|
||||
// */
|
||||
// X509 x509 = api.GetX509CertInfo(s);
|
||||
// System.out.println("证书主题DN: " + x509.getSubject());
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void testimportCertAddHT() {
|
||||
// String cert1 = "MIIB4TCCAYSgAwIBAgIIPJMAAAAAACswDAYIKoEcz1UBg3UFADAmMQswCQYDVQQGEwJDTjEXMBUGA1UEAwwOU3VueWFyZFNNMlJvb3QwHhcNMTcxMTE3MDIzMDUxWhcNMjMwMTI1MDIzMDUxWjBZMQswCQYDVQQGEwJDTjELMAkGA1UECAwCWkoxCzAJBgNVBAcMAkhaMQ4wDAYDVQQKDAVISkpZUzERMA8GA1UECwwIMDAwMDAwMDAxDTALBgNVBAMMBDIyMjIwWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAATxqegqlmc/lduzBaKREyeNuPf78RA3wfJuhAv8zymLwQ6doefs1Iul+kMOukhfwY9aEhVdqws34FZMm2vs1+wXo2cwZTAOBgNVHQ8BAf8EBAMCAMAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwHwYDVR0jBBgwFoAU93/arv8hxtk6eq2g+6z+AqVO1cEwHQYDVR0OBBYEFHfjFl72707A6s+YVuGvEuyvFWTMMAwGCCqBHM9VAYN1BQADSQAwRgIhALzg7+QW7RU4phv+4arEv0IOeaA6dtR8VT4Bwin9oHTWAiEA9kLESGiYm8L5Htf7GBXgH+pk7BJ68clml41B/ejZglI=";
|
||||
//
|
||||
// String jgh = "00000000";
|
||||
//
|
||||
// /**
|
||||
// * 上传指定证书到加密设备,并在证书前后加上begin和end
|
||||
// * @param certData 证书的字节数组
|
||||
// * @param organizationId 机构号的字节数组
|
||||
// * @return
|
||||
// */
|
||||
// RetWrap retWrap = api.importCertAddHT(cert1, jgh.getBytes());
|
||||
// System.out.println(retWrap);
|
||||
// }
|
||||
//
|
||||
// // 8012
|
||||
// @Test
|
||||
// public void testSYD_Get_X509_CertInfo_HA1() {
|
||||
//
|
||||
// String orgData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
// "<Document xmlns=\"urn:cbcc:std:dcep:2020:tech:xsd:ccms.903.001.02\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
|
||||
// " <CertNtfctn>\n" +
|
||||
// " <GrpHdr>\n" +
|
||||
// " <MsgId>20211230001190300000000032001000</MsgId>\n" +
|
||||
// " <CreDtTm>2021-12-30T09:27:49</CreDtTm>\n" +
|
||||
// " <InstgPty>\n" +
|
||||
// " <InstgDrctPty>G4000131000016</InstgDrctPty>\n" +
|
||||
// " </InstgPty>\n" +
|
||||
// " <InstdPty>\n" +
|
||||
// " <InstdDrctPty>C1175662000017</InstdDrctPty>\n" +
|
||||
// " </InstdPty>\n" +
|
||||
// " </GrpHdr>\n" +
|
||||
// " <CertNtfctnInf>\n" +
|
||||
// " <ChgTp>CC00</ChgTp>\n" +
|
||||
// " <CertTp>CS01</CertTp>\n" +
|
||||
// " </CertNtfctnInf>\n" +
|
||||
// " </CertNtfctn>\n" +
|
||||
// "</Document>";
|
||||
//
|
||||
// String sign = "MIID3QYKKoEcz1UGAQQCAqCCA80wggPJAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIICxDCCAsAwggJjoAMCAQICEBAAAAAAAAAAAAAAEEJYBCMwDAYIKoEcz1UBg3UFADBcMQswCQYDVQQGEwJDTjEwMC4GA1" +
|
||||
// "UECgwnQ2hpbmEgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MRswGQYDVQQDDBJDRkNBIFRFU1QgU00yIE9DQTEwHhcNMjEwMTExMDk1MjI1WhcNMjIwMTExMDk1MjI1WjB2MQswCQYDVQQGEwJjbjEVMBMGA1UECgwMQ0ZDQSBURVNUIENBMQ8wDQYDVQQLDAZDQ0ZDQ0IxF" +
|
||||
// "DASBgNVBAsMC0VudGVycHJpc2VzMSkwJwYDVQQDDCAwNDFAODkwNDI5MDA5OTk5RkRAQ0JDQ0AwMDAwMDAwMTBZMBMGByqGSM49AgEGCCqBHM9VAYItA0IABExU5zuJ3pVl49mS3rTBwUcPuiI/zDR/w117PkpCgJ7m0kGyyorj1h2bxM62PthpNy99KPnk9gEvS696ZE5s8LGjgeowgecw" +
|
||||
// "HwYDVR0jBBgwFoAUa/4Y2o9COqa4bbMuiIM6NKLBMOEwSAYDVR0gBEEwPzA9BghggRyG7yoBATAxMC8GCCsGAQUFBwIBFiNodHRwOi8vd3d3LmNmY2EuY29tLmNuL3VzL3VzLTE0Lmh0bTA5BgNVHR8EMjAwMC6gLKAqhihodHRwOi8vdWNybC5jZmNhLmNvbS5jbi9TTTIvY3JsMTY4NzY" +
|
||||
// "uY3JsMAsGA1UdDwQEAwID6DAdBgNVHQ4EFgQUypxjmN7VBcoruhBRWmmFNv9yG1IwEwYDVR0lBAwwCgYIKwYBBQUHAwIwDAYIKoEcz1UBg3UFAANJADBGAiEA1IQTRQf5aaDJzzVxWLRml1ZSqQd9FPFeKZJnbzGQIQMCIQD/gY5+H1nytcVAx8hGtUPssklmI+9+vTdOF5LaKMR+jzGB3T" +
|
||||
// "CB2gIBATBwMFwxCzAJBgNVBAYTAkNOMTAwLgYDVQQKDCdDaGluYSBGaW5hbmNpYWwgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxGzAZBgNVBAMMEkNGQ0EgVEVTVCBTTTIgT0NBMQIQEAAAAAAAAAAAAAAQQlgEIzAMBggqgRzPVQGDEQUAMA0GCSqBHM9VAYItAQUABEYwRAIgXmjY/FIR8" +
|
||||
// "qudmZGsIQUivZDt3/73dGojVjj5L76OcJICIAHu0G242uYPY2B8zMkGw7kQ1C1xgRipEmlC1GWwMCz0";
|
||||
//
|
||||
// /**
|
||||
// * 验签并从签名中获取证书并上载到加密机
|
||||
// * @param orgData 待签名的原始数据
|
||||
// * @param sign 签名数据
|
||||
// * @return 证书信息(包含公钥字段)
|
||||
// */
|
||||
// X509 x509 = api.SYD_Get_X509_CertInfo_HA(orgData.getBytes(), sign);
|
||||
// System.out.println("证书公钥: " + Util.bytes2HexString(x509.getPubKey()));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // 测试通过
|
||||
// // 78
|
||||
// @Test
|
||||
// public void testSM2DecryptC() {
|
||||
// String certId = "1111111111111151";
|
||||
// String publicKey = "034200048043AF118B45629857DB693105849B2617FED249D59DFD29BE9A891ADEE7441A2D8C62020953DAEF038184E0244310CF2123C507F26F5380FFECC8D53E79B24E";
|
||||
//
|
||||
// String orgData = "FFFFFFFFFFFFFFFF";
|
||||
// String s = api.SM2Encrypt(Util.hexString2Bytes(publicKey), orgData.getBytes());
|
||||
//
|
||||
// System.out.println("加密后的数据: " + s);
|
||||
// System.out.println("加密后的数据解base64: " + Util.bytes2HexString(Base64.getDecoder().decode(s)));
|
||||
//
|
||||
// byte[] bytes = api.SM2DecryptC(certId, s);
|
||||
//
|
||||
// System.out.println("decData:" + new String(bytes));
|
||||
// }
|
||||
//
|
||||
// // 测试通过
|
||||
// // 78
|
||||
// @Test
|
||||
// public void testSM2DecryptOrder2() {
|
||||
// String userId = "8015";
|
||||
// String orgData = "FfffffffffffffFfffffffffffffffff";
|
||||
//
|
||||
// // 通过用户id获取公钥
|
||||
// String publicKey = api.SM2GetPublicKeyC(userId, SydApi.FOR_SIGN);
|
||||
//
|
||||
// /**
|
||||
// * 用指定的 SM2 公钥对指定的密文数据进行加密。
|
||||
// * 输出的sm2密文结构为C1C2C3格式
|
||||
// * @param publicKey 公钥钥串,DER 编码,HEX 格式。
|
||||
// * @param pOrgData 加密的数据。
|
||||
// * @return 加密的数据 base64 编码。
|
||||
// */
|
||||
// String s = api.SM2EncryptOrder(Util.hexString2Bytes(publicKey), orgData.getBytes());
|
||||
//
|
||||
// System.out.println("加密后的数据: " + s);
|
||||
//
|
||||
// /**
|
||||
// * 通过使用者 ID 所对应的私钥对指定的密文数据进行解密。
|
||||
// * 输入的sm2密文结构为C1C2C3格式
|
||||
// * @param userId 使用者的 ID,最大长度为 16 位数字,右对齐。
|
||||
// * @param enData 加密的数据,base64 编码。
|
||||
// * @param keyType 密钥类型,0:签名证书, 1:加密证书。
|
||||
// * @return 明文数据。
|
||||
// */
|
||||
// byte[] bytes = api.SM2DecryptOrder(userId, s, SydApi.FOR_SIGN);
|
||||
//
|
||||
// System.out.println("decData:" + new String(bytes));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testDecryptDE4() {
|
||||
// String sn = "1004282452";
|
||||
// String orgCode = "00001111222233";
|
||||
//
|
||||
// /**
|
||||
// * 产生对称密钥,通过公钥加密生成网联格式的数字信封。
|
||||
// *
|
||||
// * @param certSerial 对*方 X509 证书的序列号。
|
||||
// * @param orgCode 机构码
|
||||
// * @return RetWrap 包含 CipherKey, SessionKey, KCV
|
||||
// * CipherKey 公钥加密的会话密钥 ,BASE64 编码
|
||||
// * SessionKey 本地LMK 加密的会话密钥,HEX 格式, 本地 LMK 加密的会话密钥长度,HEX 格式(不包括第 1 个字符),一般为 33 个 Bytes。默认输入值为缓冲区的大小。
|
||||
// * KCV 会话密钥的检验值,HEX 格式,长度为 32H。
|
||||
// */
|
||||
// RetWrap retWrap = api.generateDEbyGS(sn, orgCode);
|
||||
// String CipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
// String sessionKey = (String) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
// String kcv = (String) retWrap.get(SydApi.RET_KCV);
|
||||
// printRetWrap(retWrap);
|
||||
//
|
||||
// /**
|
||||
// * 接收用私钥解密数字信封,还原对称密钥。
|
||||
// *
|
||||
// * @param pCertSerial 输入。 对方 X509 证书的序列号。
|
||||
// * @param pCipherKey 输入。 公钥加密的会话密钥,BASE64 编码
|
||||
// * @return RetWrap 包含 SessionKey KCV
|
||||
// * SessionKey 输出。 本地LMK 加密的会话密钥,格式为:密钥类型|密钥密文,比如:02|密钥密文
|
||||
// * KCV 会话密钥的检验值,HEX 格式,长度为 36H。
|
||||
// * orgCode 如果有机构码的话会返回机构码
|
||||
// */
|
||||
// RetWrap retWrap1 = api.decryptDE(sn, CipherKey);
|
||||
// printRetWrap(retWrap1);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // =========================工具方法=====================
|
||||
//
|
||||
// public static void printRetWrap(RetWrap rw) {
|
||||
// printRetWrap(rw, false);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 输出
|
||||
// * @param rw
|
||||
// */
|
||||
// public static void printRetWrap(RetWrap rw, boolean flag) {
|
||||
// for (String s : rw.keySet()) {
|
||||
//
|
||||
// Object o = rw.get(s);
|
||||
// if (o instanceof String) {
|
||||
// System.out.println(s + ":" + o);
|
||||
// } else if (o instanceof byte[]) {
|
||||
// if (flag) {
|
||||
// System.out.println(s + ": " + Util.bytes2HexString((byte[]) o));
|
||||
// } else {
|
||||
// System.out.println(s + ": " + new String((byte[]) o));
|
||||
// }
|
||||
// } else {
|
||||
// System.out.println(s + ":" + o);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.cert.X509;
|
||||
import com.sunyard.proto.Util;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
|
||||
import static com.sunyard.sydapi.util.PrintUtil.printRetWrap;
|
||||
|
||||
/**
|
||||
* 甘肃银行数字货币
|
||||
*/
|
||||
public class TestGSYH {
|
||||
|
||||
SydApi4j api;
|
||||
// 对方加密证书sn
|
||||
String sn = "1004282452";
|
||||
// 自己签名证书sn
|
||||
String sn1 = "1004282451";
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
// 通过设置debug的属性开启debug,如果不设置则默认不打开
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
api = (SydApi4j) new SydApi4j().connect("61.164.40.82", 8889, null, 1000);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
try {
|
||||
this.api.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test02() {
|
||||
Base64.Encoder encoder = Base64.getEncoder();
|
||||
Base64.Decoder decoder = Base64.getDecoder();
|
||||
|
||||
// 2.
|
||||
String data = "1111111111111111";
|
||||
// 随机生成对称密钥,由指定的公钥加密生成数字信封
|
||||
RetWrap retWrap = api.generateDEbyGS(sn, SydApi.ALG_SM4);
|
||||
String sessionKey = (String) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
|
||||
// sm4加密账号等数据
|
||||
byte[] dataEnc = api.SYMEncryptData(SydApi.NALG_SM4, sessionKey, data.getBytes());
|
||||
// base64转码
|
||||
byte[] dataEncBs64 = encoder.encode(dataEnc);
|
||||
|
||||
System.out.println("dataEncBs64: " + Util.bytes2HexString(dataEncBs64));
|
||||
|
||||
// 将sm2加密后的数据进行base64转码
|
||||
String cipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] cipherKeyBs64 = encoder.encode(cipherKey.getBytes());
|
||||
|
||||
// 3.
|
||||
// 报文正文
|
||||
String msg = "12313146464564";
|
||||
// 对报文正文签名(内部会计算hash)
|
||||
String msgSign = api.netGSSign(sn1, msg.getBytes());
|
||||
// base64转码
|
||||
byte[] msgSignBs64 = encoder.encode(msgSign.getBytes());
|
||||
|
||||
|
||||
// -------------下面为城银清算步骤-----------------
|
||||
// 7.
|
||||
// base64解码
|
||||
byte[] msgSignB = decoder.decode(msgSignBs64);
|
||||
// 对报文验签
|
||||
boolean b = api.netGSVerify(sn1, msg.getBytes(), new String(msgSignB));
|
||||
System.out.println("验签结果: " + b);
|
||||
|
||||
// 8.
|
||||
byte[] cipherKeyB = decoder.decode(cipherKeyBs64);
|
||||
// 解密数字信封获取对称密钥
|
||||
RetWrap retWrap1 = api.decryptDE(sn, new String(cipherKeyB));
|
||||
sessionKey = (String) retWrap1.get(SydApi.RET_SESSION_KEY);
|
||||
|
||||
// 9.
|
||||
// 使用对称密钥解密报文
|
||||
dataEnc = decoder.decode(dataEncBs64);
|
||||
byte[] bytes1 = api.SYMDecryptData(SydApi.NALG_SM4, sessionKey, dataEnc);
|
||||
System.out.println("data: " + new String(bytes1));
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 8017
|
||||
@Test
|
||||
public void testGetX509CertFileBySN() {
|
||||
String sn2 = "3C93000000000025";
|
||||
|
||||
/**
|
||||
* 通过证书序号 sn 获取的 X509 证书文件。
|
||||
* @param sn sn,证书序号
|
||||
* @param nCertType 证书类型,0:签名证书, 1:加密证书
|
||||
* @return base64 编码的证书
|
||||
*/
|
||||
String s = api.GetX509CertFileBySN(sn2, SydApi.FOR_SIGN);
|
||||
System.out.println(s);
|
||||
|
||||
/**
|
||||
* 输入 X509 格式的证书,获取证书信息。
|
||||
* @param pCert base64 编码的证书
|
||||
* @return 证书信息类
|
||||
* 证书信息类,包含:颁发者DN、 证书序列号、 证书主题、证书有效期的起始时间、证书有效期的终止时间、DER编码的公钥。
|
||||
*/
|
||||
X509 x509 = api.GetX509CertInfo(s);
|
||||
System.out.println("证书主题DN: " + x509.getSubject());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testimportCertAddHT() {
|
||||
String cert1 = "MIIB4TCCAYSgAwIBAgIIPJMAAAAAACswDAYIKoEcz1UBg3UFADAmMQswCQYDVQQGEwJDTjEXMBUGA1UEAwwOU3VueWFyZFNNMlJvb3QwHhcNMTcxMTE3MDIzMDUxWhcNMjMwMTI1MDIzMDUxWjBZMQswCQYDVQQGEwJDTjELMAkGA1UECAwCWkoxCzAJBgNVBAcMAkhaMQ4wDAYDVQQKDAVISkpZUzERMA8GA1UECwwIMDAwMDAwMDAxDTALBgNVBAMMBDIyMjIwWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAATxqegqlmc/lduzBaKREyeNuPf78RA3wfJuhAv8zymLwQ6doefs1Iul+kMOukhfwY9aEhVdqws34FZMm2vs1+wXo2cwZTAOBgNVHQ8BAf8EBAMCAMAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwHwYDVR0jBBgwFoAU93/arv8hxtk6eq2g+6z+AqVO1cEwHQYDVR0OBBYEFHfjFl72707A6s+YVuGvEuyvFWTMMAwGCCqBHM9VAYN1BQADSQAwRgIhALzg7+QW7RU4phv+4arEv0IOeaA6dtR8VT4Bwin9oHTWAiEA9kLESGiYm8L5Htf7GBXgH+pk7BJ68clml41B/ejZglI=";
|
||||
|
||||
String jgh = "00000000";
|
||||
|
||||
/**
|
||||
* 上传指定证书到加密设备,并在证书前后加上begin和end
|
||||
* @param certData 证书的字节数组
|
||||
* @param organizationId 机构号的字节数组
|
||||
* @return
|
||||
*/
|
||||
RetWrap retWrap = api.importCertAddHT(cert1, jgh.getBytes());
|
||||
System.out.println(retWrap);
|
||||
}
|
||||
|
||||
// 8012
|
||||
@Test
|
||||
public void testSYD_Get_X509_CertInfo_HA1() {
|
||||
|
||||
String orgData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<Document xmlns=\"urn:cbcc:std:dcep:2020:tech:xsd:ccms.903.001.02\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
|
||||
" <CertNtfctn>\n" +
|
||||
" <GrpHdr>\n" +
|
||||
" <MsgId>20211230001190300000000032001000</MsgId>\n" +
|
||||
" <CreDtTm>2021-12-30T09:27:49</CreDtTm>\n" +
|
||||
" <InstgPty>\n" +
|
||||
" <InstgDrctPty>G4000131000016</InstgDrctPty>\n" +
|
||||
" </InstgPty>\n" +
|
||||
" <InstdPty>\n" +
|
||||
" <InstdDrctPty>C1175662000017</InstdDrctPty>\n" +
|
||||
" </InstdPty>\n" +
|
||||
" </GrpHdr>\n" +
|
||||
" <CertNtfctnInf>\n" +
|
||||
" <ChgTp>CC00</ChgTp>\n" +
|
||||
" <CertTp>CS01</CertTp>\n" +
|
||||
" </CertNtfctnInf>\n" +
|
||||
" </CertNtfctn>\n" +
|
||||
"</Document>";
|
||||
|
||||
String sign = "MIID3QYKKoEcz1UGAQQCAqCCA80wggPJAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIICxDCCAsAwggJjoAMCAQICEBAAAAAAAAAAAAAAEEJYBCMwDAYIKoEcz1UBg3UFADBcMQswCQYDVQQGEwJDTjEwMC4GA1" +
|
||||
"UECgwnQ2hpbmEgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MRswGQYDVQQDDBJDRkNBIFRFU1QgU00yIE9DQTEwHhcNMjEwMTExMDk1MjI1WhcNMjIwMTExMDk1MjI1WjB2MQswCQYDVQQGEwJjbjEVMBMGA1UECgwMQ0ZDQSBURVNUIENBMQ8wDQYDVQQLDAZDQ0ZDQ0IxF" +
|
||||
"DASBgNVBAsMC0VudGVycHJpc2VzMSkwJwYDVQQDDCAwNDFAODkwNDI5MDA5OTk5RkRAQ0JDQ0AwMDAwMDAwMTBZMBMGByqGSM49AgEGCCqBHM9VAYItA0IABExU5zuJ3pVl49mS3rTBwUcPuiI/zDR/w117PkpCgJ7m0kGyyorj1h2bxM62PthpNy99KPnk9gEvS696ZE5s8LGjgeowgecw" +
|
||||
"HwYDVR0jBBgwFoAUa/4Y2o9COqa4bbMuiIM6NKLBMOEwSAYDVR0gBEEwPzA9BghggRyG7yoBATAxMC8GCCsGAQUFBwIBFiNodHRwOi8vd3d3LmNmY2EuY29tLmNuL3VzL3VzLTE0Lmh0bTA5BgNVHR8EMjAwMC6gLKAqhihodHRwOi8vdWNybC5jZmNhLmNvbS5jbi9TTTIvY3JsMTY4NzY" +
|
||||
"uY3JsMAsGA1UdDwQEAwID6DAdBgNVHQ4EFgQUypxjmN7VBcoruhBRWmmFNv9yG1IwEwYDVR0lBAwwCgYIKwYBBQUHAwIwDAYIKoEcz1UBg3UFAANJADBGAiEA1IQTRQf5aaDJzzVxWLRml1ZSqQd9FPFeKZJnbzGQIQMCIQD/gY5+H1nytcVAx8hGtUPssklmI+9+vTdOF5LaKMR+jzGB3T" +
|
||||
"CB2gIBATBwMFwxCzAJBgNVBAYTAkNOMTAwLgYDVQQKDCdDaGluYSBGaW5hbmNpYWwgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxGzAZBgNVBAMMEkNGQ0EgVEVTVCBTTTIgT0NBMQIQEAAAAAAAAAAAAAAQQlgEIzAMBggqgRzPVQGDEQUAMA0GCSqBHM9VAYItAQUABEYwRAIgXmjY/FIR8" +
|
||||
"qudmZGsIQUivZDt3/73dGojVjj5L76OcJICIAHu0G242uYPY2B8zMkGw7kQ1C1xgRipEmlC1GWwMCz0";
|
||||
|
||||
/**
|
||||
* 验签并从签名中获取证书并上载到加密机
|
||||
* @param orgData 待签名的原始数据
|
||||
* @param sign 签名数据
|
||||
* @return 证书信息(包含公钥字段)
|
||||
*/
|
||||
X509 x509 = api.SYD_Get_X509_CertInfo_HA(orgData.getBytes(), sign);
|
||||
System.out.println("证书公钥: " + Util.bytes2HexString(x509.getPubKey()));
|
||||
}
|
||||
|
||||
|
||||
// 测试通过
|
||||
// 78
|
||||
@Test
|
||||
public void testSM2DecryptC() {
|
||||
String certId = "1111111111111151";
|
||||
String publicKey = "034200048043AF118B45629857DB693105849B2617FED249D59DFD29BE9A891ADEE7441A2D8C62020953DAEF038184E0244310CF2123C507F26F5380FFECC8D53E79B24E";
|
||||
|
||||
String orgData = "FFFFFFFFFFFFFFFF";
|
||||
String s = api.SM2Encrypt(Util.hexString2Bytes(publicKey), orgData.getBytes());
|
||||
|
||||
System.out.println("加密后的数据: " + s);
|
||||
System.out.println("加密后的数据解base64: " + Util.bytes2HexString(Base64.getDecoder().decode(s)));
|
||||
|
||||
byte[] bytes = api.SM2DecryptC(certId, s);
|
||||
|
||||
System.out.println("decData:" + new String(bytes));
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 78
|
||||
@Test
|
||||
public void testSM2DecryptOrder2() {
|
||||
String userId = "8015";
|
||||
String orgData = "FfffffffffffffFfffffffffffffffff";
|
||||
|
||||
// 通过用户id获取公钥
|
||||
String publicKey = api.SM2GetPublicKeyC(userId, SydApi.FOR_SIGN);
|
||||
|
||||
/**
|
||||
* 用指定的 SM2 公钥对指定的密文数据进行加密。
|
||||
* 输出的sm2密文结构为C1C2C3格式
|
||||
* @param publicKey 公钥钥串,DER 编码,HEX 格式。
|
||||
* @param pOrgData 加密的数据。
|
||||
* @return 加密的数据 base64 编码。
|
||||
*/
|
||||
String s = api.SM2EncryptOrder(Util.hexString2Bytes(publicKey), orgData.getBytes());
|
||||
|
||||
System.out.println("加密后的数据: " + s);
|
||||
|
||||
/**
|
||||
* 通过使用者 ID 所对应的私钥对指定的密文数据进行解密。
|
||||
* 输入的sm2密文结构为C1C2C3格式
|
||||
* @param userId 使用者的 ID,最大长度为 16 位数字,右对齐。
|
||||
* @param enData 加密的数据,base64 编码。
|
||||
* @param keyType 密钥类型,0:签名证书, 1:加密证书。
|
||||
* @return 明文数据。
|
||||
*/
|
||||
byte[] bytes = api.SM2DecryptOrder(userId, s, SydApi.FOR_SIGN);
|
||||
|
||||
System.out.println("decData:" + new String(bytes));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptDE4() {
|
||||
String sn = "1004282452";
|
||||
String orgCode = "00001111222233";
|
||||
|
||||
/**
|
||||
* 产生对称密钥,通过公钥加密生成网联格式的数字信封。
|
||||
*
|
||||
* @param certSerial 对*方 X509 证书的序列号。
|
||||
* @param orgCode 机构码
|
||||
* @return RetWrap 包含 CipherKey, SessionKey, KCV
|
||||
* CipherKey 公钥加密的会话密钥 ,BASE64 编码
|
||||
* SessionKey 本地LMK 加密的会话密钥,HEX 格式, 本地 LMK 加密的会话密钥长度,HEX 格式(不包括第 1 个字符),一般为 33 个 Bytes。默认输入值为缓冲区的大小。
|
||||
* KCV 会话密钥的检验值,HEX 格式,长度为 32H。
|
||||
*/
|
||||
RetWrap retWrap = api.generateDEbyGS(sn, orgCode);
|
||||
String CipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
String sessionKey = (String) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
String kcv = (String) retWrap.get(SydApi.RET_KCV);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
/**
|
||||
* 接收用私钥解密数字信封,还原对称密钥。
|
||||
*
|
||||
* @param pCertSerial 输入。 对方 X509 证书的序列号。
|
||||
* @param pCipherKey 输入。 公钥加密的会话密钥,BASE64 编码
|
||||
* @return RetWrap 包含 SessionKey KCV
|
||||
* SessionKey 输出。 本地LMK 加密的会话密钥,格式为:密钥类型|密钥密文,比如:02|密钥密文
|
||||
* KCV 会话密钥的检验值,HEX 格式,长度为 36H。
|
||||
* orgCode 如果有机构码的话会返回机构码
|
||||
*/
|
||||
RetWrap retWrap1 = api.decryptDE(sn, CipherKey);
|
||||
printRetWrap(retWrap1);
|
||||
}
|
||||
|
||||
|
||||
// =========================工具方法=====================
|
||||
|
||||
public static void printRetWrap(RetWrap rw) {
|
||||
printRetWrap(rw, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出
|
||||
* @param rw
|
||||
*/
|
||||
public static void printRetWrap(RetWrap rw, boolean flag) {
|
||||
for (String s : rw.keySet()) {
|
||||
|
||||
Object o = rw.get(s);
|
||||
if (o instanceof String) {
|
||||
System.out.println(s + ":" + o);
|
||||
} else if (o instanceof byte[]) {
|
||||
if (flag) {
|
||||
System.out.println(s + ": " + Util.bytes2HexString((byte[]) o));
|
||||
} else {
|
||||
System.out.println(s + ": " + new String((byte[]) o));
|
||||
}
|
||||
} else {
|
||||
System.out.println(s + ":" + o);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,14 @@ import com.sunyard.SydApi;
|
||||
import com.sunyard.cert.X509;
|
||||
import com.sunyard.proto.Util;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Base64;
|
||||
|
||||
import static com.sunyard.sydapi.util.PrintUtil.printRetWrap;
|
||||
|
||||
/**
|
||||
* 衡泰例子
|
||||
@@ -25,6 +26,7 @@ public class TestHT {
|
||||
// 通过设置debug的属性开启debug,如果不设置则默认不打开
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
api = (SydApi4j) new SydApi4j().connect("172.16.18.59", 8889, null, 1000);
|
||||
// api = (SydApi4j) new SydApi4j().connect("192.168.0.66", 8889, null, 1000);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -36,36 +38,6 @@ public class TestHT {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程演示
|
||||
*/
|
||||
@Test
|
||||
public void testProcess() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = new byte[2 * 1024 * 1024];
|
||||
|
||||
// 签名
|
||||
String sign = api.attachedSign(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
// 生成数字信封
|
||||
RetWrap retWrap = api.generateDEByDn(dn, sign.getBytes());
|
||||
byte[] cipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
System.out.println("数字信封: " + new String(cipherKey));
|
||||
|
||||
// 解密数字信封
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, cipherKey);
|
||||
byte[] oData = (byte[]) retWrap1.get("oData");
|
||||
System.out.println("原数据: " + retWrap1.get("oData"));
|
||||
|
||||
// 验签
|
||||
RetWrap verify = api.attachedVerifyAndGetAll(oData);
|
||||
if (verify != null) {
|
||||
System.out.println("x509公钥: " + Util.bytes2HexString(((X509) verify.get("x509")).getPubKey()));
|
||||
System.out.println("签名原数据: " + Util.bytes2HexString((byte[]) (verify.get("oData"))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// 测试通过
|
||||
@@ -73,8 +45,8 @@ public class TestHT {
|
||||
@Test
|
||||
public void testSM2ConfirmSessionKeyC() {
|
||||
|
||||
String userId = "8012";
|
||||
byte[] data = "12343242".getBytes();
|
||||
String userId = "1111111111111151";
|
||||
String data = "12343242";
|
||||
|
||||
// 通过用户id获取公钥
|
||||
String pk = api.SM2GetPublicKeyC(userId, SydApi.FOR_ENCRYPT);
|
||||
@@ -87,7 +59,7 @@ public class TestHT {
|
||||
String kcv = (String) retWrap.get(SydApi.RET_KCV);
|
||||
|
||||
// 使用生成的对称密钥加密数据
|
||||
byte[] dataEnc = api.SYMEncryptData(SydApi.NALG_SM4, sessionKey, data);
|
||||
byte[] dataEnc = api.SYMEncryptData(SydApi.NALG_SM4, sessionKey, data.getBytes());
|
||||
|
||||
// 解密数字信封
|
||||
RetWrap retWrap1 = api.SM2ConfirmSessionKeyC(userId, cipherKey);
|
||||
@@ -100,66 +72,6 @@ public class TestHT {
|
||||
System.out.println("解密后的数据:" + new String(bytes1));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDetachedSignAndVerify1() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String orgData = "111111213323143243243";
|
||||
|
||||
|
||||
String sign = api.detachedSign(1, orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
System.out.println("签名结果 hex : " + Util.bytes2HexString(Util.decodeBase64(sign)));
|
||||
|
||||
boolean verify = api.detachedVerify(1, orgData.getBytes(), sign);
|
||||
System.out.println("验签结果: " + verify);
|
||||
Assert.assertTrue(verify);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetachedSignAndVerify2() throws UnsupportedEncodingException {
|
||||
// Dn 反转问题
|
||||
String dn = "CN=YCCA@黄金交易所@Zhuangj@1,OU=Individual-2,OU=YCCA,O=CFCA OCA1,C=CN";
|
||||
String orgData = "111111213323143243243";
|
||||
|
||||
|
||||
String sign = api.detachedSign(1, orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
System.out.println("签名结果 hex : " + Util.bytes2HexString(Util.decodeBase64(sign)));
|
||||
|
||||
boolean verify = api.detachedVerify(1, orgData.getBytes(), sign);
|
||||
System.out.println("验签结果: " + verify);
|
||||
Assert.assertTrue(verify);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetachedSignAndVerify3() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = new byte[3 * 1024];
|
||||
|
||||
String sign = api.attachedSign(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
System.out.println("签名结果 hex: " + Util.bytes2HexString(Util.decodeBase64(sign)));
|
||||
|
||||
boolean verify = api.attachedVerify(sign);
|
||||
System.out.println("验签结果: " + verify);
|
||||
Assert.assertTrue(verify);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetachedSignAndVerify8() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = new byte[8 * 1024];
|
||||
|
||||
String sign = api.attachedSign(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
System.out.println("签名结果 hex: " + Util.bytes2HexString(Util.decodeBase64(sign)));
|
||||
|
||||
boolean verify = api.attachedVerify(sign);
|
||||
System.out.println("验签结果: " + verify);
|
||||
Assert.assertTrue(verify);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 8018
|
||||
@Test
|
||||
@@ -168,7 +80,6 @@ public class TestHT {
|
||||
String orgData = "111111213323143243243";
|
||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
System.out.println("签名结果 hex : " + Util.bytes2HexString(Util.decodeBase64(sign)));
|
||||
|
||||
boolean verify = api.attachedVerify(sign);
|
||||
System.out.println("验签结果: " + verify);
|
||||
@@ -177,11 +88,10 @@ public class TestHT {
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyGetX509() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = "111111213323143243243".getBytes();
|
||||
String sign = api.attachedSign(orgData, dn);
|
||||
String orgData = "111111213323143243243";
|
||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
|
||||
X509 verify = api.attachedVerifyAndGetX509(sign);
|
||||
System.out.println("验签结果: " + Util.bytes2HexString(verify.getPubKey()));
|
||||
}
|
||||
@@ -193,183 +103,67 @@ public class TestHT {
|
||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
byte[] verify = api.attachedVerifyRD(sign);
|
||||
System.out.println("验签结果: " + Util.bytes2HexString(verify));
|
||||
String verify = api.attachedVerifyRD(sign);
|
||||
System.out.println("验签结果: " + verify);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyGetAll() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = "111111213323143243243".getBytes();
|
||||
String sign = api.attachedSign(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
RetWrap verify = api.attachedVerifyAndGetAll(sign);
|
||||
if (verify != null) {
|
||||
System.out.println("x509公钥: " + Util.bytes2HexString(((X509) verify.get("x509")).getPubKey()));
|
||||
System.out.println("签名原数据: " + verify.get("oData"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyGetAll8k() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = new byte[ 8 * 1024 ];
|
||||
String sign = api.attachedSign(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
RetWrap verify = api.attachedVerifyAndGetAll(sign);
|
||||
if (verify != null) {
|
||||
System.out.println("x509公钥: " + Util.bytes2HexString(((X509) verify.get("x509")).getPubKey()));
|
||||
System.out.println("签名原数据: " + verify.get("oData"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyGetX509C() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = "111111213323143243243".getBytes();
|
||||
byte[] sign = api.attachedSignC(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
X509 verify = api.attachedVerifyAndGetX509(sign);
|
||||
System.out.println("验签结果: " + Util.bytes2HexString(verify.getPubKey()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyRDC() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String orgData = "111111213323143243243";
|
||||
byte[] sign = api.attachedSignC(orgData.getBytes(), dn);
|
||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
byte[] verify = api.attachedVerifyRD(sign);
|
||||
System.out.println("验签结果: " + Util.bytes2HexString(verify));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyGetAllC() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] orgData = "111111213323143243243".getBytes();
|
||||
byte[] sign = api.attachedSignC(orgData, dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
|
||||
RetWrap verify = api.attachedVerifyAndGetAll(sign);
|
||||
if (verify != null) {
|
||||
System.out.println("x509公钥: " + Util.bytes2HexString(((X509) verify.get("x509")).getPubKey()));
|
||||
System.out.println("x509公钥: " + Util.bytes2HexString(((X509)verify.get("x509")).getPubKey()));
|
||||
System.out.println("签名原数据: " + verify.get("oData"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptDE54k12() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] oData = new byte[4 * 1024];
|
||||
|
||||
RetWrap retWrap = api.generateDEByDnHsm(dn, oData);
|
||||
byte[] CipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] sessionKey = (byte[]) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDNSoft(dn, new String(CipherKey));
|
||||
printRetWrap(retWrap1);
|
||||
byte[] deData = (byte[]) retWrap1.get("oData");
|
||||
Assert.assertArrayEquals(deData, oData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptDE54k21() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] oData = new byte[4 * 1024];
|
||||
|
||||
RetWrap retWrap = api.generateDEByDnSoft(dn, oData);
|
||||
byte[] CipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] sessionKey = (byte[]) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDNHsm(dn, new String(CipherKey));
|
||||
printRetWrap(retWrap1);
|
||||
byte[] deData = (byte[]) retWrap1.get("oData");
|
||||
Assert.assertArrayEquals(deData, oData);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecryptDE54k() throws UnsupportedEncodingException {
|
||||
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] oData = new byte[4 * 1024];
|
||||
|
||||
RetWrap retWrap = api.generateDEByDn(dn, oData);
|
||||
byte[] CipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] sessionKey = (byte[]) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, CipherKey);
|
||||
printRetWrap(retWrap1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecryptDE54kr() throws UnsupportedEncodingException {
|
||||
String dn = "CN=YCCA@黄金交易所@Zhuangj@1,OU=Individual-2,OU=YCCA,O=CFCA OCA1,C=CN";
|
||||
byte[] oData = new byte[4 * 1024];
|
||||
|
||||
RetWrap retWrap = api.generateDEByDn(dn, oData);
|
||||
byte[] CipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] sessionKey = (byte[]) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, CipherKey);
|
||||
printRetWrap(retWrap1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecryptDE520M() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] oData = new byte[20 * 1024 * 1024];
|
||||
|
||||
RetWrap retWrap = api.generateDEByDn(dn, oData);
|
||||
byte[] CipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] sessionKey = (byte[]) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, CipherKey);
|
||||
printRetWrap(retWrap1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptDE58k() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] oData = new byte[8 * 1024];
|
||||
|
||||
RetWrap retWrap = api.generateDEByDn(dn, oData);
|
||||
byte[] CipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] sessionKey = (byte[]) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, CipherKey);
|
||||
printRetWrap(retWrap1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptDE5() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] oData = "00001111222233".getBytes();
|
||||
String oData = "00001111222233";
|
||||
|
||||
RetWrap retWrap = api.generateDEByDn(dn, oData);
|
||||
byte[] CipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
byte[] sessionKey = (byte[]) retWrap.get(SydApi.RET_SESSION_KEY);
|
||||
printRetWrap(retWrap);
|
||||
String cipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
System.out.println("数字信封: " + cipherKey);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, CipherKey);
|
||||
printRetWrap(retWrap1);
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, cipherKey);
|
||||
System.out.println("原数据: " + retWrap1.get("oData"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程演示
|
||||
*/
|
||||
@Test
|
||||
public void testProcess() {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String orgData = "111111213323143243243";
|
||||
|
||||
// 签名
|
||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
// 生成数字信封
|
||||
RetWrap retWrap = api.generateDEByDn(dn, sign);
|
||||
String cipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
System.out.println("数字信封: " + cipherKey);
|
||||
|
||||
// 解密数字信封
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, cipherKey);
|
||||
String oData = (String) retWrap1.get("oData");
|
||||
System.out.println("原数据: " + retWrap1.get("oData"));
|
||||
|
||||
// 验签
|
||||
RetWrap verify = api.attachedVerifyAndGetAll(oData);
|
||||
if (verify != null) {
|
||||
System.out.println("x509公钥: " + Util.bytes2HexString(((X509)verify.get("x509")).getPubKey()));
|
||||
System.out.println("签名原数据: " + verify.get("oData"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 76
|
||||
@@ -391,7 +185,6 @@ public class TestHT {
|
||||
|
||||
/**
|
||||
* 输出
|
||||
*
|
||||
* @param rw
|
||||
*/
|
||||
public static void printRetWrap(RetWrap rw, boolean flag) {
|
||||
@@ -411,4 +204,7 @@ public class TestHT {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
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 TestICBC {
|
||||
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><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>";
|
||||
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( "<MainBody><MsgId><Id>000000000000000201809181000008627</Id><CreDtTm>2018-09-17T19:06:39</CreDtTm></MsgId><CertNtfctnInf><ChngTp>CC00</ChngTp></CertNtfctnInf></MainBody>".getBytes(), sign2 );
|
||||
// System.out.println( pass );
|
||||
//
|
||||
// // 获取公钥
|
||||
// X509 x = api.SYD_Get_X509_CertInfo_HA( "<MainBody><MsgId><Id>000000000000000201809181000008627</Id><CreDtTm>2018-09-17T19:06:39</CreDtTm></MsgId><CertNtfctnInf><ChngTp>CC00</ChngTp></CertNtfctnInf></MainBody>".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"),
|
||||
"<MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>".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"),
|
||||
"<MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>".getBytes() ,
|
||||
sign3
|
||||
) );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -537,7 +537,7 @@ public class TestLast {
|
||||
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验证签名(+)
|
||||
@@ -560,7 +560,7 @@ public class TestLast {
|
||||
//15.7计算HASH散列值(MD5\SHA1\SHA256)(+) -> pass
|
||||
@Test
|
||||
public void RSASignC() {
|
||||
RetWrap retWrap1 = api.countHash(1, 0, key2.getBytes(), key1.getBytes());
|
||||
RetWrap retWrap1 = api.conutHash(1, 0, key2.getBytes(), key1.getBytes());
|
||||
System.out.println(retWrap1);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ public class TestPKCS1 {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug","true");
|
||||
|
||||
// 连接加密机
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.0.200", 8889, null, 1000);
|
||||
|
||||
@@ -22,10 +22,10 @@ public class TestPKCS1 {
|
||||
try {
|
||||
|
||||
// 原始数据模式
|
||||
case1( api );
|
||||
// case1( api );
|
||||
|
||||
// 外部 hash
|
||||
// case2( api );
|
||||
case2( api );
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
package com.sunyard.sydapi.sample;
|
||||
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
@@ -15,7 +15,7 @@ public class TestPKCS7 {
|
||||
|
||||
// 连接加密机
|
||||
// SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.17.162", 8889, null, 1000);
|
||||
SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.18.59", 8889, 1000);
|
||||
SydApi4j.SYD_Set_Parameter_HA("unkown", "192.168.0.100", 8889, 1000);
|
||||
SydApi4j api = (SydApi4j) new SydApi4j();
|
||||
|
||||
try {
|
||||
|
||||
@@ -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 = "<MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>";
|
||||
private static final String testData = "<MainBody><MsgId><Id>000000000000000201902231000012910</Id><CreDtTm>2019-02-23T09:29:19</CreDtTm></MsgId><CertNtfctnInf><ChngTp>CC00</ChngTp></CertNtfctnInf></MainBody>";
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,104 +1,104 @@
|
||||
//package com.sunyard.sydapi.test;
|
||||
//
|
||||
//
|
||||
//import com.sunyard.SydApi;
|
||||
//import com.sunyard.proto.Util;
|
||||
//import racal.sunyard.main.SydApi4j;
|
||||
//import racal.sunyard.main.SydApiBuilder;
|
||||
//
|
||||
//import static com.sunyard.SydApi.*;
|
||||
//
|
||||
//
|
||||
//public class TestSV {
|
||||
//
|
||||
// private static final String inHexData = "67c6697351ff4aec29cdbaabf2fbe346";
|
||||
// private static final String dn = "C=CN,ST=浙江,L=杭州,O=信雅达测试123,OU=安全应用1,OU=安全应用2,CN=@信雅达安全测试";
|
||||
//
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
// System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
// // 连接加密机
|
||||
// SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.18.59", 8889, null, 1000);
|
||||
//
|
||||
// SydApiBuilder builder = new SydApiBuilder().setIp("192.168.5.88");
|
||||
// builder.build();
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// // case1(api);
|
||||
// case4(api);
|
||||
// case5(api);
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// } finally {
|
||||
// api.disconnect();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static void case1(SydApi api) {
|
||||
// String sign = api.attachedSign( Util.hexString2Bytes( inHexData ), dn );
|
||||
// System.out.println("签名结果 " + sign );
|
||||
//
|
||||
//
|
||||
// boolean pass = api.attachedVerify(sign);
|
||||
// System.out.println("验签结果 " + pass);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static void case2(SydApi api) {
|
||||
// System.out.println("begin SYD_Sign_Detach");
|
||||
// String sign = api.detachedSign( DATA_ORIGIN, Util.hexString2Bytes( inHexData ), dn );
|
||||
// System.out.println("签名结果 " + sign );
|
||||
// System.out.println("begin SYD_Sign_Detach");
|
||||
//
|
||||
// System.out.println("begin SYD_Verify_Detach");
|
||||
// boolean pass = api.detachedVerify(DATA_ORIGIN, Util.hexString2Bytes( inHexData ), sign);
|
||||
// System.out.println("验签结果 " + pass);
|
||||
// System.out.println("end SYD_Verify_Detach");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static void case3(SydApi api) {
|
||||
// System.out.println("begin SYD_NakedSign");
|
||||
// byte[] sign = api.SYD_NakedSign( Util.hexString2Bytes(inHexData) , dn);
|
||||
// System.out.println("签名结果 " + Util.bytes2HexString(sign) );
|
||||
// System.out.println("end SYD_NakedSign");
|
||||
//
|
||||
// System.out.println("begin SYD_NakedVerify");
|
||||
// boolean pass = api.SYD_NakedVerify( Util.hexString2Bytes(inHexData), sign, dn);
|
||||
// System.out.println("验签结果 " + pass);
|
||||
// System.out.println("end SYD_NakedVerify");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static void case4(SydApi api) {
|
||||
// // 不传 ID
|
||||
// String pk = api.SM2GetPublicKeyC("65667", 0 );
|
||||
// String sk = api.SM2GetPrivateKeyC("000000000006566700000000001");
|
||||
//
|
||||
// String sign = api.SM2SignC( 0, sk, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData) );
|
||||
// System.out.println("签名结果 " + sign );
|
||||
//
|
||||
// boolean pass = api.SM2Verify(Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData), sign );
|
||||
// System.out.println("验签结果 " + pass);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static void case5(SydApi api) {
|
||||
// // 传 ID
|
||||
// String uid = "8765432187654321";
|
||||
// String pk = api.SM2GetPublicKeyC("65667", 0 );
|
||||
// String sk = api.SM2GetPrivateKeyC("000000000006566700000000001");
|
||||
//
|
||||
// System.out.println("begin SYD_Sign_P1");
|
||||
// String sign = api.SM2SignC( 0, uid, sk, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData) );
|
||||
// System.out.println("签名结果 " + Util.bytes2HexString( Util.decodeBase64( sign ) ) );
|
||||
// System.out.println("end SYD_Verify_P1");
|
||||
//
|
||||
// System.out.println("begin SYD_Sign_P1");
|
||||
// boolean pass = api.SM2Verify(uid, 1, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData), sign );
|
||||
// System.out.println("验签结果 " + pass);
|
||||
// System.out.println("end SYD_Verify_P1");
|
||||
// }
|
||||
//}
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import static com.sunyard.SydApi.*;
|
||||
|
||||
|
||||
public class TestSV {
|
||||
|
||||
private static final String inHexData = "67c6697351ff4aec29cdbaabf2fbe346";
|
||||
private static final String dn = "C=CN,ST=浙江,L=杭州,O=信雅达测试123,OU=安全应用1,OU=安全应用2,CN=@信雅达安全测试";
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
// 连接加密机
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.18.59", 8889, null, 1000);
|
||||
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp("192.168.5.88");
|
||||
builder.build();
|
||||
|
||||
try {
|
||||
|
||||
// case1(api);
|
||||
case4(api);
|
||||
case5(api);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
api.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public static void case1(SydApi api) {
|
||||
String sign = api.attachedSign( Util.hexString2Bytes( inHexData ), dn );
|
||||
System.out.println("签名结果 " + sign );
|
||||
|
||||
|
||||
boolean pass = api.attachedVerify(sign);
|
||||
System.out.println("验签结果 " + pass);
|
||||
}
|
||||
|
||||
|
||||
public static void case2(SydApi api) {
|
||||
System.out.println("begin SYD_Sign_Detach");
|
||||
String sign = api.detachedSign( DATA_ORIGIN, Util.hexString2Bytes( inHexData ), dn );
|
||||
System.out.println("签名结果 " + sign );
|
||||
System.out.println("begin SYD_Sign_Detach");
|
||||
|
||||
System.out.println("begin SYD_Verify_Detach");
|
||||
boolean pass = api.detachedVerify(DATA_ORIGIN, Util.hexString2Bytes( inHexData ), sign);
|
||||
System.out.println("验签结果 " + pass);
|
||||
System.out.println("end SYD_Verify_Detach");
|
||||
}
|
||||
|
||||
|
||||
public static void case3(SydApi api) {
|
||||
System.out.println("begin SYD_NakedSign");
|
||||
byte[] sign = api.SYD_NakedSign( Util.hexString2Bytes(inHexData) , dn);
|
||||
System.out.println("签名结果 " + Util.bytes2HexString(sign) );
|
||||
System.out.println("end SYD_NakedSign");
|
||||
|
||||
System.out.println("begin SYD_NakedVerify");
|
||||
boolean pass = api.SYD_NakedVerify( Util.hexString2Bytes(inHexData), sign, dn);
|
||||
System.out.println("验签结果 " + pass);
|
||||
System.out.println("end SYD_NakedVerify");
|
||||
}
|
||||
|
||||
|
||||
public static void case4(SydApi api) {
|
||||
// 不传 ID
|
||||
String pk = api.SM2GetPublicKeyC("65667", 0 );
|
||||
String sk = api.SM2GetPrivateKeyC("000000000006566700000000001");
|
||||
|
||||
String sign = api.SM2SignC( 0, sk, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData) );
|
||||
System.out.println("签名结果 " + sign );
|
||||
|
||||
boolean pass = api.SM2Verify(Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData), sign );
|
||||
System.out.println("验签结果 " + pass);
|
||||
}
|
||||
|
||||
|
||||
public static void case5(SydApi api) {
|
||||
// 传 ID
|
||||
String uid = "8765432187654321";
|
||||
String pk = api.SM2GetPublicKeyC("65667", 0 );
|
||||
String sk = api.SM2GetPrivateKeyC("000000000006566700000000001");
|
||||
|
||||
System.out.println("begin SYD_Sign_P1");
|
||||
String sign = api.SM2SignC( 0, uid, sk, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData) );
|
||||
System.out.println("签名结果 " + Util.bytes2HexString( Util.decodeBase64( sign ) ) );
|
||||
System.out.println("end SYD_Verify_P1");
|
||||
|
||||
System.out.println("begin SYD_Sign_P1");
|
||||
boolean pass = api.SM2Verify(uid, 1, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData), sign );
|
||||
System.out.println("验签结果 " + pass);
|
||||
System.out.println("end SYD_Verify_P1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
public class TestShangqingXingye {
|
||||
private static final byte[] orgDataBig = new byte[ 5 * 1024];
|
||||
private static final byte[] orgData2k = new byte[ 2 * 1024];
|
||||
private static final String pcDnEN = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
|
||||
public static void main(String[] args) {
|
||||
//System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
long startTime = System.currentTimeMillis(); //获取开始时间
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp("192.168.0.100");
|
||||
SydApi4j api = (SydApi4j) builder.build();
|
||||
|
||||
try {
|
||||
|
||||
/**
|
||||
* 产生对称密钥,通过公钥加密生成数字信封,。
|
||||
* @param pcDnEN: 清算所的公钥证书
|
||||
* @param pcData: 明文数据。
|
||||
* @return RetWrap: 数字信封
|
||||
*/
|
||||
RetWrap signData = api.generateDEByDn(pcDnEN, orgDataBig);
|
||||
byte[] cpkey2 = (byte[]) signData.get("CipherKey");
|
||||
System.out.println("加密信封:" + new String(cpkey2));
|
||||
|
||||
/**
|
||||
* 接收用私钥解密数字信封,还原原文。。
|
||||
* @param pcDnEN: 清算所的公钥证书
|
||||
* @param cpkey: 数字信封。
|
||||
* @return preData: 原数据
|
||||
*/
|
||||
RetWrap oDataWrap = api.decryptDEByDN(pcDnEN, cpkey2);
|
||||
byte[] preData = (byte[]) oDataWrap.get("oData");
|
||||
System.out.println("解密信封:" + Util.bytes2HexString(preData));
|
||||
|
||||
|
||||
/**
|
||||
* 通过指定的私钥对指定的原始数据编制带公钥证书的数字签名(遵循PKCS#7),
|
||||
* @param orgData: 待签名的原始数据
|
||||
* @param pcDnEN: 签名者证书 DN
|
||||
* @return signsData: 签名数据
|
||||
*/
|
||||
String signsData = api.SYD_SM2_DetachedSign_HA(orgData2k, pcDnEN);
|
||||
System.out.println("签名数据:" + signsData);
|
||||
|
||||
/**
|
||||
* 利用清算所的公钥证书对签名数据进行验签。
|
||||
* @param dataType: 数据模式, 0:输入的数据为 HASH 后的数据, 1:输入的数据为原始数据库(本次传入1)
|
||||
* @param orgData: 待签名的原始数据
|
||||
* @param sign: 签名数据。
|
||||
*/
|
||||
boolean result = api.detachedVerify(1, orgData2k, signsData);
|
||||
System.out.println("验签结果:" + result);
|
||||
|
||||
|
||||
/**
|
||||
* 产生对称密钥,通过清算所公钥证书加密生成数字信封。
|
||||
* 利用会员的私钥证书对数据进行签名
|
||||
* 上清所 SYD_SignDzigitalEnvelope (String pcDnEN, String pcDnSign, byte[] pcData);
|
||||
* @param pcDnEN: 清算所的公钥证书
|
||||
* @param pcDnSign:会员的私钥证书
|
||||
* @param pcData: 明文数据。
|
||||
* @return pcSignData: 签名数字信封
|
||||
*/
|
||||
String pcSignData = api.SYD_SignDigitalEnvelope(pcDnEN, pcDnEN, orgData2k);
|
||||
System.out.println("签名数字信封:" + pcSignData);
|
||||
|
||||
/**
|
||||
* 利用清算所公钥证书对签名数据进行验签。接收用会员的私钥证书解密数字信封,还原原文。
|
||||
* 上清所 byte[] SYD_VerifyDigitalEnveloe(String pcDnDe, String pcDnVerify, String pcSignData );
|
||||
* @param pcDnDe: 会员的私钥证书
|
||||
* @param pcDnVerify: 清算所公钥证书
|
||||
* @param pcSignData: 签名数字信封数据。
|
||||
* @return pcData:原数据
|
||||
*/
|
||||
|
||||
byte[] oData = api.SYD_VerifyDigitalEnveloe(pcDnEN, pcDnEN, pcSignData);
|
||||
System.out.println("原数据:" + Util.bytes2HexString(oData));
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
long endTime = System.currentTimeMillis(); //获取结束时间
|
||||
System.out.println("程序运行时间:" + (endTime - startTime) + "ms"); //输出程序运行时间
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,113 +1,113 @@
|
||||
//package com.sunyard.sydapi.test;
|
||||
//
|
||||
//import com.sunyard.trans.PacketSN;
|
||||
//import org.junit.Test;
|
||||
//import racal.sunyard.main.SydApi4j;
|
||||
//
|
||||
//import java.lang.reflect.Method;
|
||||
//import java.lang.reflect.ParameterizedType;
|
||||
//import java.lang.reflect.Type;
|
||||
//import java.text.SimpleDateFormat;
|
||||
//import java.util.Arrays;
|
||||
//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();
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.trans.PacketSN;
|
||||
import org.junit.Test;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
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<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", 0);
|
||||
data.put("certificateModel$option", 0);
|
||||
data.put("certificateSn", "113123");
|
||||
data.put("keyType", "X");
|
||||
packet.put("data", data);
|
||||
SectionWrap s=new SectionWrap();
|
||||
HashMap<String, Section> sc = new HashMap<String, Section>();
|
||||
SectionValue s2=new SectionValue();
|
||||
s2.setValue("L".getBytes());
|
||||
sc.put("data",s2);
|
||||
s.setSections(sc);*/
|
||||
// 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", 0);
|
||||
// data.put("certificateModel$option", 0);
|
||||
// data.put("certificateSn", "113123");
|
||||
// data.put("keyType", "X");
|
||||
// packet.put("data", data);
|
||||
// SectionWrap s=new SectionWrap();
|
||||
// HashMap<String, Section> sc = new HashMap<String, Section>();
|
||||
// SectionValue s2=new SectionValue();
|
||||
// s2.setValue("L".getBytes());
|
||||
// sc.put("data",s2);
|
||||
// s.setSections(sc);*/
|
||||
//// HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||
//// HashMap<String, Object> data = new HashMap<String, Object>();
|
||||
//// 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();
|
||||
//// }
|
||||
// PacketSN sn = PacketSN.gen();
|
||||
// packet.put("header", sn.getSn().array());
|
||||
// data.put("algorithmId$option", 0x1);
|
||||
// data.put("keyLength", 256);
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获取所有方法
|
||||
// */
|
||||
// @Test
|
||||
// public void getMethod() {
|
||||
// Class<SydApi4j> jClass = SydApi4j.class;
|
||||
//
|
||||
// Method[] dm = jClass.getDeclaredMethods();
|
||||
//
|
||||
// System.out.println(dm.length);
|
||||
//
|
||||
// for (int i = 0; i < dm.length; i++) {
|
||||
// Type[] types = dm[i].getGenericParameterTypes();
|
||||
// System.out.print(dm[i].getName() + "(");
|
||||
// for (int j = 0; j < types.length; j++) {
|
||||
// Type type = types[j];
|
||||
//
|
||||
// System.out.print(getRealTypeName(type));
|
||||
// if (j != types.length - 1) {
|
||||
// System.out.print(", ");
|
||||
// }
|
||||
// }
|
||||
// System.out.println(")");
|
||||
// try {
|
||||
// byte[] a=(byte[]) Util.eval("ResE2","getKeyLen",packet,null,null);
|
||||
// System.out.println(a[0]);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public String getRealTypeName(Type type) {
|
||||
//
|
||||
// String resultName = "";
|
||||
// if (type instanceof ParameterizedType) {
|
||||
//
|
||||
// resultName = getRealName(type.getTypeName()) + "<";
|
||||
//
|
||||
// Type[] actualTypes = ((ParameterizedType) type).getActualTypeArguments();
|
||||
//
|
||||
// for (int z = 0; z < actualTypes.length; z++) {
|
||||
// resultName += getRealName(actualTypes[z].getTypeName());
|
||||
// if (z != actualTypes.length - 1) {
|
||||
// resultName += ", ";
|
||||
// }
|
||||
// }
|
||||
// resultName += ">";
|
||||
// } else {
|
||||
// resultName = getRealName(type.getTypeName());
|
||||
// }
|
||||
//
|
||||
// return resultName.replace("$", ".");
|
||||
// }
|
||||
//
|
||||
// public String getRealName(String typeName) {
|
||||
// if (typeName.contains(".") && typeName.contains("<")) {
|
||||
// typeName = typeName.substring(0, typeName.indexOf("<"));
|
||||
// return typeName.substring(typeName.lastIndexOf(".") + 1);
|
||||
// }
|
||||
//
|
||||
// if (typeName.contains(".")) {
|
||||
// return typeName.substring(typeName.lastIndexOf(".") + 1);
|
||||
// }
|
||||
//
|
||||
// return typeName;
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有方法
|
||||
*/
|
||||
@Test
|
||||
public void getMethod() {
|
||||
Class<SydApi4j> jClass = SydApi4j.class;
|
||||
|
||||
Method[] dm = jClass.getDeclaredMethods();
|
||||
|
||||
System.out.println(dm.length);
|
||||
|
||||
for (int i = 0; i < dm.length; i++) {
|
||||
Type[] types = dm[i].getGenericParameterTypes();
|
||||
System.out.print(dm[i].getName() + "(");
|
||||
for (int j = 0; j < types.length; j++) {
|
||||
Type type = types[j];
|
||||
|
||||
System.out.print(getRealTypeName(type));
|
||||
if (j != types.length - 1) {
|
||||
System.out.print(", ");
|
||||
}
|
||||
}
|
||||
System.out.println(")");
|
||||
}
|
||||
}
|
||||
|
||||
public String getRealTypeName(Type type) {
|
||||
|
||||
String resultName = "";
|
||||
if (type instanceof ParameterizedType) {
|
||||
|
||||
resultName = getRealName(type.getTypeName()) + "<";
|
||||
|
||||
Type[] actualTypes = ((ParameterizedType) type).getActualTypeArguments();
|
||||
|
||||
for (int z = 0; z < actualTypes.length; z++) {
|
||||
resultName += getRealName(actualTypes[z].getTypeName());
|
||||
if (z != actualTypes.length - 1) {
|
||||
resultName += ", ";
|
||||
}
|
||||
}
|
||||
resultName += ">";
|
||||
} else {
|
||||
resultName = getRealName(type.getTypeName());
|
||||
}
|
||||
|
||||
return resultName.replace("$", ".");
|
||||
}
|
||||
|
||||
public String getRealName(String typeName) {
|
||||
if (typeName.contains(".") && typeName.contains("<")) {
|
||||
typeName = typeName.substring(0, typeName.indexOf("<"));
|
||||
return typeName.substring(typeName.lastIndexOf(".") + 1);
|
||||
}
|
||||
|
||||
if (typeName.contains(".")) {
|
||||
return typeName.substring(typeName.lastIndexOf(".") + 1);
|
||||
}
|
||||
|
||||
return typeName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,457 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.cert.X509;
|
||||
import com.sunyard.proto.Util;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 新疆联通政务云
|
||||
*/
|
||||
public class TestXJ {
|
||||
|
||||
SydApi4j api;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
// 通过设置debug的属性开启debug,如果不设置则默认不打开
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
api = (SydApi4j) new SydApi4j().connect("192.168.0.100", 8889, null, 1000);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
try {
|
||||
this.api.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 8003
|
||||
@Test
|
||||
public void testSYD_NakedSign() {
|
||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
byte[] bytes = api.SYD_NakedSign("111".getBytes(), dn);
|
||||
System.out.println(Util.bytes2HexString(bytes));
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 8004
|
||||
@Test
|
||||
public void testSYD_NakedVerify() {
|
||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
String orgData = "111";
|
||||
byte[] bytes = api.SYD_NakedSign(orgData.getBytes(), dn);
|
||||
String sign = Util.bytes2HexString(bytes);
|
||||
System.out.println(sign);
|
||||
|
||||
boolean b = api.SYD_NakedVerify(orgData.getBytes(), bytes, dn);
|
||||
System.out.println(b);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 6C
|
||||
@Test
|
||||
public void testNetSign() {
|
||||
String sn = "1004282451";
|
||||
String s = api.netSign(sn, "111".getBytes());
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 6D
|
||||
@Test
|
||||
public void testNetVerify() {
|
||||
String sn = "1004282451";
|
||||
String data = "111";
|
||||
String s = api.netSign(sn, data.getBytes());
|
||||
|
||||
boolean b = api.netVerify(sn, data.getBytes(), s);
|
||||
System.out.println(b);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 80
|
||||
@Test
|
||||
public void testSM2SignCustomized() {
|
||||
String sn = "1004282452";
|
||||
String s = api.SM2SignCustomized(sn, "111".getBytes());
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 81
|
||||
@Test
|
||||
public void testSM2VerifyCustomized() {
|
||||
String sn = "1004282451";
|
||||
String data = "111";
|
||||
String s = api.SM2SignCustomized(sn, data.getBytes());
|
||||
|
||||
boolean b = api.SM2VerifyCustomized(sn, data.getBytes(), s);
|
||||
System.out.println(b);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 74
|
||||
@Test
|
||||
public void testSM2SignC() {
|
||||
String userId = "1111111111111113";
|
||||
String certNo = "1234567812345678";
|
||||
String thisPublicKey = "03420004549B6A1A09A5D0D9432C6829D443F85ED8785340FC1AB14118BB7637830C808F7A888DF0C4F988EA6FF2EE6C76ECD00C4B7CEC92CC8EA365F8EA291041CAB231";
|
||||
String thisOrgData = "FFFFFFFFFFFFFFFF";
|
||||
|
||||
String s = api.SM2SignC(userId, certNo, 1, Util.hexString2Bytes(thisPublicKey), thisOrgData.getBytes());
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 75
|
||||
@Test
|
||||
public void testSM2Verify() {
|
||||
|
||||
String userId = "1111111111111113";
|
||||
String certNo = "1234567812345678";
|
||||
String thisPublicKey = "03420004549B6A1A09A5D0D9432C6829D443F85ED8785340FC1AB14118BB7637830C808F7A888DF0C4F988EA6FF2EE6C76ECD00C4B7CEC92CC8EA365F8EA291041CAB231";
|
||||
String thisOrgData = "FFFFFFFFFFFFFFFF";
|
||||
|
||||
String s = api.SM2SignC(userId, certNo, 1, Util.hexString2Bytes(thisPublicKey), thisOrgData.getBytes());
|
||||
|
||||
System.out.println(s);
|
||||
boolean b = api.SM2Verify(certNo, 1, Util.hexString2Bytes(thisPublicKey), thisOrgData.getBytes(), s);
|
||||
System.out.println(b);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 8005
|
||||
@Test
|
||||
public void testSYD_DetachedSign() {
|
||||
|
||||
String orgData = "3214312341243214";
|
||||
String DN = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
String s = api.SYD_DetachedSign(orgData.getBytes(), DN);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 8006
|
||||
@Test
|
||||
public void testSYD_DetachedVerify() {
|
||||
String orgData = "3214312341243214";
|
||||
String DN = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
String sign = api.SYD_DetachedSign(orgData.getBytes(), DN);
|
||||
System.out.println("签名结果" + sign);
|
||||
|
||||
boolean b = api.SYD_DetachedVerify(orgData.getBytes(), sign);
|
||||
System.out.println("验签结果:" + b);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 8005
|
||||
@Test
|
||||
public void testSm3AndDetachedSign() {
|
||||
String publicKey = "0342000469DE3847DD6A66DA96DB8F2DCFA32E10E680FF2EF4A592079E7C3A44320BB15084E7CA9782A39B6E28F07C04FE00D68958A2605921E71712D56C1E4435A39FA5";
|
||||
String orgData = "FFFFFFFFFFFFFFFF";
|
||||
String testCertNo = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
|
||||
String sign = api.sm3AndDetachedSign(orgData.getBytes(), publicKey, testCertNo);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
boolean b = api.sm3AndDetachedVerify(orgData.getBytes(), publicKey, sign);
|
||||
System.out.println("验签结果:" + b);
|
||||
}
|
||||
|
||||
|
||||
// 测试通过
|
||||
// 8005
|
||||
@Test
|
||||
public void testDetachedSign() {
|
||||
String publicKey = "0342000469DE3847DD6A66DA96DB8F2DCFA32E10E680FF2EF4A592079E7C3A44320BB15084E7CA9782A39B6E28F07C04FE00D68958A2605921E71712D56C1E4435A39FA5";
|
||||
String orgData = "FFFFFFFFFFFFFFFF";
|
||||
String testCertNo = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
|
||||
byte[] hash = api.SM3Hash(publicKey, orgData.getBytes());
|
||||
|
||||
String sign = api.detachedSign(
|
||||
SydApi.DATA_HASH,
|
||||
hash,
|
||||
testCertNo
|
||||
);
|
||||
|
||||
System.out.println("\t签名结果: " + sign);
|
||||
|
||||
boolean verify = api.detachedVerify(
|
||||
SydApi.DATA_HASH,
|
||||
hash,
|
||||
sign
|
||||
);
|
||||
|
||||
System.out.println("\t验签结果: " + verify);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 72
|
||||
@Test
|
||||
public void testSM2GenSessionKey() {
|
||||
|
||||
String pk="034200041CD47354867E12B9D138F098413C47D42EDEB2AD402EAB431C0C7AC2FE2D6DE9C67273C643C709F2A749188941B7FA7F9FF14F8E7D19316936DB4D4954FF3819";
|
||||
|
||||
RetWrap retWrap = api.SM2GenSessionKey(pk);
|
||||
printRetWrap(retWrap);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 73
|
||||
@Test
|
||||
public void testSM2ConfirmSessionKeyC() {
|
||||
|
||||
String userId = "1111111111111147";
|
||||
|
||||
String pk="0342000422C4FC907E0BEC600C2070D675EFB65EAE3A628260FF5461DD5F8133CF7CF98530EF392D016B6487BA6148E9AC27BDD4E8D7404A310CB09335F50AEF00ADB068";
|
||||
|
||||
RetWrap retWrap = api.SM2GenSessionKey(pk);
|
||||
printRetWrap(retWrap);
|
||||
|
||||
String cipherKey = (String) retWrap.get("CipherKey");
|
||||
|
||||
RetWrap retWrap1 = api.SM2ConfirmSessionKeyC(userId, cipherKey);
|
||||
printRetWrap(retWrap1);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// E0
|
||||
@Test
|
||||
public void testSYMEncryptData() {
|
||||
String sessionKey = "XF356BCBA3204F6E6F356BCBA3204F6E6";
|
||||
String pInData = "1111111111111111";
|
||||
|
||||
byte[] bytes = api.SYMEncryptData(3,sessionKey, pInData.getBytes());
|
||||
byte[] bytes1 = api.SYMDecryptData(3, sessionKey, bytes);
|
||||
System.out.println(new String(bytes1));
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// E0
|
||||
@Test
|
||||
public void testEncDecData() {
|
||||
|
||||
String msg = "1111111111111111111111";
|
||||
|
||||
String key = "X3C9003C47A13379011733681ABB4A4D0";
|
||||
|
||||
byte[] bytes = api.SYMEncryptDataCBC(1, key, msg.getBytes());
|
||||
|
||||
System.out.println("输出为: " + Util.bytes2HexString(bytes));
|
||||
|
||||
byte[] bytes1 = api.SYMDecryptDataCBC(1, key, bytes);
|
||||
System.out.println("明文:" + new String(bytes1));
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 6B
|
||||
@Test
|
||||
public void testDecryptDE() {
|
||||
String sn = "1004282452";
|
||||
RetWrap retWrap = api.generateDE(sn, (byte) 0x30);
|
||||
String sessionKey = (String) retWrap.get("SessionKey");
|
||||
String CipherKey = (String) retWrap.get("CipherKey");
|
||||
String KCV = (String) retWrap.get("KCV");
|
||||
|
||||
RetWrap retWrap1 = api.decryptDE(sn, CipherKey);
|
||||
printRetWrap(retWrap1);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 7E
|
||||
@Test
|
||||
public void testSYD_SM2_Get_Dn_PublicKey_HA() {
|
||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
String s = api.SYD_SM2_Get_Dn_PublicKey_HA(dn.getBytes(), 0);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 6E
|
||||
@Test
|
||||
public void testGetX509SN() {
|
||||
String dn = "C=CN,ST=ZJ,L=HZ,O=SUNYARD,OU=123456,CN=111";
|
||||
String s = api.getX509SN(0, dn.getBytes());
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 7E
|
||||
@Test
|
||||
public void testGetDNPublicKey() {
|
||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
String s = api.GetDNPublicKey(0, dn.getBytes());
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// QQ
|
||||
@Test
|
||||
public void testSM2GetPublicKeyC() {
|
||||
String userId = "1111111111111117";
|
||||
|
||||
String s = api.SM2GetPublicKeyC(userId, 0);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 8016
|
||||
@Test
|
||||
public void testGetX509CertInfo() {
|
||||
|
||||
String pCert = "-----BEGIN CERTIFICATE-----\u0007MIIC1jCCAnqgAwIBAgIFQAKAAXQwDAYIKoEcz1UBg3UFADBhMQswCQYDVQQGEwJD\u0007TjEwMC4GA1UECgwnQ2hpbmEgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9y\u0007aXR5MSAwHgYDVQQDDBdDRkNBIEFDUyBURVNUIFNNMiBPQ0EzMTAeFw0xNzExMTYw\u0007NjU0NDVaFw0yMjExMTYwNjU0NDVaMIGDMQswCQYDVQQGEwJDTjEcMBoGA1UECgwT\u0007Q0ZDQSBURVNUIFNNMiBPQ0EzMTEOMAwGA1UECwwFU0hDUEUxGTAXBgNVBAsMEE9y\u0007Z2FuaXphdGlvbmFsLTExKzApBgNVBAMMIjA1MUDkuIrmtbfnpajmja7kuqTmmJPm\u0007iYBAQUFBQUFBQDgwWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAARg8D1RBEv9lpOE\u0007Q3SdzdLCQ4fDiE8Ncb2Fl4qIGc12GA/LUS1fgzLZuk0WlgyZDSe+QlQziqkmsXsx\u0007KoTCzqsto4H5MIH2MD8GCCsGAQUFBwEBBDMwMTAvBggrBgEFBQcwAYYjaHR0cDov\u0007L29jc3B0ZXN0LmNmY2EuY29tLmNuOjgwL29jc3AwHwYDVR0jBBgwFoAUBMe8+VkB\u0007aT6MNDYgYhg83ry1uwwwDAYDVR0TAQH/BAIwADA2BgNVHR8ELzAtMCugKaAnhiVo\u0007dHRwOi8vMjEwLjc0LjQyLjMvT0NBMzEvU00yL2NybDEuY3JsMA4GA1UdDwEB/wQE\u0007AwIGwDAdBgNVHQ4EFgQUomdLtdhENYb16pe1LNRlcr4N7b8wHQYDVR0lBBYwFAYI\u0007KwYBBQUHAwIGCCsGAQUFBwMEMAwGCCqBHM9VAYN1BQADSAAwRQIgZpJGhpRKmgfi\u0007Vbdq3UAGW6I3AUMfbWMd6webLQXmCOoCIQDSxTKRb0TfoXepD3VgO9qxCDwSc4yn\u0007WJ2GC3qmr81QBg==\u0007-----END CERTIFICATE-----\u0007";
|
||||
X509 x509 = api.GetX509CertInfo(pCert);
|
||||
|
||||
String path = "E:\\work\\sunyard\\证书\\sm2.q\\sm2.q.enc.crt.pem";
|
||||
X509 x509_1 = api.GetX509CertInfo(getCertStr(path));
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 8017
|
||||
@Test
|
||||
public void testGetX509CertFileC() {
|
||||
String userId = "8001";
|
||||
|
||||
String s = api.GetX509CertFileC(userId, 0);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// E2
|
||||
@Test
|
||||
public void testSM2GenKeyPair() {
|
||||
RetWrap retWrap = api.SM2GenKeyPair();
|
||||
printRetWrap(retWrap, true);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// QN
|
||||
@Test
|
||||
public void testSYD_SM2GenKeyPair() {
|
||||
RetWrap retWrap = api.SYD_SM2GenKeyPair();
|
||||
printRetWrap(retWrap);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 77
|
||||
@Test
|
||||
public void testSM2Encrypt() {
|
||||
String publicKey = "03420004C51A40A094B6A14500B2980603D68CA263FF1BA238AFB17BB8B791C5F444465A749B68B4584C83E7BEF66DE2446177E14DBE0F32691F54B1636CC73334A1A94D";
|
||||
String orgData = "FFFFFFFFFFFFFFFF";
|
||||
String s = api.SM2Encrypt(Util.hexString2Bytes(publicKey), orgData.getBytes());
|
||||
|
||||
System.out.println("encData: " + s);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 78
|
||||
@Test
|
||||
public void testSM2DecryptC() {
|
||||
String certId = "1111111111111122";
|
||||
String publicKey = "0342000469DE3847DD6A66DA96DB8F2DCFA32E10E680FF2EF4A592079E7C3A44320BB15084E7CA9782A39B6E28F07C04FE00D68958A2605921E71712D56C1E4435A39FA5";
|
||||
String orgData = "FFFFFFFFFFFFFFFF";
|
||||
String s = api.SM2Encrypt(Util.hexString2Bytes(publicKey), orgData.getBytes());
|
||||
|
||||
byte[] bytes = api.SM2DecryptC(certId, s);
|
||||
|
||||
System.out.println("decData:" + new String(bytes));
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 76
|
||||
// 带公钥
|
||||
@Test
|
||||
public void testSM3Hash() {
|
||||
String publicKey = "0342000469DE3847DD6A66DA96DB8F2DCFA32E10E680FF2EF4A592079E7C3A44320BB15084E7CA9782A39B6E28F07C04FE00D68958A2605921E71712D56C1E4435A39FA5";
|
||||
String orgData = "FFFFFFFFFFFFFFFF";
|
||||
|
||||
byte[] hash = api.SM3Hash(publicKey, orgData.getBytes());
|
||||
|
||||
System.out.println("hash:" + Util.bytes2HexString(hash));
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 76
|
||||
// 不带公钥
|
||||
@Test
|
||||
public void testSM3Hash2() {
|
||||
String orgData = "FFFFFFFFFFFFFFFF";
|
||||
|
||||
byte[] hash = api.SM3Hash(orgData.getBytes());
|
||||
|
||||
System.out.println("hash:" + Util.bytes2HexString(hash));
|
||||
}
|
||||
|
||||
// 工具方法
|
||||
// ==========================================
|
||||
|
||||
public static void printRetWrap(RetWrap rw) {
|
||||
printRetWrap(rw, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出
|
||||
* @param rw
|
||||
*/
|
||||
public static void printRetWrap(RetWrap rw, boolean flag) {
|
||||
for (String s : rw.keySet()) {
|
||||
|
||||
Object o = rw.get(s);
|
||||
if (o instanceof String) {
|
||||
System.out.println(s + ":" + o);
|
||||
} else if (o instanceof byte[]) {
|
||||
if (flag) {
|
||||
System.out.println(s + ": " + Util.bytes2HexString((byte[]) o));
|
||||
} else {
|
||||
System.out.println(s + ": " + new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) o))));
|
||||
}
|
||||
} else {
|
||||
System.out.println(s + ":" + o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取证书
|
||||
public String getCertStr(String path) {
|
||||
|
||||
BufferedInputStream bis = null;
|
||||
try {
|
||||
bis = new BufferedInputStream(new FileInputStream(path));
|
||||
|
||||
StringBuilder str = new StringBuilder();
|
||||
|
||||
int len = 0;
|
||||
|
||||
while ((len = bis.read()) != -1) {
|
||||
str.append((char) len);
|
||||
}
|
||||
|
||||
return str.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (bis != null) {
|
||||
try {
|
||||
bis.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package com.sunyard.sydapi.util;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import org.bouncycastle.asn1.cms.ContentInfo;
|
||||
import org.bouncycastle.cms.SydCmsUtil;
|
||||
|
||||
import org.bouncycastle.asn1.ASN1Sequence;
|
||||
import org.bouncycastle.asn1.ASN1Set;
|
||||
import org.bouncycastle.asn1.ASN1TaggedObject;
|
||||
import org.bouncycastle.asn1.DEROctetString;
|
||||
import org.bouncycastle.asn1.cms.ContentInfo;
|
||||
import org.bouncycastle.cms.SydCmsUtil;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
import org.junit.Test;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
|
||||
public class SydCmsUtilTest {
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.0.200", 8889, null, 1000);
|
||||
|
||||
try {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String oData = "00001111222233";
|
||||
|
||||
RetWrap retWrap = api.generateDEByDnSoft(dn, oData.getBytes() );
|
||||
byte[] cipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
System.out.println("数字信封: " + cipherKey);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, cipherKey);
|
||||
System.out.println("原数据: " + retWrap1.get("oData"));
|
||||
}catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if ( null != api ) {
|
||||
api.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
//
|
||||
//
|
||||
// String tmpl = "3082014D06092A864886F70D010703A082013E3082013A0201003181F73081F40201003065305C310B300906035504061302434E3130302E060355040A0C274368696E612046696E616E6369616C2043657274696669636174696F6E20417574686F72697479311B301906035504030C1243464341205445535420534D32204F43413102051004282452300B06092A811CCF5501822D03047B307902203C3AF535307DA548DA02C0AD171D2BC24D22472B42E5E175FCAF2C5CD30B5443022100ED53E7594F35FFACEB57F05898123F78E5B2D045CC47D894CD2E7BD34D66DA1D042014BD71F8CDA9729093A7CC391E2009C5D5F007586C2EBFB55BC175A6E8BDA33E04104AB82510BFDDD4FEE79C3F107D6F7F94303B060A2A811CCF550601040201301B06072A811CCF55016804100000000000000000000000000000000080109FD3D4338DB19E672CC162AF5B9B03E9";
|
||||
//
|
||||
// System.out.println( SydCmsUtil.class.getClassLoader() );
|
||||
//
|
||||
// ContentInfo info = SydCmsUtil.getContentInfo(Util.hexString2Bytes( tmpl ) );
|
||||
//
|
||||
// System.out.println( info );
|
||||
//
|
||||
// info = SydApi4j.genCMSEnvelopedData(new byte[0], new byte[0]);
|
||||
//
|
||||
// SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.0.200", 8889, null, 1000);
|
||||
//
|
||||
// try {
|
||||
// String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
// String oData = "00001111222233";
|
||||
//
|
||||
// RetWrap retWrap = api.generateDEByDnSoft(dn, oData);
|
||||
// String cipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
// System.out.println("数字信封: " + cipherKey);
|
||||
//
|
||||
// RetWrap retWrap1 = api.decryptDEByDN(dn, cipherKey);
|
||||
// System.out.println("原数据: " + retWrap1.get("oData"));
|
||||
// }catch ( Exception e ) {
|
||||
// e.printStackTrace();
|
||||
// } finally {
|
||||
// if ( null != api ) {
|
||||
// api.disconnect();
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package lrapi;
|
||||
|
||||
public class lr {
|
||||
|
||||
public static String AUTO = "AUTO";
|
||||
|
||||
public static void start_transaction(String t) {
|
||||
System.out.println("start_transaction" + t);
|
||||
}
|
||||
|
||||
public static void end_transaction(String t, String type) {
|
||||
System.out.println("end_transaction" + t);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package sample;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApiPoolBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* 集群模式 - 长连接
|
||||
*/
|
||||
public class HSMPoolLongLink {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 调试模式
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
// 建立链接
|
||||
final String[] pcipList = {"172.16.18.59", "192.168.0.200"};
|
||||
final int[] iportList = {8889, 8889};
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int tmp = i;
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SydApiPoolBuilder builder = new SydApiPoolBuilder(pcipList, iportList, 10, 1000);
|
||||
SydApi api = builder.build();
|
||||
try {
|
||||
for (int j = 0; j < 20; j++) {
|
||||
byte[] data = api.SM3Hash("test".getBytes());
|
||||
System.out.println("hex=" + Util.bytes2HexString(data));
|
||||
// boolean sign = api.deleteCert("C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1");
|
||||
// System.out.println(sign);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (null != api) {
|
||||
api.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, i + "t").start();
|
||||
}
|
||||
System.out.println(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package sample;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApiClusterBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* 集群模式 - 短连接
|
||||
*/
|
||||
public class HSMPoolShortLink {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 调试模式
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
// 建立链接
|
||||
final String[] pcipList = {"172.16.18.59", "192.168.0.200"};
|
||||
final int[] iportList = {8889, 8889};
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int tmp = i;
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SydApi api = SydApiClusterBuilder.SYD_Short_Connect_Ex(
|
||||
pcipList,
|
||||
iportList,
|
||||
10,
|
||||
1000);
|
||||
try {
|
||||
for (int j = 0; j < 20; j++) {
|
||||
byte[] data = api.SM3Hash("test".getBytes());
|
||||
System.out.println("hex=" + Util.bytes2HexString(data));
|
||||
// boolean sign = api.deleteCert("C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1");
|
||||
// System.out.println(sign);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (null != api) {
|
||||
api.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package sample;
|
||||
|
||||
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 HashTest {
|
||||
|
||||
private static final String ip = "172.16.17.161";
|
||||
private SydApi api;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
api = new SydApi4j().connect(ip, 8889, null, 5000);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
if (null != api) {
|
||||
api.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void md5(){
|
||||
api.itHash( 2, new byte[ 5 * 1024 * 1024 ]);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void sha1(){
|
||||
api.itHash( 0, new byte[ 5 * 1024 * 1024 ]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sha256(){
|
||||
api.itHash( 1, new byte[ 5 * 1024 * 1024 ]);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void hex(){
|
||||
String s = "MEQCICECex9ZSh6PktFDu3rkszxJ++miqXBs5uCJS2VL8lhUAiBgZSLbJAMgrpTpmRL2L/5XsWBHSoFbKI6ToSzDnbPCaQ==";
|
||||
System.out.println(Util.bytes2HexString(Util.decodeBase64(s)));
|
||||
System.out.println(new String(Util.decodeBase64(s)));
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package sample;
|
||||
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
public class Sample4GH {
|
||||
private static final String SM2dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
private static final String SM2dn2 = "C=CN,O=SM2,OU=test,CN=1";
|
||||
private static final String RSAdn = "C=cn,O=CFCA TEST CA,OU=NCS2,OU=Enterprises,CN=041@Z402451000010@ShanDong@00000001";
|
||||
private static final byte[] orgData = new byte[ 1024];
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
//设置连接
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp("172.16.17.161");
|
||||
SydApi4j api = (SydApi4j) builder.build();
|
||||
|
||||
byte[] nakedSign = api.SYD_NakedSign(SM2dn, orgData, (byte[]) null);
|
||||
System.out.println("裸签"+nakedSign);
|
||||
|
||||
boolean nakedVerify = api.SYD_NakedVerify(SM2dn, nakedSign, orgData, (byte[]) null);
|
||||
System.out.println("裸签验签"+nakedVerify);
|
||||
|
||||
String detachedSign = api.detachedSign(1, orgData, SM2dn);
|
||||
System.out.println("det签名"+detachedSign);
|
||||
|
||||
boolean detachedVerify = api.detachedVerify(1, orgData, detachedSign);
|
||||
System.out.println("det验签"+detachedVerify);
|
||||
|
||||
String attachedSign = api.attachedSignHsm(orgData, SM2dn);
|
||||
System.out.println("att签名"+attachedSign);
|
||||
|
||||
boolean attachedVerify = api.attachedVerify(attachedSign.getBytes());
|
||||
System.out.println("att验签"+attachedVerify);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package sample;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Sample4HY {
|
||||
private static final String SM2dn = "C=cn,O=CFCA TEST OCA1,OU=Local RA,OU=Organizational-1,CN=041@Z8000000001938231GX0@8000000001938231GX0@00000001";
|
||||
private static final String SM2dn2 = "C=CN,O=Sunyard,OU=8001,CN=8001" ;
|
||||
|
||||
|
||||
private static final byte[] orgData = new byte[ 10*1024];
|
||||
|
||||
public static void main(String[] args) {
|
||||
//调试模式(控制台会打印发送报文)
|
||||
//System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
//证书是否反序校验
|
||||
//System.setProperty("com.sunyard.dnsort", "false");
|
||||
//主备模式连接
|
||||
SydApi4j.SYD_Set_Parameter_HA("172.16.17.47", "172.16.17.16", 8889, 1000);
|
||||
SydApi4j api = (SydApi4j) new SydApi4j();
|
||||
//设置连接
|
||||
// SydApiBuilder builder = new SydApiBuilder().setIp("192.168.0.100");
|
||||
// SydApi4j api = (SydApi4j) builder.build();
|
||||
try {
|
||||
|
||||
// SM2裸签
|
||||
byte[] nakedSign1 = api.SYD_NakedSign(orgData, SM2dn2);
|
||||
System.out.println("SM2数据裸签:"+ Util.bytes2HexString(nakedSign1));
|
||||
|
||||
String sign= "30450221008E2342E7C1CECACC46BF7CB6777382FE6A1B19D89DF80428B87630EEC8D4D4CD02200CF82B240708765432ED74495DD73A0BF1E6DCDE6AE56C6CB4BEFA1A875E777E";
|
||||
|
||||
boolean nakedVerify1 = api.SYD_NakedVerify(orgData, Util.hexString2Bytes(sign), SM2dn2);
|
||||
System.out.println("SM2数据验签:"+nakedVerify1 );
|
||||
|
||||
String s = api.detachedSign(1, orgData, SM2dn2);
|
||||
System.out.println("原始数据小于4k签名:"+s);
|
||||
|
||||
//原始数据大于4k
|
||||
byte[] hash = api.SM3Hash(orgData);//计算hash
|
||||
String s2 = api.detachedSign(0, hash, SM2dn2);
|
||||
System.out.println("原始数据大于4k签名:"+s2);
|
||||
|
||||
String aa = "MIIDLwYKKoEcz1UGAQQCAqCCAx8wggMbAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIICMTCCAi0wggHSoAMCAQICBgGKaA2T3TAMBggqgRzPVQGDdQUAMEsxCzAJBgNVBAYTAkNOMQ4wDAYDVQQKEwVHTVNTTDEQMA4GA1UECxMHUEtJL1NNMjEaMBgGA1UEAxMRTWlkZGxlQ0EgZm9yIFRlc3QwIhgPMjAyMzA5MDUxNjAwMDBaGA8yMDI0MDkwNTE2MDAwMFowXTELMAkGA1UEBgwCQ04xCzAJBgNVBAgMAnpqMQswCQYDVQQHDAJoejEQMA4GA1UECgwHc3VueWFyZDEQMA4GA1UECwwHU00yVGVzdDEQMA4GA1UEAwwHU00yVGVzdDBZMBMGByqGSM49AgEGCCqBHM9VAYItA0IABJLNr8XSXI2UFvhoW5vBZMJUAyjzBaPR+0klKxVxwwKodFdH3iNrRjNf7Zj6ye8rP8TqKzHu9+zc1Wm3/DBPeiGjgYkwgYYwGwYDVR0jBBQwEoAQ+X9VtCeUM2KmVspvzF0a/zAZBgNVHQ4EEgQQK7bhyJnGBrfCV6cWZnJQJDAxBggrBgEFBQcBAQQlMCMwIQYIKwYBBQUHMAGGFWh0dHBzOi8vb2NzcC5nbXNzbC5jbjAJBgNVHRMEAjAAMA4GA1UdDwEB/wQEAwIAwDAMBggqgRzPVQGDdQUAA0cAMEQCIAHfg+kXDY0hwKtcFh4QBrI+C+96RPc5HuT8ls9Ribd2AiB4jFCV7CSa3aBscynS5LHEM1UNX9BxwMs9gtHUkDjLlDGBwjCBvwIBATBVMEsxCzAJBgNVBAYTAkNOMQ4wDAYDVQQKEwVHTVNTTDEQMA4GA1UECxMHUEtJL1NNMjEaMBgGA1UEAxMRTWlkZGxlQ0EgZm9yIFRlc3QCBgGKaA2T3TAMBggqgRzPVQGDEQUAMA0GCSqBHM9VAYItAQUABEYwRAIgEeWxsmL+TZFsDJkNAtOt572P+V53WZoPN9ppDcleOSECIHSuoF0zEUV8EPHS3omE9mvUuVMoO4E6vIWuwGTGurN4";
|
||||
|
||||
System.out.println(Util.bytes2HexString(Util.decodeBase64(aa)));
|
||||
|
||||
|
||||
// //数字信封
|
||||
// RetWrap genSM2 = api.generateDEByDn( SM2dn2, orgData);
|
||||
// byte[] cipherKey = (byte[]) genSM2.get(SydApi.RET_CIPHER_KEY);
|
||||
// System.out.println("SM2数字信封: " + new String(cipherKey));
|
||||
// RetWrap denSM2 = api.decryptDEByDN( SM2dn2, cipherKey);
|
||||
// byte[] oData = (byte[]) denSM2.get("oData");
|
||||
// System.out.println("SM2信封解密:"+Util.bytes2HexString(oData));
|
||||
//
|
||||
//
|
||||
// String aa ="MEUCIQD3ZW+ReFjSbkPx2SEm3R8SwC4ke8ZllgGJBXEp8aSJsAIgUUEVqWQtbDPitbJQec5+71gCU3e3OBNwdL0EYoKId4k=";
|
||||
// String oData2 ="test123";
|
||||
// boolean nakedVerify2 = api.SYD_NakedVerify(oData2.getBytes(), Util.decodeBase64(aa), SM2dn);
|
||||
// System.out.println("SM2数据验签:"+nakedVerify2 );
|
||||
|
||||
|
||||
// String certByDn = api.getCertByDn(SM2dn2, 0);
|
||||
// System.out.println(certByDn);
|
||||
//
|
||||
// Pattern pattern = Pattern.compile("-----BEGIN CERTIFICATE-----|-----END CERTIFICATE-----");
|
||||
// Matcher matcher = pattern.matcher(certByDn);
|
||||
// String dealCert = matcher.replaceAll("").trim();
|
||||
// System.out.println(dealCert);
|
||||
|
||||
|
||||
}catch (SydApiException e){
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user