p1 验签 hash 数据 bug
This commit is contained in:
parent
f90276218c
commit
6b94ddaab4
@ -3822,6 +3822,7 @@ public class SydApi4j implements SydApi {
|
|||||||
data.put("signature", sign);
|
data.put("signature", sign);
|
||||||
data.put("userId", certNo.getBytes());
|
data.put("userId", certNo.getBytes());
|
||||||
data.put("infoData", orgData);
|
data.put("infoData", orgData);
|
||||||
|
data.put("hashData", orgData);
|
||||||
data.put("publicKey", publicKey);
|
data.put("publicKey", publicKey);
|
||||||
// 渲染发送
|
// 渲染发送
|
||||||
ByteBuffer bb = proto.rend(packet);
|
ByteBuffer bb = proto.rend(packet);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package com.sunyard.sydapi.sample;
|
package com.sunyard.sydapi.test;
|
||||||
|
|
||||||
|
|
||||||
import com.sunyard.SydApi;
|
import com.sunyard.SydApi;
|
||||||
@ -8,6 +8,7 @@ import racal.sunyard.main.SydApi4j;
|
|||||||
|
|
||||||
public class TestPKCS1 {
|
public class TestPKCS1 {
|
||||||
|
|
||||||
|
private static final String testId = "8012";
|
||||||
private static final String testData = "1234567812345678";
|
private static final String testData = "1234567812345678";
|
||||||
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=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||||
|
|
||||||
@ -15,13 +16,16 @@ public class TestPKCS1 {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
// 连接加密机
|
// 连接加密机
|
||||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.0.100", 8889, null, 1000);
|
SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.0.200", 8889, null, 1000);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// 原始数据模式
|
// 原始数据模式
|
||||||
case1(api);
|
// case1( api );
|
||||||
|
|
||||||
|
// 外部 hash
|
||||||
|
case2( api );
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -31,8 +35,9 @@ public class TestPKCS1 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void case1(SydApi api) {
|
|
||||||
// 签名验签 1
|
// 签名验签 1
|
||||||
|
public static void case1(SydApi api) {
|
||||||
|
|
||||||
System.out.println("\n\n----- 裸签名 -----");
|
System.out.println("\n\n----- 裸签名 -----");
|
||||||
byte[] sign = api.SYD_NakedSign(testData.getBytes(), testCertNo);
|
byte[] sign = api.SYD_NakedSign(testData.getBytes(), testCertNo);
|
||||||
System.out.println("签名结果 " + Util.bytes2HexString(sign) );
|
System.out.println("签名结果 " + Util.bytes2HexString(sign) );
|
||||||
@ -42,12 +47,20 @@ public class TestPKCS1 {
|
|||||||
System.out.println("验签结果 " + pass);
|
System.out.println("验签结果 " + pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 签名验签 2
|
||||||
public static void case2(SydApi api) {
|
public static void case2(SydApi api) {
|
||||||
byte[] sign = api.SYD_NakedSign(testData.getBytes(), testCertNo);
|
|
||||||
|
String pk = api.SM2GetPublicKeyC( testId ,0);
|
||||||
|
|
||||||
|
System.out.println( pk );
|
||||||
|
|
||||||
|
byte[] data = api.SM3Hash( Util.hexString2Bytes(pk) );
|
||||||
|
|
||||||
|
byte[] sign = api.SYD_NakedSign(data, testCertNo);
|
||||||
System.out.println("签名结果 " + Util.bytes2HexString(sign) );
|
System.out.println("签名结果 " + Util.bytes2HexString(sign) );
|
||||||
|
|
||||||
|
|
||||||
boolean pass = api.SYD_NakedVerify(testData.getBytes(), sign, testCertNo);
|
boolean pass = api.SYD_NakedVerify(data, sign, testCertNo);
|
||||||
System.out.println("验签结果 " + pass);
|
System.out.println("验签结果 " + pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user