p7 证书相关
This commit is contained in:
@@ -4,15 +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.Before;
|
||||
import org.junit.Test;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Base64;
|
||||
|
||||
import static com.sunyard.sydapi.util.PrintUtil.printRetWrap;
|
||||
|
||||
/**
|
||||
* 衡泰例子
|
||||
@@ -25,7 +23,7 @@ public class TestHT {
|
||||
public void before() {
|
||||
// 通过设置debug的属性开启debug,如果不设置则默认不打开
|
||||
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.200", 8889, null, 1000);
|
||||
// api = (SydApi4j) new SydApi4j().connect("192.168.0.66", 8889, null, 1000);
|
||||
}
|
||||
|
||||
@@ -39,6 +37,46 @@ public class TestHT {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecryptDE5() throws UnsupportedEncodingException {
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String oData = "00001111222233";
|
||||
|
||||
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 testDecryptDE5Soft1() throws UnsupportedEncodingException {
|
||||
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"));
|
||||
}
|
||||
|
||||
@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";
|
||||
|
||||
RetWrap retWrap = api.generateDEByDn(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"));
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 测试通过
|
||||
// 73
|
||||
@@ -121,19 +159,19 @@ public class TestHT {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecryptDE5() throws UnsupportedEncodingException {
|
||||
public void getCert(){
|
||||
String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
String oData = "00001111222233";
|
||||
|
||||
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"));
|
||||
String cert = api.GetX509CertFileBySN("1111111111111151", SydApi.FOR_ENCRYPT );
|
||||
System.out.println( cert );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 流程演示
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.sunyard.sydapi.util;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import org.bouncycastle.asn1.cms.ContentInfo;
|
||||
import org.bouncycastle.cms.SydCmsUtil;
|
||||
|
||||
import org.bouncycastle.asn1.ASN1Sequence;
|
||||
import org.bouncycastle.asn1.ASN1Set;
|
||||
import org.bouncycastle.asn1.ASN1TaggedObject;
|
||||
import org.bouncycastle.asn1.DEROctetString;
|
||||
import org.bouncycastle.asn1.cms.ContentInfo;
|
||||
import org.bouncycastle.cms.SydCmsUtil;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
import org.junit.Test;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
|
||||
public class SydCmsUtilTest {
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user