DN reverse bug fix
This commit is contained in:
@@ -22,16 +22,11 @@ public class ShangTest {
|
||||
}
|
||||
|
||||
public void action(){
|
||||
String sign = api.attachedSign(testData, dn);
|
||||
byte[] sign = api.attachedSign(testData, dn);
|
||||
boolean ret = api.attachedVerify( sign );
|
||||
|
||||
assert ret;
|
||||
|
||||
sign = api.SYD_DetachedSign(testData, dn);
|
||||
ret = api.SYD_DetachedVerify( testData, sign );
|
||||
|
||||
assert ret;
|
||||
|
||||
}
|
||||
|
||||
public void end(){
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,17 +4,13 @@ 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.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
/**
|
||||
* 衡泰例子
|
||||
@@ -26,7 +22,7 @@ public class TestHT {
|
||||
@Before
|
||||
public void before() {
|
||||
// 通过设置debug的属性开启debug,如果不设置则默认不打开
|
||||
// System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
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);
|
||||
}
|
||||
@@ -40,97 +36,35 @@ public class TestHT {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 流程演示
|
||||
*/
|
||||
@Test
|
||||
public void testDecryptDE5() throws UnsupportedEncodingException {
|
||||
public void testProcess() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String oData = "00001111222233";
|
||||
byte[] orgData = "111111213323143243243".getBytes("UTF-8");
|
||||
|
||||
RetWrap retWrap = api.generateDEByDn(dn, oData);
|
||||
String cipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
System.out.println("数字信封: " + cipherKey);
|
||||
// 签名
|
||||
byte[] sign = api.attachedSign(orgData, dn);
|
||||
System.out.println("签名结果: " + Util.bytes2HexString(sign) );
|
||||
|
||||
// 生成数字信封
|
||||
RetWrap retWrap = api.generateDEByDn(dn, sign);
|
||||
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"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptDE5Soft1() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] test = new byte[ 4 * 1024 ];
|
||||
Arrays.fill( test, (byte) 0x30 );
|
||||
String oData = new String(test);
|
||||
|
||||
RetWrap retWrap = api.generateDEByDn(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"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptDE5Soft2() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String oData = "00001111222233000011112222330000111122223300001111222233000011112222330000111122223300001111222233";
|
||||
|
||||
RetWrap retWrap = api.generateDEByDnHsm(dn, oData);
|
||||
String cipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
System.out.println("数字信封: " + cipherKey);
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDNSoft(dn, cipherKey);
|
||||
byte[] cat = (byte[]) retWrap1.get("oData");
|
||||
System.out.println("原数据: " + new String( cat ));
|
||||
|
||||
Assert.assertEquals( oData, new String( cat ));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecryptDE5Soft3() throws UnsupportedEncodingException {
|
||||
|
||||
long t1 = System.currentTimeMillis();
|
||||
System.out.println("start");
|
||||
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
byte[] aData = new byte[ 20 * 1024 * 1024 ];
|
||||
Arrays.fill( aData, (byte) 0x55 );
|
||||
|
||||
String oData = new String( aData );
|
||||
RetWrap retWrap = api.generateDEByDnSoft(dn, oData);
|
||||
String cipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
System.out.println("数字信封: " + cipherKey);
|
||||
write("./cms.p7", cipherKey.getBytes());
|
||||
long t2 = System.currentTimeMillis();
|
||||
System.out.println("加密耗时=" + ( t2 - t1 ));
|
||||
|
||||
RetWrap retWrap1 = api.decryptDEByDNSoft(dn, cipherKey);
|
||||
byte[] cat = (byte[]) retWrap1.get("oData");
|
||||
System.out.println("原数据: " + new String( cat ));
|
||||
long t3 = System.currentTimeMillis();
|
||||
System.out.println("解密耗时=" + ( t3 - t2 ));
|
||||
System.out.println("总耗时=" + ( t3 - t1 ));
|
||||
|
||||
Assert.assertEquals( oData, new String( cat ));
|
||||
}
|
||||
|
||||
public static void write(String path, byte[] data){
|
||||
try {
|
||||
File f = new File( path );
|
||||
if ( f.exists() ) {
|
||||
f.createNewFile();
|
||||
}
|
||||
FileOutputStream out = new FileOutputStream( f );
|
||||
try {
|
||||
out.write( data );
|
||||
out.flush();
|
||||
out.close();
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
}catch ( Exception e ){
|
||||
e.printStackTrace();
|
||||
// 验签
|
||||
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"))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
@@ -139,8 +73,8 @@ public class TestHT {
|
||||
@Test
|
||||
public void testSM2ConfirmSessionKeyC() {
|
||||
|
||||
String userId = "1111111111111151";
|
||||
String data = "12343242";
|
||||
String userId = "8012";
|
||||
byte[] data = "12343242".getBytes();
|
||||
|
||||
// 通过用户id获取公钥
|
||||
String pk = api.SM2GetPublicKeyC(userId, SydApi.FOR_ENCRYPT);
|
||||
@@ -153,7 +87,7 @@ public class TestHT {
|
||||
String kcv = (String) retWrap.get(SydApi.RET_KCV);
|
||||
|
||||
// 使用生成的对称密钥加密数据
|
||||
byte[] dataEnc = api.SYMEncryptData(SydApi.NALG_SM4, sessionKey, data.getBytes());
|
||||
byte[] dataEnc = api.SYMEncryptData(SydApi.NALG_SM4, sessionKey, data);
|
||||
|
||||
// 解密数字信封
|
||||
RetWrap retWrap1 = api.SM2ConfirmSessionKeyC(userId, cipherKey);
|
||||
@@ -172,8 +106,8 @@ public class TestHT {
|
||||
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);
|
||||
byte[] sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + Util.bytes2HexString(sign) );
|
||||
|
||||
boolean verify = api.attachedVerify(sign);
|
||||
System.out.println("验签结果: " + verify);
|
||||
@@ -182,9 +116,9 @@ public class TestHT {
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyGetX509() {
|
||||
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[] orgData = "111111213323143243243".getBytes();
|
||||
byte[] sign = api.attachedSign(orgData, dn);
|
||||
System.out.println("签名结果: " + Util.bytes2HexString(sign) );
|
||||
|
||||
X509 verify = api.attachedVerifyAndGetX509(sign);
|
||||
System.out.println("验签结果: " + Util.bytes2HexString(verify.getPubKey()));
|
||||
@@ -194,19 +128,19 @@ public class TestHT {
|
||||
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[] sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + Util.bytes2HexString(sign));
|
||||
|
||||
String verify = api.attachedVerifyRD(sign);
|
||||
System.out.println("验签结果: " + verify);
|
||||
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";
|
||||
String orgData = "111111213323143243243";
|
||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
byte[] orgData = "111111213323143243243".getBytes();
|
||||
byte[] sign = api.attachedSign(orgData, dn);
|
||||
System.out.println("签名结果: " + Util.bytes2HexString(sign));
|
||||
|
||||
RetWrap verify = api.attachedVerifyAndGetAll(sign);
|
||||
if (verify != null) {
|
||||
@@ -215,49 +149,68 @@ public class TestHT {
|
||||
}
|
||||
}
|
||||
|
||||
@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 getCert(){
|
||||
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";
|
||||
String cert = api.GetX509CertFileBySN("1111111111111151", SydApi.FOR_ENCRYPT );
|
||||
System.out.println( cert );
|
||||
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 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 流程演示
|
||||
*/
|
||||
@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
|
||||
@@ -271,6 +224,7 @@ public class TestHT {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// =============================工具方法==============================================
|
||||
|
||||
public static void printRetWrap(RetWrap rw) {
|
||||
|
||||
@@ -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");
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -28,8 +28,8 @@ public class SydCmsUtilTest {
|
||||
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);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user