20M 数字信封支持
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import org.junit.After;
|
||||
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[ 20 * 1024 * 1024 ];
|
||||
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);
|
||||
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");
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println( "耗时=" + ( end - start ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,11 +6,15 @@ 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;
|
||||
|
||||
/**
|
||||
* 衡泰例子
|
||||
@@ -22,8 +26,8 @@ public class TestHT {
|
||||
@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);
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -53,9 +57,11 @@ public class TestHT {
|
||||
@Test
|
||||
public void testDecryptDE5Soft1() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String oData = "00001111222233";
|
||||
byte[] test = new byte[ 4 * 1024 ];
|
||||
Arrays.fill( test, (byte) 0x30 );
|
||||
String oData = new String(test);
|
||||
|
||||
RetWrap retWrap = api.generateDEByDnSoft(dn, oData);
|
||||
RetWrap retWrap = api.generateDEByDn(dn, oData);
|
||||
String cipherKey = (String) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
System.out.println("数字信封: " + cipherKey);
|
||||
|
||||
@@ -66,17 +72,67 @@ public class TestHT {
|
||||
@Test
|
||||
public void testDecryptDE5Soft2() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String oData = "00001111222233";
|
||||
String oData = "00001111222233000011112222330000111122223300001111222233000011112222330000111122223300001111222233";
|
||||
|
||||
RetWrap retWrap = api.generateDEByDn(dn, oData);
|
||||
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);
|
||||
System.out.println("原数据: " + retWrap1.get("oData"));
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 测试通过
|
||||
// 73
|
||||
|
||||
@@ -45,38 +45,38 @@ public class SydCmsUtilTest {
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
// 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();
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user