添加单元测试
This commit is contained in:
parent
7d0aebad53
commit
772458254e
@ -73,5 +73,5 @@ public interface SydHashApi {
|
||||
|
||||
public RetWrap countHash(int hashType, int packSn, byte[] msg, byte[] filterData);
|
||||
|
||||
public byte[] hash(int hashType, byte[] orgData);
|
||||
public byte[] itHash(int hashType, byte[] orgData);
|
||||
}
|
||||
|
||||
@ -915,7 +915,7 @@ public class SydApi4j implements SydApi {
|
||||
deVerify= detachedVerify(rFlag,dataType,orgData,sign);
|
||||
}else {
|
||||
//RetWrap hashData = countHash(0, 0, orgData, null);
|
||||
byte[] hashData = hash(0, orgData);
|
||||
byte[] hashData = itHash(0, orgData);
|
||||
deVerify= this.detachedVerify(2, 0, hashData, sign);
|
||||
}
|
||||
return deVerify;
|
||||
@ -1114,7 +1114,7 @@ public class SydApi4j implements SydApi {
|
||||
sign = detachedSign(rFlag,dataType,orgData,sCertDN);
|
||||
}else{
|
||||
// RetWrap hashData = countHash(0, 0, orgData, null);
|
||||
byte[] hash = hash(0, orgData);
|
||||
byte[] hash = itHash(0, orgData);
|
||||
sign = detachedSign(2,0, hash, sCertDN);
|
||||
}
|
||||
return sign;
|
||||
@ -9174,7 +9174,7 @@ public class SydApi4j implements SydApi {
|
||||
@param hashType HASH类型。0: SHA1,1: SHA256,2: MD5
|
||||
@param orgData 原始数据
|
||||
*/
|
||||
public byte[] hash(int hashType, byte[] orgData) {
|
||||
public byte[] itHash(int hashType, byte[] orgData) {
|
||||
byte[] hashData = new byte[0];
|
||||
final int packLen = 4064;
|
||||
// 如果长度小于等于 4064 ,发送唯一包
|
||||
@ -11666,7 +11666,7 @@ public class SydApi4j implements SydApi {
|
||||
verifyRSA= this.detachedVerify(rFlag, 1, orgData, sign2);
|
||||
}else {
|
||||
// RetWrap hashData = this.countHash(0, 0, orgData, null);
|
||||
byte[] hashData = hash(0, orgData);
|
||||
byte[] hashData = itHash(0, orgData);
|
||||
verifyRSA= this.detachedVerify(2, 0, hashData, sign2);
|
||||
}
|
||||
return verifyRSA;
|
||||
@ -11714,7 +11714,7 @@ public class SydApi4j implements SydApi {
|
||||
try {
|
||||
// RetWrap hashData = countHash(0, 0, orgData, null);
|
||||
// byte[] hash = (byte[]) hashData.get("hash");
|
||||
byte[] hash = hash(0, orgData);
|
||||
byte[] hash = itHash(0, orgData);
|
||||
String sign = this.detachedSign(2,0, hash, sCertDN);
|
||||
return ASN1Util.addOriginDataToPKCS7Sign( orgData, sign );
|
||||
} catch (IOException e) {
|
||||
|
||||
48
src/test/java/HashTest.java
Normal file
48
src/test/java/HashTest.java
Normal file
@ -0,0 +1,48 @@
|
||||
import com.sunyard.SydApi;
|
||||
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 = "192.168.1.197";
|
||||
// private static final String dn = "/C=cn/O=CFCA TEST CA/OU=CIPSTEST/OU=Units/CN=041@3CIPSCNSHCLR@CN000000129@00000017";
|
||||
// private static final String ip = "192.168.1.129";
|
||||
private static final String ip = "172.16.17.161";
|
||||
// private static final String dn = "C=cn,O=CFCA TEST CA,OU=CIPSTEST,OU=Units,CN=041@3PBOCCNSFCFX@CN000000129@00000003";//"C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
// private static final String dn = "C=cn,O=CFCA TEST CA,OU=CIPSTEST,OU=Units,CN=041@3CIPSCNSHCLR@CN000000129@00000022";
|
||||
private static final String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
private static final String rsa = "C=CN,O=sunyard,OU=rsa,CN=javaRsa";
|
||||
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 ]);
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class SM3Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SydApi api = new SydApi4j().connect("192.168.0.100", 8889, null, 1000);
|
||||
try {
|
||||
byte[] data = api.SM3Hash("test".getBytes(StandardCharsets.UTF_8));
|
||||
System.out.println("hex=" + Util.bytes2HexString(data));
|
||||
}catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user