1、添加签名验签接口,外部hash不带公钥。2、修改dproto依赖的版本
This commit is contained in:
parent
3ed89ebbe1
commit
45db61b1cd
Binary file not shown.
2
pom.xml
2
pom.xml
@ -77,7 +77,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sunyard</groupId>
|
<groupId>com.sunyard</groupId>
|
||||||
<artifactId>dproto</artifactId>
|
<artifactId>dproto</artifactId>
|
||||||
<version>1.0-20210526</version>
|
<version>1.0-20211220</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@ -228,6 +228,24 @@ interface SydDetachedSVApi {
|
|||||||
String publicKey,
|
String publicKey,
|
||||||
String sign);
|
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);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -174,6 +174,7 @@ public class SydApi4j implements SydApi {
|
|||||||
data.put("privateKey", privateKey);
|
data.put("privateKey", privateKey);
|
||||||
data.put("publicKey", publicKey);
|
data.put("publicKey", publicKey);
|
||||||
data.put("infoData", orgData);
|
data.put("infoData", orgData);
|
||||||
|
data.put("hashData", orgData);
|
||||||
data.put("privateKeyTag", "999999999999999999999999999");
|
data.put("privateKeyTag", "999999999999999999999999999");
|
||||||
|
|
||||||
// 渲染发送
|
// 渲染发送
|
||||||
@ -330,7 +331,7 @@ public class SydApi4j implements SydApi {
|
|||||||
//ProtocolRender render = pset.getProtocolReqRender("75");
|
//ProtocolRender render = pset.getProtocolReqRender("75");
|
||||||
Proto75 proto = new Proto75();
|
Proto75 proto = new Proto75();
|
||||||
|
|
||||||
byte[] sign = Util.decodeBase64(base64Sign);
|
byte[] sign = SYMUtil.base64SignAsDerSign(base64Sign);
|
||||||
|
|
||||||
// 填充数据
|
// 填充数据
|
||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
@ -597,6 +598,18 @@ public class SydApi4j implements SydApi {
|
|||||||
return detachedVerify(DATA_HASH, hash, sign);
|
return detachedVerify(DATA_HASH, hash, sign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String sm3WithoutPKDetachedSign(byte[] orgData, String sCertDN) {
|
||||||
|
byte[] hash = SM3Hash(orgData);
|
||||||
|
return detachedSign(DATA_HASH, hash, sCertDN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean sm3WithoutPKDetachedVerify(byte[] orgData, String sign) {
|
||||||
|
byte[] hash = SM3Hash(orgData);
|
||||||
|
return detachedVerify(DATA_HASH, hash, sign);
|
||||||
|
}
|
||||||
|
|
||||||
// 测试通过
|
// 测试通过
|
||||||
@Override
|
@Override
|
||||||
public String detachedSign(int dataType, byte[] orgData, String sCertDN) {
|
public String detachedSign(int dataType, byte[] orgData, String sCertDN) {
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import racal.sunyard.main.SydApi4j;
|
|||||||
import racal.sunyard.main.SydApiBuilder;
|
import racal.sunyard.main.SydApiBuilder;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
import static com.sunyard.sydapi.util.PrintUtil.printByteArray;
|
import static com.sunyard.sydapi.util.PrintUtil.printByteArray;
|
||||||
import static com.sunyard.sydapi.util.PrintUtil.printRetWrap;
|
import static com.sunyard.sydapi.util.PrintUtil.printRetWrap;
|
||||||
@ -29,7 +30,8 @@ public class TestAllMethods {
|
|||||||
public void before() {
|
public void before() {
|
||||||
// 通过设置debug的属性开启debug,如果不设置则默认不打开
|
// 通过设置debug的属性开启debug,如果不设置则默认不打开
|
||||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||||
api = (SydApi4j) new SydApi4j().connect("192.168.0.100", 8889, null, 1000);
|
api = (SydApi4j) new SydApi4j().connect("192.168.0.66", 8889, null, 1000);
|
||||||
|
// api = (SydApi4j) new SydApi4j().connect("192.168.0.100", 8889, null, 1000);
|
||||||
// api = (SydApi4j) new SydApi4j().connect("172.16.17.162", 8889, null, 1000);
|
// api = (SydApi4j) new SydApi4j().connect("172.16.17.162", 8889, null, 1000);
|
||||||
// api = (SydApi4j) new SydApi4j().connect("192.168.1.7", 8889, null, 5000);
|
// api = (SydApi4j) new SydApi4j().connect("192.168.1.7", 8889, null, 5000);
|
||||||
}
|
}
|
||||||
@ -984,16 +986,20 @@ public class TestAllMethods {
|
|||||||
printRetWrap(retWrap1);
|
printRetWrap(retWrap1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 74
|
|
||||||
@Test
|
|
||||||
public void testSYD_SM2_Sign_HA() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 75
|
// 75
|
||||||
@Test
|
@Test
|
||||||
public void testSYD_SM2_Verify_HA() {
|
public void testSYD_SM2_Verify_HA() {
|
||||||
|
String orgData = "11111111111111";
|
||||||
|
String pk="034200044BDBCE365B5DB87799EBBB78D871BEEA70A6B3BAAA2973FEDC4BF067F8F1D2A977D2BFA01562E9554F600FBBFCD0D04F50603FB225ABBEDE0DF346E5E4882F68";
|
||||||
|
String sk="00010000B3A7643171ABFC00D30307025B2CC5826F20210F5112F5D4BE7A8E32C82067C00000000000000000000000000000000000000000000000000000000000000000";
|
||||||
|
|
||||||
|
byte[] oData = api.SM3Hash(pk, Util.hexString2Bytes(orgData));
|
||||||
|
String s = api.SYD_SM2_Sign_HA(SydApi.DATA_HASH, Util.hexString2Bytes(sk), Util.hexString2Bytes(pk), oData);
|
||||||
|
|
||||||
|
System.out.println("decBase64:" + Util.bytes2HexString(Util.decodeBase64(s)));
|
||||||
|
System.out.println("decBase64-1:" + Util.bytes2HexString(SYMUtil.base64SignAsDerSign(s)));
|
||||||
|
boolean b = api.SYD_SM2_Verify_HA(SydApi.DATA_HASH, Util.hexString2Bytes(pk), Util.hexString2Bytes(orgData), s);
|
||||||
|
System.out.println("验签结果: " + b);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 测试通过
|
// 测试通过
|
||||||
@ -1491,12 +1497,13 @@ public class TestAllMethods {
|
|||||||
@Test
|
@Test
|
||||||
public void testSM2Verify3() {
|
public void testSM2Verify3() {
|
||||||
|
|
||||||
String thisPublicKey = "0342000422C4FC907E0BEC600C2070D675EFB65EAE3A628260FF5461DD5F8133CF7CF98530EF392D016B6487BA6148E9AC27BDD4E8D7404A310CB09335F50AEF00ADB068";
|
String thisPublicKey = "03420004C0D7FCD41C4A27B6B2DAC20B1332ED89202F2F85EF79929CAD1028F11AE0E8EFECA9C26A2145773F234631B2D2F1C7DAE5880C681122B28DA842509CEC8DF82D";
|
||||||
String thisOrgData = "FFFFFFFFFFFFFFFF";
|
String thisOrgData = "FFFFFFFFFFFFFFFF";
|
||||||
|
|
||||||
String s = api.SM2SignC(1, "111111111111114700000000001", Util.hexString2Bytes(thisPublicKey), thisOrgData.getBytes());
|
String s = api.SM2SignC(1, "000000000000000100000000001", Util.hexString2Bytes(thisPublicKey), thisOrgData.getBytes());
|
||||||
|
|
||||||
System.out.println(s);
|
System.out.println(s);
|
||||||
|
System.out.println("DecBase64:" + Util.bytes2HexString(Base64.getDecoder().decode(s)));
|
||||||
boolean b = api.SM2Verify( Util.hexString2Bytes(thisPublicKey), thisOrgData.getBytes(), s);
|
boolean b = api.SM2Verify( Util.hexString2Bytes(thisPublicKey), thisOrgData.getBytes(), s);
|
||||||
System.out.println(b);
|
System.out.println(b);
|
||||||
}
|
}
|
||||||
@ -1599,7 +1606,7 @@ public class TestAllMethods {
|
|||||||
String orgData = "3214312341243214";
|
String orgData = "3214312341243214";
|
||||||
String DN = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
String DN = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||||
String sign = api.SYD_DetachedSign(orgData.getBytes(), DN);
|
String sign = api.SYD_DetachedSign(orgData.getBytes(), DN);
|
||||||
System.out.println("签名结果" + sign);
|
System.out.println("签名结果: " + sign);
|
||||||
|
|
||||||
boolean b = api.SYD_DetachedVerify(orgData.getBytes(), sign);
|
boolean b = api.SYD_DetachedVerify(orgData.getBytes(), sign);
|
||||||
System.out.println("验签结果:" + b);
|
System.out.println("验签结果:" + b);
|
||||||
@ -1649,11 +1656,12 @@ public class TestAllMethods {
|
|||||||
// 8005
|
// 8005
|
||||||
@Test
|
@Test
|
||||||
public void testDetachedSign() {
|
public void testDetachedSign() {
|
||||||
String publicKey = "0342000469DE3847DD6A66DA96DB8F2DCFA32E10E680FF2EF4A592079E7C3A44320BB15084E7CA9782A39B6E28F07C04FE00D68958A2605921E71712D56C1E4435A39FA5";
|
String publicKey = "034200043EDA3A107B7CC35CC005C7FBF0BB4E6B43A07EE14E360603D22ECA2A600B2D0FA03055D400D1240300F54648B849D13F50B330FF14351B5645B13686820A65BB";
|
||||||
String orgData = "FFFFFFFFFFFFFFFF";
|
String orgData = "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101";
|
||||||
String testCertNo = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
String testCertNo = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||||
|
|
||||||
byte[] hash = api.SM3Hash(publicKey, orgData.getBytes());
|
byte[] hash = api.SM3Hash(publicKey, Util.hexString2Bytes(orgData));
|
||||||
|
System.out.println("hash:" + hash);
|
||||||
|
|
||||||
String sign = api.detachedSign(
|
String sign = api.detachedSign(
|
||||||
SydApi.DATA_HASH,
|
SydApi.DATA_HASH,
|
||||||
@ -1687,6 +1695,20 @@ public class TestAllMethods {
|
|||||||
System.out.println("验签结果:" + b);
|
System.out.println("验签结果:" + b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 测试通过
|
||||||
|
// 8005
|
||||||
|
@Test
|
||||||
|
public void testSm3WithoutPKDetachedSign() {
|
||||||
|
String orgData = "FFFFFFFFFFFFFFFF";
|
||||||
|
String testCertNo = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||||
|
|
||||||
|
String sign = api.sm3WithoutPKDetachedSign(orgData.getBytes(), testCertNo);
|
||||||
|
System.out.println("签名结果: " + sign);
|
||||||
|
|
||||||
|
boolean b = api.sm3WithoutPKDetachedVerify(orgData.getBytes(), sign);
|
||||||
|
System.out.println("验签结果:" + b);
|
||||||
|
}
|
||||||
|
|
||||||
// 8026
|
// 8026
|
||||||
@Test
|
@Test
|
||||||
public void testDetachedSignbysn() {
|
public void testDetachedSignbysn() {
|
||||||
|
|||||||
@ -618,9 +618,10 @@ public class TestLast {
|
|||||||
//16.6 SM2公钥验签(+)->pass (仅签名数据类型为原数据通过)
|
//16.6 SM2公钥验签(+)->pass (仅签名数据类型为原数据通过)
|
||||||
@Test
|
@Test
|
||||||
public void SYD_SM2_Verify_HA() {
|
public void SYD_SM2_Verify_HA() {
|
||||||
RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "006", 256);
|
RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "007", 256);
|
||||||
String s = api.SYD_SM2_Sign_HA(1, (byte[]) retWrap.get("PrivateKey"), (byte[]) retWrap.get("PublicKey"), key7.getBytes());
|
String s = api.SYD_SM2_Sign_HA(1, (byte[]) retWrap.get("PrivateKey"), (byte[]) retWrap.get("PublicKey"), key7.getBytes());
|
||||||
System.out.println(s);
|
System.out.println(s);
|
||||||
|
System.out.println( Util.bytes2HexString( Util.decodeBase64(s) ) );
|
||||||
boolean b = api.SYD_SM2_Verify_HA(1, (byte[]) retWrap.get("PublicKey"), key7.getBytes(), s);
|
boolean b = api.SYD_SM2_Verify_HA(1, (byte[]) retWrap.get("PublicKey"), key7.getBytes(), s);
|
||||||
System.out.println(b);
|
System.out.println(b);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user