init files
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
package com.sunyard.sydapi.sample;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ASYMEnDeTest {
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
|
||||
System.out.println("非对称密钥加解密");
|
||||
byte[] testData = new byte[100];
|
||||
Arrays.fill(testData, (byte) 0x88);
|
||||
|
||||
SydApi4j api = (SydApi4j) new SydApiBuilder()
|
||||
.setIp("172.16.17.161")
|
||||
.useDebugMode()
|
||||
.build();
|
||||
|
||||
|
||||
RetWrap ret;
|
||||
try {
|
||||
|
||||
String rsaPk = "308189028181009AF6135A23B634E6DFE6AC1BC5E18FAAC5A4287D433C81CB520615DBD386822A20328EF064D16D4AA0ED97056BF6F387D2922834C9DAFF3BFDC5666F280EF187102A47A2CDB45E5BBE66E1F28E88335B880A7BBC5E56FCA9F460C4F2EE034393ED5258D801DC252268FE0A7A36DDFA823C133148D634E560FA3C526E18093B3D0203010001";
|
||||
String rsaSk = "0004000096E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D6429CED6878A26E7DA37C6D6E3CC99DF92CFB6208B239A6F6D452F70961413C86ABABBB97905F4D8416125D6705006E0CBBE2A55C21C5021D6D4BA6357574DAEA872F744343497FC301A0072DCB5AFFADE4E38618CF193B417465D51F55E7A05143EF22ED52B15C3D7EAB07A83442F7AA0FE0864D6FA656D35A3F8F78EE76E0623396E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D6424759813A8629F2E496E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D6429C90258F09582794C56F6F811DD07E128A0D8EF28DD2A159CBC0F638D0D1ED316BF916A04BC5AB62B95826F2387D1342EA33779526A1909FCAEB67DB6C8F1BB8550544087407462997852081DDAA22AB072EBB204A911654DC8EE988BCDAA8D36433320A1FCBB1E02932119CD6B77FFD2459B1EF170FF35FF38BA957259FBB5396E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D642F13FEACF9F953255F45DB33FFA13DABC74A15EFDC5BB956C94590170BB2473B1F381564524E001284FF13325E0E123E68C5ACC3ACF396B15DFF3CF22C24D719696E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D642E8A95E58CBA24739343ECA89FDAB1C0D16C5353ECD90C364667B1B7E3B3D8698F3E0EE4874004D7100AA57E7F2778C76DE4D0E2F79B337C06DD2E407B80351DC96E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D642ECA9E92F835FAEA4AE5B73605852635FBE67D5F472BA7BE41DF94C44F472D49FAE23C3649A842C685B5CC1A5D475D8D3B46854FD28EBE9BD72921388A98BF2F196E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D642DE755DEFD7ABBDC9A95A90262084CA8E9C69123CEBF24BFC9A82114EB8E62673EA2A2BD72D321F795A2A22A4ADB5BAA42D55FC561F09D6BB0AA3518EE7BC0B8C96E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D64296E684B99F21D642487F135CC93AA0E8A97C1DA44B6706EBA95A3CCB24D9EB2E643D6B339FF7DE3983DC16C03AF3C4A22878EF976D9D2AF4549D1D9933EAC824CB32801CC4136EDF";
|
||||
|
||||
String sm2Pk = "03420004571DE0574BACC945BE003FBA94EB3FF4000BD2C64C5D81D4463099177A5E387E583DEEF7087E988E5C84E4FE19B24566A9A130D7159CE13DC8527B8341CEA3F3";
|
||||
|
||||
String sm2Sk = "00010000EBCA3A20376AAEDA2A0B607F14ADD89CE62DFF26A115FB4C987FDDDE75E78CBB0000000000000000000000000000000000000000000000000000000000000000";
|
||||
|
||||
// ret = api.SM2OrRSAGenKeyPair(1, "", 1024);
|
||||
//
|
||||
// System.out.println( ret );
|
||||
// System.out.println( Util.bytes2HexString((byte[]) ret.get("PrivateKey")) );
|
||||
// System.out.println( Util.bytes2HexString((byte[]) ret.get("PublicKey")) );
|
||||
|
||||
|
||||
byte[] enData1 = api.encryptByPk(1, sm2Pk, testData);
|
||||
System.out.println( new String(enData1) );
|
||||
|
||||
byte[] deData1 = api.decryptBySk(1, sm2Sk, enData1);
|
||||
|
||||
// deData == testData
|
||||
assert Arrays.equals( enData1, deData1 );
|
||||
System.out.println("SM2 公钥加密/私钥解密 测试通过");
|
||||
//
|
||||
//
|
||||
// byte[] enData = api.encryptByPk(0, rsaPk, testData);
|
||||
// byte[] deData = api.decryptBySk(0, rsaSk, enData);
|
||||
//
|
||||
// // deData == testData
|
||||
// assert Arrays.equals( enData, deData );
|
||||
// System.out.println("RSA 公钥加密/私钥解密 测试通过");
|
||||
|
||||
|
||||
|
||||
// byte[] enData1 = api.encryptBySk(1, sm2Sk, testData);
|
||||
// System.out.println( new String(enData1) );
|
||||
//
|
||||
// byte[] deData1 = api.decryptByPk(1, sm2Pk, enData1);
|
||||
//
|
||||
// // deData == testData
|
||||
// assert Arrays.equals( enData1, deData1 );
|
||||
// System.out.println("SM2 私钥加密/公钥解密 测试通过");
|
||||
//
|
||||
//
|
||||
// byte[] enData = api.encryptBySk(0, rsaSk, testData);
|
||||
// byte[] deData = api.decryptByPk(0, rsaPk, enData);
|
||||
//
|
||||
// // deData == testData
|
||||
// assert Arrays.equals( enData, deData );
|
||||
// System.out.println("RSA 私钥加密/公钥解密 测试通过");
|
||||
|
||||
|
||||
} finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.sunyard.sydapi.sample;
|
||||
|
||||
public class Build {
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.sunyard.sydapi.sample;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.cert.X509;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
/**
|
||||
* 密钥导入导出功能测试
|
||||
* 其实就是做 lmk2zmk(A8) 转加密和 zmk2lmk(A6) 转加密
|
||||
*/
|
||||
public class InputOutputKeyTest
|
||||
{
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
|
||||
System.out.println("密钥导入导出功能测试");
|
||||
|
||||
|
||||
SydApi api = new SydApiBuilder()
|
||||
.setIp("172.16.17.161")
|
||||
// .useDebugMode()
|
||||
// .useEBCDMode()
|
||||
// .useETEncrypt()
|
||||
.build();
|
||||
|
||||
try {
|
||||
|
||||
String keyType = "000";
|
||||
char sydSln = 'X';
|
||||
|
||||
|
||||
// 生成一个测试用的 zmk
|
||||
RetWrap ret = api.genSymmetricKey(
|
||||
"000",
|
||||
'Z'
|
||||
);
|
||||
|
||||
String zmk = new String((byte[]) ret.get("lmkKey"));
|
||||
System.out.println( "zmk=" + zmk);
|
||||
|
||||
|
||||
// 生成一个测试用的 key
|
||||
ret = api.genSymmetricKey(
|
||||
keyType,
|
||||
sydSln
|
||||
);
|
||||
|
||||
String key = new String((byte[]) ret.get("lmkKey"));
|
||||
System.out.println( "lmkKek=" + key);
|
||||
|
||||
|
||||
// 将 key 转加密输出
|
||||
ret = api.outputKey(keyType, sydSln, zmk, key);
|
||||
String key2 = new String((byte[]) ret.get("key"));
|
||||
System.out.println( "zmkKek=" + key2);
|
||||
|
||||
|
||||
// 将 key 重新导入
|
||||
ret = api.inputKey(keyType, sydSln, zmk, key2);
|
||||
String key3 = new String((byte[]) ret.get("key"));
|
||||
System.out.println( "*lmkKek=" + key3);
|
||||
|
||||
|
||||
}finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.sunyard.sydapi.sample;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
public class MACTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SydApi api = new SydApiBuilder()
|
||||
.setIp("172.16.17.162")
|
||||
// .useEBCDMode()
|
||||
.useDebugMode()
|
||||
// .useETEncrypt()
|
||||
.build();
|
||||
|
||||
|
||||
byte[] data = new byte[10];
|
||||
byte[] mac = api.MACCalc(0, 1, 0, 2, "X12345678123456781234567812345678", data);
|
||||
|
||||
System.out.println( new String( mac ) );
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package com.sunyard.sydapi.sample;
|
||||
|
||||
import com.sunyard.cert.X509;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
import sun.misc.BASE64Encoder;
|
||||
import sun.security.provider.X509Factory;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class RSAP1SignVerify {
|
||||
private static byte[] createBlock(byte type, byte[] in) {
|
||||
if (2 == type && (255 & in[0]) >= 128) {
|
||||
byte[] nin = new byte[in.length + 1];
|
||||
nin[0] = 0;
|
||||
System.arraycopy(in, 0, nin, 1, in.length);
|
||||
in = nin;
|
||||
}
|
||||
|
||||
int len = in.length;
|
||||
ByteBuffer bb;
|
||||
if (len > 128) {
|
||||
int lenLen = len / 256 + 1;
|
||||
bb = ByteBuffer.allocate(len + 1 + 1 + lenLen);
|
||||
bb.put(type);
|
||||
bb.put((byte) (128 + lenLen));
|
||||
|
||||
for (int i = 0; i < lenLen; ++i) {
|
||||
bb.put((byte) (255 & len >>> 8 * (lenLen - 1 - i)));
|
||||
}
|
||||
} else {
|
||||
bb = ByteBuffer.allocate(len + 1 + 1);
|
||||
bb.put(type);
|
||||
bb.put((byte) (255 & len));
|
||||
}
|
||||
|
||||
bb.put(in);
|
||||
return bb.array();
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SydApi4j api = (SydApi4j) new SydApiBuilder()
|
||||
.setIp("192.168.1.226")
|
||||
.useDebugMode()
|
||||
.build();
|
||||
|
||||
|
||||
try {
|
||||
//model 0:通过证书序列号去签名,以及验签
|
||||
//model 1:通过证书DN去签名,以及验签
|
||||
//model 2:通过证书实体的机构号获取到公钥,通过机构号以及公钥去签名,公钥去验签
|
||||
byte model = 2;
|
||||
switch (model) {
|
||||
case 2: {
|
||||
String cert = "-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIIEQjCCAyqgAwIBAgIFQAeZAyIwDQYJKoZIhvcNAQELBQAwXTELMAkGA1UEBhMC\n" +
|
||||
"Q04xMDAuBgNVBAoMJ0NoaW5hIEZpbmFuY2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhv\n" +
|
||||
"cml0eTEcMBoGA1UEAwwTQ0ZDQSBBQ1MgVEVTVCBPQ0EzMTAeFw0xOTEwMjgwODU4\n" +
|
||||
"NTRaFw0yNDEwMjgwODU4NTRaMGsxCzAJBgNVBAYTAkNOMRYwFAYDVQQKDA1DRkNB\n" +
|
||||
"IE9DQTMxIENBMQ4wDAYDVQQLDAVneW5zaDEZMBcGA1UECwwQT3JnYW5pemF0aW9u\n" +
|
||||
"YWwtMzEZMBcGA1UEAwwQZ3luc2g5ODEwMDAwMTE1MDCCASIwDQYJKoZIhvcNAQEB\n" +
|
||||
"BQADggEPADCCAQoCggEBANZhyVUufcUclty+zfbbrCsjePrTRlvvXjL0gprrSK6U\n" +
|
||||
"ynyzs4h76+s3MBewAvmDcemOopddC+uvX/zfKgTzyEeyrmnee936xKXHyv1SHblW\n" +
|
||||
"a4oMPR458X2o/Ej3hHzEXqj/WdUEZdx83HeaYcdhCgoHNaKcEpiqkpIjhXtIU4Ah\n" +
|
||||
"L3ciTF7Y+0NWTi17dDI17i0C681Tjya5p0Srpw4pRy1Rb0dx6zkTGGq52RLCQk4g\n" +
|
||||
"GVWvYEn4ST4DhWZXcgTOkVBMPMNS+qXxHNy6KLi3ky6x9U+10ldg1rqG7jOtWn1E\n" +
|
||||
"HqlzcIxqdqr7iO95h5a/K0bFKiVywEq/YdlxgAbH/KUCAwEAAaOB+jCB9zA/Bggr\n" +
|
||||
"BgEFBQcBAQQzMDEwLwYIKwYBBQUHMAGGI2h0dHA6Ly9vY3NwdGVzdC5jZmNhLmNv\n" +
|
||||
"bS5jbjo4MC9vY3NwMB8GA1UdIwQYMBaAFJo9tK5lWPvOWgV4JqBtKwSGusbsMAwG\n" +
|
||||
"A1UdEwEB/wQCMAAwNwYDVR0fBDAwLjAsoCqgKIYmaHR0cDovLzIxMC43NC40Mi4z\n" +
|
||||
"L09DQTMxL1JTQS9jcmw2NC5jcmwwDgYDVR0PAQH/BAQDAgbAMB0GA1UdDgQWBBTa\n" +
|
||||
"pk33a/mKcAoX27Prs1miHQgqPTAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUH\n" +
|
||||
"AwQwDQYJKoZIhvcNAQELBQADggEBAK7B11CFYLThIEEIIWG4A3BDvMiQhkeJ2jDd\n" +
|
||||
"xvc/pIH6SmIRJyOTWYxKhkBrI1AaKhOYfzsU973sK2gyLURjkatg1pTxg5v37sIo\n" +
|
||||
"BGqMe05aUF1MQlXsx+R+mes1GJcurPXeZ+Ho3DCBPo/O1uU5QHy5OU4iVOwErrOK\n" +
|
||||
"ExslrbDPFizZSes7I+y/dQcl4WkhjcSA37G/Zay6RsQuiPkHpt7dHzUGnMqF9CvW\n" +
|
||||
"6SiEvhdtSRTyqvjbJFL2bP3prUBwDD6Yi3oe5uclm/iPwy/7HLbG1oGBz0sHn+80\n" +
|
||||
"ac8jKPehg78CEgMaq1FKcl2zvorIixrjoLGYOSVthz6oABZ5MHk=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
|
||||
String signCert = "MIID6DCCAtCgAwIBAgIFJnVRuPUwDQYJKoZIhvcNAQELBQAwPTELMAkGA1UEBhMCQ04xFDAS\n" +
|
||||
"BgNVBAoMC05YWTIwNDhURVNUMRgwFgYDVQQDDA9OWFkyMDQ4Uk9PVFRFU1QwHhcNMTkwNTMw\n" +
|
||||
"MDAxNjI2WhcNMjQwNTI4MDAxNjI2WjB6MQswCQYDVQQGEwJDTjE3MDUGA1UECgwuUnVyYWwg\n" +
|
||||
"Q3JlZGl0IEJhbmtzIEZ1bmRzIENsZWFyaW5nIENlbnRlcihURVNUKTEUMBIGA1UECwwLRW50\n" +
|
||||
"ZXJwcmlzZXMxHDAaBgNVBAMMEzA2M0A2NzMzMjcwOTk5OTkwMDQwggEiMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4IBDwAwggEKAoIBAQCEEMIed7o5R2ZCPKKZrJjQ7x7hIYsAaBd5vhAhj+HyXyCPF6O6\n" +
|
||||
"3N9znR8uv+BlG2va4jIdye/rLgTGnBuuRZPEYNGvJvoTy01lFtixuInkNW1VkgEQ1CDlwW47\n" +
|
||||
"TOC5dFPYHENkSMMSiDM0BLBQsZH1p4oQzSyGVtAs9YTWQhb/nWSSXgpiz5+qmlvSrsEU+Ffy\n" +
|
||||
"1fYsN6RadZWL2Pegk8NTS/KTfbo9NCgE6jKFoPNzJ20fdK5aUR5ePI5JdnzxfrabkI9F9964\n" +
|
||||
"tlsynsOaoWY60FMmfB+HcvJoSgSI65iNRFRwkzic8mtnmdq9EIIcPgZVz7GCEp9v3Vk30T9e\n" +
|
||||
"M2/ZAgMBAAGjgbEwga4wHwYDVR0jBBgwFoAUZaX9myCvxP1gs80NCsJZtGtypMEwCQYDVR0T\n" +
|
||||
"BAIwADBUBgNVHR8ETTBLMEmgR6BFpEMwQTEOMAwGA1UEAwwFY3JsMjExDDAKBgNVBAsMA2Ny\n" +
|
||||
"bDEUMBIGA1UECgwLTlhZMjA0OFRFU1QxCzAJBgNVBAYTAkNOMAsGA1UdDwQEAwIHgDAdBgNV\n" +
|
||||
"HQ4EFgQUdhrTivJUnKI5oZ0T2OZkSEaDkIUwDQYJKoZIhvcNAQELBQADggEBACgf34fsfPvN\n" +
|
||||
"ln1Ch2Cid7jrJEw5o1AQlahxWtnJH4fzxgYldqgNpoZD3p9XOmFEIvTBHAt8wANQoCQEFJj2\n" +
|
||||
"3PZvwG4T6VXwRn05/u25fMDF4R7Z9IYlNVY5hpxtisC7u8aq7VCqHwzXsjaItuCPQbOkhTCb\n" +
|
||||
"2m4TVGbaMYXVWhEJiss31XrNZgAbKfrFEAmG6+KO5cRdfjXHooaY44sgeEd+Mi5aPyY+QNR1\n" +
|
||||
"uio39G+ur/BjHqOCIujUEI8f3g8wAQaIFyA97rAjJW1W/BVZispRg4niG0mLQ356cTGj+kkJ\n" +
|
||||
"imdxvNyhfwmMNweP6fIUnajMOtJiMomjSAdIuqdxDIw=";
|
||||
String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?><T><D><M><k>操作员:</k><v>800000783001</v></M></D><E><M><k>CifNo</k><v>800000783</v></M><M><k>LoginId</k><v>800000783001</v></M><M><k>LoginType</k><v>C</v></M><M><k>transaction</k><v>eibs.login</v></M></E></T>";
|
||||
String signatureBase64 = "CC0uWxM/YqFrPzRKqvpEDBKz5AZC2+Hp2eEWhgR+z0XR9nirrtovb8e61ahLeYywsZ5bBZgCL5lKI/YJ/mI2Nh3ntWQCXSAf8DpOD3GWkHRMfDgeiGj0F3qyTOJi7iY+wAZOFBLiOEe2P2YFCl0Luny6dfRFoBkvoxVbrrKui+8d5pusciuuwQcL+P7K0FeIPb2yjdZfm+oz+FMlq4dvSHJrnDZ3tUcS7ZzfXSHYwAm1aA5SAWNIS6ixP1pT4nwLM0W+tUdvtP1yx6q7UyZPeDaWDsTqZbLvd3Ond38jQIrPutK/ACBsg92VS2SmQDVj0C+ZrJkvjbXbRj87dn0CGw==";
|
||||
byte[] bSource = source.getBytes();
|
||||
|
||||
byte[] derCert = Util.decodeBase64(signCert);
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
cert = X509Factory.BEGIN_CERT + "\n" + encoder.encodeBuffer(derCert) + X509Factory.END_CERT;
|
||||
X509 X509Cert = api.GetX509CertInfo(cert);
|
||||
|
||||
byte[] signature = Util.decodeBase64(signatureBase64);
|
||||
byte[] signatureDer = createBlock((byte) 4, signature);
|
||||
|
||||
|
||||
// 通过传入公钥P1验签
|
||||
Boolean bRet = api.RSAVerify(0, api.DATA_ORIGIN, X509Cert.getPubKey(), bSource, signatureDer);
|
||||
System.out.println("P1验签结果:" + bRet);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
String userID = "2";
|
||||
byte[] testData = {1,2,3,45,1,2,3,45};
|
||||
// 机构号获取公钥
|
||||
String pk=api.RSAGetPublicKeyC(userID,0);
|
||||
System.out.println("PK: " + pk);
|
||||
|
||||
// 通过机构号获取私钥P1签名
|
||||
byte[] sign = api.RSASignC(userID,1,api.DATA_ORIGIN,testData);
|
||||
System.out.println( "P1签名结果: " + Util.bytes2HexString(sign) );
|
||||
|
||||
// 通过传入公钥P1验签
|
||||
boolean bRet = api.RSAVerify(1,api.DATA_ORIGIN,Util.hexString2Bytes(pk),testData, sign );
|
||||
System.out.println("P1验签结果:"+bRet);*/
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
|
||||
if (null != api) {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.sunyard.sydapi.sample;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.cert.X509;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
public class Test
|
||||
{
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
|
||||
System.out.println("工银亚洲测试功能测试");
|
||||
byte[] testData = new byte[17000];
|
||||
Arrays.fill(testData, (byte) 0x88);
|
||||
|
||||
SydApi api = new SydApiBuilder()
|
||||
.setIp("192.168.1.226")
|
||||
// .useEBCDMode()
|
||||
.useDebugMode()
|
||||
// .useETEncrypt()
|
||||
.build();
|
||||
|
||||
// SydApi api = new SydApi4j().connect("192.168.0.222", 8889, null, 3000);
|
||||
|
||||
try {
|
||||
|
||||
//RetWrap ret = api.genComposeKey(new String[]{"D5B45BA5E80B4520", "187B1BFB7629DCD7"});
|
||||
//RetWrap ret = api.genSymmetricKey("000", 'X');
|
||||
//System.out.println( ret );
|
||||
|
||||
String cert2 = "-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIID6DCCAtCgAwIBAgIFJnVRuPUwDQYJKoZIhvcNAQELBQAwPTELMAkGA1UEBhMCQ04xFDAS\n" +
|
||||
"BgNVBAoMC05YWTIwNDhURVNUMRgwFgYDVQQDDA9OWFkyMDQ4Uk9PVFRFU1QwHhcNMTkwNTMw\n" +
|
||||
"MDAxNjI2WhcNMjQwNTI4MDAxNjI2WjB6MQswCQYDVQQGEwJDTjE3MDUGA1UECgwuUnVyYWwg\n" +
|
||||
"Q3JlZGl0IEJhbmtzIEZ1bmRzIENsZWFyaW5nIENlbnRlcihURVNUKTEUMBIGA1UECwwLRW50\n" +
|
||||
"ZXJwcmlzZXMxHDAaBgNVBAMMEzA2M0A2NzMzMjcwOTk5OTkwMDQwggEiMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4IBDwAwggEKAoIBAQCEEMIed7o5R2ZCPKKZrJjQ7x7hIYsAaBd5vhAhj+HyXyCPF6O6\n" +
|
||||
"3N9znR8uv+BlG2va4jIdye/rLgTGnBuuRZPEYNGvJvoTy01lFtixuInkNW1VkgEQ1CDlwW47\n" +
|
||||
"TOC5dFPYHENkSMMSiDM0BLBQsZH1p4oQzSyGVtAs9YTWQhb/nWSSXgpiz5+qmlvSrsEU+Ffy\n" +
|
||||
"1fYsN6RadZWL2Pegk8NTS/KTfbo9NCgE6jKFoPNzJ20fdK5aUR5ePI5JdnzxfrabkI9F9964\n" +
|
||||
"tlsynsOaoWY60FMmfB+HcvJoSgSI65iNRFRwkzic8mtnmdq9EIIcPgZVz7GCEp9v3Vk30T9e\n" +
|
||||
"M2/ZAgMBAAGjgbEwga4wHwYDVR0jBBgwFoAUZaX9myCvxP1gs80NCsJZtGtypMEwCQYDVR0T\n" +
|
||||
"BAIwADBUBgNVHR8ETTBLMEmgR6BFpEMwQTEOMAwGA1UEAwwFY3JsMjExDDAKBgNVBAsMA2Ny\n" +
|
||||
"bDEUMBIGA1UECgwLTlhZMjA0OFRFU1QxCzAJBgNVBAYTAkNOMAsGA1UdDwQEAwIHgDAdBgNV\n" +
|
||||
"HQ4EFgQUdhrTivJUnKI5oZ0T2OZkSEaDkIUwDQYJKoZIhvcNAQELBQADggEBACgf34fsfPvN\n" +
|
||||
"ln1Ch2Cid7jrJEw5o1AQlahxWtnJH4fzxgYldqgNpoZD3p9XOmFEIvTBHAt8wANQoCQEFJj2\n" +
|
||||
"3PZvwG4T6VXwRn05/u25fMDF4R7Z9IYlNVY5hpxtisC7u8aq7VCqHwzXsjaItuCPQbOkhTCb\n" +
|
||||
"2m4TVGbaMYXVWhEJiss31XrNZgAbKfrFEAmG6+KO5cRdfjXHooaY44sgeEd+Mi5aPyY+QNR1\n" +
|
||||
"uio39G+ur/BjHqOCIujUEI8f3g8wAQaIFyA97rAjJW1W/BVZispRg4niG0mLQ356cTGj+kkJ\n" +
|
||||
"imdxvNyhfwmMNweP6fIUnajMOtJiMomjSAdIuqdxDIw=\n" +
|
||||
"-----END CERTIFICATE-----\n";
|
||||
|
||||
X509 x509 = api.GetX509CertInfo( cert2 );
|
||||
|
||||
System.out.println( x509 );
|
||||
|
||||
|
||||
}finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.sunyard.sydapi.sample;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
// S
|
||||
// key=53353745304145303232443638383236
|
||||
// kcv=3641364533414331353746454631303730314132374139334446303246313938
|
||||
// s1 = 4AD6F3FCC606182A
|
||||
// s2 = 2F47B4C75439C0F0
|
||||
|
||||
|
||||
/**
|
||||
* S
|
||||
* 53433030443432444141433331394234
|
||||
* 3031463646374141334331453532333945443237423031434136333735383530
|
||||
* <p>
|
||||
* <p>
|
||||
* <p>
|
||||
* 554233453843413345304545453331374130333744353832434544454433363138
|
||||
* 334138463043
|
||||
* <p>
|
||||
* <p>
|
||||
* <p>
|
||||
* SA035CDE407F5249
|
||||
* D99CABFAE8D110CD9269FB34B8CAD265
|
||||
* <p>
|
||||
* <p>
|
||||
* X55D9B6452E7B89BB7B266E2D02042780
|
||||
* 7AD5FB
|
||||
* <p>
|
||||
* X7B266E2D0204278055D9B6452E7B89BB
|
||||
* 5A2ABC60CEFCC568
|
||||
*/
|
||||
// U
|
||||
|
||||
/**
|
||||
554233453843413345304545453331374130333744353832434544454433363138
|
||||
334138463043
|
||||
*/
|
||||
|
||||
// T
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* SA035CDE407F5249
|
||||
* D99CABFAE8D110CD9269FB34B8CAD265
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* X55D9B6452E7B89BB7B266E2D02042780
|
||||
* 7AD5FB
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* X7B266E2D0204278055D9B6452E7B89BB
|
||||
* 5A2ABC60CEFCC568
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* X1C7B9DF464C039F2D031E0465E8F89B9
|
||||
* 10093C
|
||||
*/
|
||||
public class Test2 {
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
|
||||
System.out.println("工银亚洲测试功能测试");
|
||||
byte[] testData = new byte[17000];
|
||||
Arrays.fill(testData, (byte) 0x88);
|
||||
|
||||
SydApi api = new SydApiBuilder()
|
||||
.setIp("172.16.17.162")
|
||||
.useDebugMode()
|
||||
.build();
|
||||
|
||||
// SydApi api = new SydApi4j().connect("192.168.0.222", 8889, null, 3000);
|
||||
|
||||
|
||||
RetWrap ret;
|
||||
try {
|
||||
// ret = api.genAndPrintSplit(
|
||||
// "000",
|
||||
// 'X'
|
||||
// );
|
||||
//
|
||||
//
|
||||
// System.out.println( Util.bytes2HexString((byte[]) ret.get("lmkKey")) );
|
||||
// System.out.println( Util.bytes2HexString((byte[]) ret.get("keyCheck")) );
|
||||
|
||||
String[] splits = new String[]{"45A2863406F82135", "2314C1B6C97DF5B8"};
|
||||
// byte[] p1 = Util.hexString2Bytes( splits[0] );
|
||||
// byte[] p2 = Util.hexString2Bytes( splits[1] );
|
||||
// byte[] keybytes = new byte[p1.length + p2.length];
|
||||
|
||||
// for ( int i = 0; i < keybytes.length ; i++ ){
|
||||
// keybytes[i] = (byte) (p1[i] ^ p2[i]);
|
||||
// }
|
||||
|
||||
// System.arraycopy( p1, 0, keybytes, 0, p1.length );
|
||||
// System.arraycopy( p2, 0, keybytes, p1.length, p2.length );
|
||||
//
|
||||
ret = api.genComposeKey("000", 'X', splits[0] + splits[1]);
|
||||
|
||||
System.out.println(ret);
|
||||
System.out.println(new String((byte[]) ret.get("lmkKey")));
|
||||
System.out.println(new String((byte[]) ret.get("keyCheck")));
|
||||
|
||||
} finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.sunyard.sydapi.sample;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TestKeyPair
|
||||
{
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
|
||||
System.out.println("非对称密钥生成");
|
||||
byte[] testData = new byte[17000];
|
||||
Arrays.fill(testData, (byte) 0x88);
|
||||
|
||||
SydApi api = new SydApiBuilder()
|
||||
.setIp("172.16.17.161")
|
||||
.useDebugMode()
|
||||
.build();
|
||||
|
||||
RetWrap ret;
|
||||
try {
|
||||
|
||||
// SM2
|
||||
ret = api.SM2OrRSAGenKeyPair(1, "", 0);
|
||||
|
||||
System.out.println( ret );
|
||||
System.out.println( Util.bytes2HexString((byte[]) ret.get("PrivateKey")) );
|
||||
System.out.println( Util.bytes2HexString((byte[]) ret.get("PublicKey")) );
|
||||
|
||||
|
||||
// RSA
|
||||
ret = api.SM2OrRSAGenKeyPair(0, "", 1152);
|
||||
|
||||
System.out.println( ret );
|
||||
System.out.println( Util.bytes2HexString((byte[]) ret.get("PrivateKey")) );
|
||||
System.out.println( Util.bytes2HexString((byte[]) ret.get("PublicKey")) );
|
||||
|
||||
}finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
/**
|
||||
* SydApi AES256
|
||||
* 调用方法参考如下,加密机需要相应的设置。
|
||||
*/
|
||||
public class AESEnDeApi {
|
||||
|
||||
public static void write(String file, String content) {
|
||||
write(file, content.getBytes());
|
||||
}
|
||||
|
||||
public static void write(String file, byte[] content) {
|
||||
try {
|
||||
File f = new File(file);
|
||||
if (!f.exists()) {
|
||||
f.createNewFile();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
fos.write(content);
|
||||
} catch (Exception e) {
|
||||
System.out.println("写入文件 " + file + " 异常");
|
||||
}
|
||||
}
|
||||
|
||||
public static String read(String file) {
|
||||
try {
|
||||
File f = new File(file);
|
||||
if (!f.exists()) {
|
||||
return null;
|
||||
}
|
||||
FileInputStream fis = new FileInputStream(f);
|
||||
byte[] buff = new byte[5024];
|
||||
int len = fis.read(buff);
|
||||
return new String(buff, 0, len);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 连接加密机
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("61.164.40.82", 8889, null, 1000);
|
||||
|
||||
|
||||
try {
|
||||
|
||||
|
||||
byte[] testData = "<xml></xml>".getBytes();
|
||||
|
||||
// 生成密钥
|
||||
// 注意 'L' 表示 AES 所用的密钥
|
||||
String seesionKey = "L" + api.GenerateRandom(64);
|
||||
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 CBC -----");
|
||||
|
||||
byte[] enDataCBC = api.SYMEncryptDataCBC(SydApi.NALG_AES, seesionKey, testData);
|
||||
System.out.print("密文 : ");
|
||||
System.out.println(Util.bytes2HexString(enDataCBC));
|
||||
write("./EnData.bin", enDataCBC);
|
||||
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 CBC -----");
|
||||
byte[] deDataCBC = api.SYMDecryptDataCBC(SydApi.NALG_AES, seesionKey, enDataCBC);
|
||||
System.out.print("解密 : ");
|
||||
System.out.println(Util.bytes2HexString(deDataCBC));
|
||||
write("./DeData.bin", deDataCBC);
|
||||
|
||||
// 原始报文是字符串,还原原始报文
|
||||
System.out.println(new String(testData));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
|
||||
|
||||
SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.17.162", 8889 , 1000);
|
||||
|
||||
SydApi4j api = (SydApi4j) new SydApi4j();//.connect("wuyong.fullstack.club" , 8889, null,1000);
|
||||
|
||||
|
||||
RetWrap r = api.SYD_SM2GenKeyPair();
|
||||
System.out.println( r.get("publicKey") );
|
||||
System.out.println( r.get("privateKey") );
|
||||
|
||||
// System.out.println("\n\n----- 获取公钥 () -----");
|
||||
// String pk = api.SYD_SM2_Get_Id_PublicKey_HA("1234", 0);
|
||||
// System.out.print("\r\n公钥 : ");
|
||||
// System.out.println( pk );
|
||||
//
|
||||
//
|
||||
//// pk = api.SYD_SM2_Get_Dn_PublicKey_HA("C=CN,O=Sunyard,OU=8001,CN=8001".getBytes("GBK"), 0);
|
||||
//// System.out.print("\r\n公钥 : ");
|
||||
//// System.out.println( pk );
|
||||
//
|
||||
//
|
||||
// // 签名
|
||||
String data="MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>";
|
||||
final String testPubKey = "0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614";
|
||||
// System.out.println("\n\n----- SM2 算法签名 (原始数据) -----");
|
||||
// String sign = api.SYD_SM2_Sign_HA(
|
||||
// "1234",
|
||||
// SydApi.DATA_ORIGIN,
|
||||
// Util.hexString2Bytes(testPubKey),
|
||||
// data.getBytes()
|
||||
// );
|
||||
// System.out.print("\n\n----- SM2 算法签名 结果: ");
|
||||
// System.out.println( sign );
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// System.out.println("\n\n----- SM2 算法验签 (原始数据) -----");
|
||||
// boolean SM2VerifyRet = api.SYD_SM2_Verify_HA(
|
||||
// SydApi.DATA_ORIGIN,
|
||||
// Util.hexString2Bytes(testPubKey), data.getBytes() , sign);
|
||||
// if (SM2VerifyRet){
|
||||
// System.out.println("验签通过");
|
||||
// }else{
|
||||
// System.err.println("验签失败");
|
||||
// throw new RuntimeException("验签失败");
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// // 签名验签 2
|
||||
// System.out.println("\n\n----- 签名验签 2 -----");
|
||||
// String sign2 = api.SYD_SM2_DetachedSign_HA( data.getBytes() , "C=CN,O=Sunyard,OU=8001,CN=8001");
|
||||
// System.out.println( sign2 );
|
||||
|
||||
|
||||
// String sign2 = "MIICpQYKKoEcz1UGAQQCAqCCApUwggKRAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIIByTCCAcUwggFooAMCAQICCDyTAAAAAAAlMAwGCCqBHM9VAYN1BQAwJjELMAkGA1UEBhMCQ04xFzAVBgNVBAMMDlN1bnlhcmRTTTJSb290MB4XDTE3MDUxNzAyNTI0NFoXDTIyMDcyNTAyNTI0NFowPTELMAkGA1UEBhMCQ04xEDAOBgNVBAoMB1N1bnlhcmQxDTALBgNVBAsMBDgwMDExDTALBgNVBAMMBDgwMDEwWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAAQ+2joQe3zDXMAFx/vwu05rQ6B+4U42BgPSLsoqYAstD6AwVdQA0SQDAPVGSLhJ0T9QszD/FDUbVkWxNoaCCmW7o2cwZTAOBgNVHQ8BAf8EBAMCAMAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwHwYDVR0jBBgwFoAU93/arv8hxtk6eq2g+6z+AqVO1cEwHQYDVR0OBBYEFAMWZaY2AwaQTNiFLpsa0dyCzBZ6MAwGCCqBHM9VAYN1BQADSQAwRgIhAIl2ZHGfln5hedcousARzZ2yeUjUbxSFMmhMmr5t6Q6nAiEAvqYX/KpIcvnPyB/Yiil+oq6DFdVM6P3vDxBhU/8taXExgaAwgZ0CAQEwMjAmMQswCQYDVQQGEwJDTjEXMBUGA1UEAwwOU3VueWFyZFNNMlJvb3QCCDyTAAAAAAAlMAwGCCqBHM9VAYMRBQAwDQYJKoEcz1UBgi0BBQAERzBFAiATwLIYiylt7xHmBkH6EclrchClxzLlKWC5guxxzkr58gIhANSw+owu8cyypdJtHGrGqjSiB1BVzGva+irUHelx/GbC";
|
||||
// sign2 = "MIID7gYKKoEcz1UGAQQCAqCCA94wggPaAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIIC2jCCAtYwggJ6oAMCAQICBUACgAF0MAwGCCqBHM9VAYN1BQAwYTELMAkGA1UEBhMCQ04xMDAuBgNVBAoMJ0NoaW5hIEZpbmFuY2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEgMB4GA1UEAwwXQ0ZDQSBBQ1MgVEVTVCBTTTIgT0NBMzEwHhcNMTcxMTE2MDY1NDQ1WhcNMjIxMTE2MDY1NDQ1WjCBgzELMAkGA1UEBhMCQ04xHDAaBgNVBAoME0NGQ0EgVEVTVCBTTTIgT0NBMzExDjAMBgNVBAsMBVNIQ1BFMRkwFwYDVQQLDBBPcmdhbml6YXRpb25hbC0xMSswKQYDVQQDDCIwNTFA5LiK5rW356Wo5o2u5Lqk5piT5omAQEFBQUFBQUA4MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEYPA9UQRL/ZaThEN0nc3SwkOHw4hPDXG9hZeKiBnNdhgPy1EtX4My2bpNFpYMmQ0nvkJUM4qpJrF7MSqEws6rLaOB+TCB9jA/BggrBgEFBQcBAQQzMDEwLwYIKwYBBQUHMAGGI2h0dHA6Ly9vY3NwdGVzdC5jZmNhLmNvbS5jbjo4MC9vY3NwMB8GA1UdIwQYMBaAFATHvPlZAWk+jDQ2IGIYPN68tbsMMAwGA1UdEwEB/wQCMAAwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovLzIxMC43NC40Mi4zL09DQTMxL1NNMi9jcmwxLmNybDAOBgNVHQ8BAf8EBAMCBsAwHQYDVR0OBBYEFKJnS7XYRDWG9eqXtSzUZXK+De2/MB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDBDAMBggqgRzPVQGDdQUAA0gAMEUCIGaSRoaUSpoH4lW3at1ABluiNwFDH21jHesHmy0F5gjqAiEA0sUykW9E36F3qQ91YDvasQg8EnOMp1idhgt6pq/NUAYxgdgwgdUCAQEwajBhMQswCQYDVQQGEwJDTjEwMC4GA1UECgwnQ2hpbmEgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MSAwHgYDVQQDDBdDRkNBIEFDUyBURVNUIFNNMiBPQ0EzMQIFQAKAAXQwDAYIKoEcz1UBgxEFADANBgkqgRzPVQGCLQEFAARHMEUCIQDH3ePzq4nYJ8pAodJyqPKqCQuQwmOpyj/rWcDILzFj2gIgUW5c9W6jD7u91opMcDwaw4aNEvEtGX6ks5XDIMIkUjI=";
|
||||
//
|
||||
//
|
||||
//
|
||||
// boolean pass = api.SYD_SM2_DetachedVerify_HA( "<MainBody><MsgId><Id>000000000000000201809181000008627</Id><CreDtTm>2018-09-17T19:06:39</CreDtTm></MsgId><CertNtfctnInf><ChngTp>CC00</ChngTp></CertNtfctnInf></MainBody>".getBytes(), sign2 );
|
||||
// System.out.println( pass );
|
||||
//
|
||||
// // 获取公钥
|
||||
// X509 x = api.SYD_Get_X509_CertInfo_HA( "<MainBody><MsgId><Id>000000000000000201809181000008627</Id><CreDtTm>2018-09-17T19:06:39</CreDtTm></MsgId><CertNtfctnInf><ChngTp>CC00</ChngTp></CertNtfctnInf></MainBody>".getBytes(), sign2 );
|
||||
// System.out.println( Util.bytes2HexString( x.getPubKey() ) );
|
||||
|
||||
byte[]ttt = new byte[40960];
|
||||
Arrays.fill(ttt, (byte) 0x88);
|
||||
String sign2 = api.SYD_SM2_Sign_HA(
|
||||
"1234",
|
||||
SydApi.DATA_HASH,
|
||||
Util.hexString2Bytes("0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"),
|
||||
ttt
|
||||
);
|
||||
System.out.print("\n\n----- SM2 算法签名 结果: ");
|
||||
System.out.println( sign2 );
|
||||
|
||||
System.out.println( api.SYD_SM2_Verify_HA(
|
||||
SydApi.DATA_HASH,
|
||||
Util.hexString2Bytes("0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"),
|
||||
ttt ,
|
||||
sign2
|
||||
) );
|
||||
|
||||
|
||||
|
||||
String sign3 = api.SYD_SM2_Sign_HA(
|
||||
"1234",
|
||||
SydApi.DATA_ORIGIN,
|
||||
Util.hexString2Bytes("0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"),
|
||||
"<MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>".getBytes()
|
||||
);
|
||||
System.out.print("\n\n----- SM2 算法签名 结果: ");
|
||||
System.out.println( sign3 );
|
||||
|
||||
System.out.println( api.SYD_SM2_Verify_HA(
|
||||
SydApi.DATA_ORIGIN,
|
||||
Util.hexString2Bytes("0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"),
|
||||
"<MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>".getBytes() ,
|
||||
sign3
|
||||
) );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.proto.Util;
|
||||
import com.sunyard.util.SYMUtil;
|
||||
|
||||
public class DerBase64 {
|
||||
public static void main(String[] args) {
|
||||
|
||||
// String s = "W+O1ul8sVkWa071M8VFCJenstGxNa0HQ3P0WFzQ10KEo68A5nB0b4Ywx20H98lKdKduUGFFXkqOgaKq5OphrIg==";
|
||||
// byte[] c = SYMUtil.base64Sign2DerSign(s);
|
||||
// String ss = SYMUtil.derSign2Base64Sign(c);
|
||||
//
|
||||
//
|
||||
// System.out.println(s);
|
||||
// System.out.println(ss);
|
||||
//
|
||||
// c = SYMUtil.base64Sign2DerSign(ss);
|
||||
// ss = SYMUtil.derSign2Base64Sign(c);
|
||||
//
|
||||
//
|
||||
// System.out.println(s);
|
||||
// System.out.println(ss);
|
||||
|
||||
|
||||
String s = "Q7SUNKlzHJ7IMUDrwTsp3qEtJG6WK68r0SgQzbRvaZMBEuW+3zQmWwa59TLxKslmPt+/rba8A0DAozUa9ULPyuzkDi6VIKU+NybHy5SsWWzaPdcFFuTGn1gKx+ZEJnisooD1+hINERBveggO5lNE82yYUgo8saD7dR3VpXj3LCsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==";
|
||||
System.out.println(s);
|
||||
byte[] c = SYMUtil.base64EnData2DerEnData(s);
|
||||
|
||||
System.out.println( Util.bytes2HexString(c) );
|
||||
|
||||
// s = SYMUtil.derEnData2Base64EnData(c);
|
||||
//
|
||||
// System.out.println(s);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.util.CoderUtil;
|
||||
|
||||
public class EBCDTest {
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.sunyard.sydapi.test
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
var code = 32774
|
||||
|
||||
println( String.format("%X", code) )
|
||||
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true")
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.proto.Util;
|
||||
|
||||
public class HEX {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
int a = 123;
|
||||
System.out.println( a & 0xFF );
|
||||
System.out.println( a >> 8 & 0xFF );
|
||||
|
||||
|
||||
System.out.println(Util.bytes2HexString( "MA".getBytes() ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
public class JsonTest {
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println(String.format("%03X", 10));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.proto.ProtocolRender;
|
||||
import com.sunyard.proto.ProtocolSet;
|
||||
import com.sunyard.proto.loader.Loader;
|
||||
import com.sunyard.proto.loader.ResourceLoader;
|
||||
import com.sunyard.trans.PacketSN;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LoaderTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MACTest {
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
System.out.println("MAC 测试");
|
||||
byte[] testData = new byte[ 2 * 1024];
|
||||
SydApi4j api = (SydApi4j) new SydApiBuilder()
|
||||
.setIp("172.16.17.162")
|
||||
.useDebugMode()
|
||||
.build();
|
||||
|
||||
|
||||
RetWrap ret;
|
||||
try {
|
||||
|
||||
String mac = api.MACCalc(2, 1, "X3E95C24E03921CFA8CB8BA02DC76E22B", 1, testData, 2);
|
||||
System.out.println( mac );
|
||||
api.MACCheck( 2, 1, "X3E95C24E03921CFA8CB8BA02DC76E22B", 1, testData, mac );
|
||||
|
||||
|
||||
|
||||
mac = api.MACCalc(0, 0, "7DEB4320CE659D56", 1, testData, 2);
|
||||
System.out.println( mac );
|
||||
api.MACCheck( 0, 0, "7DEB4320CE659D56", 1, testData, mac );
|
||||
|
||||
|
||||
mac = api.MACCalc(0, 0, "1234567812345678", 0, testData, 1);
|
||||
System.out.println( mac );
|
||||
api.MACCheck( 0, 0, "1234567812345678", 0, testData, mac );
|
||||
|
||||
|
||||
mac = api.MACCalc(2, 0, "X12345678123456781234567812345678", 0, testData, 2);
|
||||
System.out.println( mac );
|
||||
api.MACCheck( 2, 0, "X12345678123456781234567812345678", 0, testData, mac );
|
||||
|
||||
mac = api.MACCalc(2, 0, "X12345678123456781234567812345678", 0, testData, 3);
|
||||
System.out.println( mac );
|
||||
api.MACCheck( 2, 0, "X12345678123456781234567812345678", 0, testData, mac );
|
||||
|
||||
} finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
|
||||
public class NetTest {
|
||||
|
||||
/*
|
||||
* 字符转换为字节
|
||||
*/
|
||||
private static byte charToByte(char c) {
|
||||
return (byte) "0123456789ABCDEF".indexOf(c);
|
||||
}
|
||||
/*
|
||||
* 16进制字符串转字节数组
|
||||
*/
|
||||
public static byte[] hexString2Bytes(String hex) {
|
||||
|
||||
if ((hex == null) || (hex.equals(""))){
|
||||
return null;
|
||||
}
|
||||
else if (hex.length()%2 != 0){
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
hex = hex.toUpperCase();
|
||||
int len = hex.length()/2;
|
||||
byte[] b = new byte[len];
|
||||
char[] hc = hex.toCharArray();
|
||||
for (int i=0; i<len; i++){
|
||||
int p=2*i;
|
||||
b[i] = (byte) (charToByte(hc[p]) << 4 | charToByte(hc[p+1]));
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
|
||||
//创建Socket对象,连接服务器
|
||||
Socket socket = new Socket("172.16.17.162",8889);
|
||||
//通过客户端的套接字对象Socket方法,获取字节输出流,将数据写向服务器
|
||||
OutputStream out=socket.getOutputStream();
|
||||
out.write( hexString2Bytes("000D00000000000000005938303038") );
|
||||
|
||||
//读取服务器发回的数据,使用socket套接字对象中的字节输入流
|
||||
InputStream in=socket.getInputStream();
|
||||
byte[] data = new byte[1024];
|
||||
int len = in.read(data);
|
||||
System.out.println(new String(data,0,len));
|
||||
|
||||
socket.close();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
public class PBOCTest {
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
System.out.println("PBOC MAC 测试");
|
||||
byte[] testData = new byte[ 16 * 1024 + 1];
|
||||
SydApi4j api = (SydApi4j) new SydApiBuilder()
|
||||
.setIp("172.16.17.162")
|
||||
.useDebugMode()
|
||||
.build();
|
||||
|
||||
|
||||
RetWrap ret;
|
||||
try {
|
||||
|
||||
String mac = api.calcPBOCMAC(0, 0, "1234567812345678", testData, 0, null);
|
||||
System.out.println( mac );
|
||||
|
||||
|
||||
|
||||
mac = api.calcPBOCMAC(2, 0, "X12345678123456781234567812345678", testData, 0, null);
|
||||
|
||||
System.out.println( mac );
|
||||
|
||||
|
||||
} finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class PINOpt {
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
|
||||
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.17.162", 8889, null,1000);
|
||||
|
||||
|
||||
|
||||
try {
|
||||
|
||||
int a = 1;
|
||||
int pt = 6;
|
||||
|
||||
// String pin = "D35A15B4285519BC9A0E593C9A84F3C6";
|
||||
String pin1 = "5D5D0A6BD27BBB3B68CED0002036B96C";
|
||||
String key4 = "X87654321876543218765432187654321";
|
||||
String key2 = "X12345678123456781234567812345678";
|
||||
/*
|
||||
String pb = api.transPINFromZPKToZPK(
|
||||
"X32EE7621370CBD81D1CB1344C22A481E",
|
||||
"X80DB2CDB008A974D155988DD9EBDE5AE",
|
||||
a, a, pt, pt, pin,
|
||||
"202000910731"
|
||||
);*/
|
||||
String pb = api.transPINFromZPKToZPK(
|
||||
key4,
|
||||
key2,
|
||||
a, a, pt, pt, pin1,
|
||||
"123456789123"
|
||||
);
|
||||
|
||||
|
||||
System.out.println(pb);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.inf.SydPledge;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
public class PledgeTest {
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
byte[] testData = "1234567812345678".getBytes();
|
||||
//testData = new byte[8];
|
||||
|
||||
// 连接加密机
|
||||
SydPledge api = new SydApiBuilder()
|
||||
.setIp("192.168.0.222")
|
||||
//.useEBCDMode()
|
||||
.build();
|
||||
|
||||
|
||||
try {
|
||||
|
||||
String mac = api.GenerateMIYA("123456", 1, SydApi.NALG_3DES, testData);
|
||||
System.out.println("MAC = " + mac);
|
||||
Boolean ret = api.VerifyMIYA( "123456", 1, SydApi.NALG_3DES, mac, testData);
|
||||
if ( ret ){
|
||||
System.out.println("核押通过");
|
||||
} else {
|
||||
System.out.println("核押不通过");
|
||||
}
|
||||
|
||||
|
||||
// 测试篡改 MAC
|
||||
String errMac = "F0BD5669";
|
||||
Boolean ret2 = api.VerifyMIYA( "123456", 1, SydApi.NALG_3DES, errMac, testData);
|
||||
if ( ret2 ){
|
||||
System.out.println("篡改 MAC 未检测到");
|
||||
} else {
|
||||
System.out.println("篡改 MAC");
|
||||
}
|
||||
|
||||
} finally {
|
||||
((SydApi) api).disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.inf.SydPledge;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
public class PledgeTest2 {
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
byte[] testData = "1234567812345678".getBytes();
|
||||
//testData = new byte[8];
|
||||
|
||||
// 连接加密机
|
||||
SydPledge api = new SydApiBuilder()
|
||||
.setIp("192.168.0.222")
|
||||
//.useEBCDMode()
|
||||
.build();
|
||||
try {
|
||||
|
||||
String mac = api.GenerateMIYA("123456", 1, SydApi.NALG_SM4, testData);
|
||||
System.out.println("MAC = " + mac);
|
||||
Boolean ret = api.VerifyMIYA( "123456", 1, SydApi.NALG_SM4, mac, testData);
|
||||
if ( ret ){
|
||||
System.out.println("核押通过");
|
||||
} else {
|
||||
System.out.println("核押不通过");
|
||||
}
|
||||
|
||||
|
||||
// 测试篡改 MAC
|
||||
String errMac = "F0BD5669";
|
||||
Boolean ret2 = api.VerifyMIYA( "123456", 1,SydApi.NALG_SM4, errMac, testData);
|
||||
if ( ret2 ){
|
||||
System.out.println("篡改 MAC 未检测到");
|
||||
} else {
|
||||
System.out.println("篡改 MAC");
|
||||
}
|
||||
|
||||
} finally {
|
||||
((SydApi) api).disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.inf.SydPledge;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class PrintTest {
|
||||
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
// 连接加密机
|
||||
SydApi4j api = (SydApi4j) new SydApiBuilder()
|
||||
.setIp("172.16.17.161")
|
||||
.useDebugMode()
|
||||
.build();
|
||||
|
||||
|
||||
try {
|
||||
|
||||
api.setPrintFormat(new String(">L>003^0>033^4>L>003^1>023^P>033^5>053^Q>L>003^2>033^6>003^3>033^7>L>003THANK YOU>033>THANK YOU 中文>L>F".getBytes("UTF-8") , "GB2312"));
|
||||
|
||||
// String r1 = api.GenerateRandom(1);
|
||||
// System.out.println( r1 );
|
||||
|
||||
api.genAndPrintSplit("000", 'X');
|
||||
|
||||
} finally {
|
||||
((SydApi) api).disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import javax.script.*;
|
||||
|
||||
public class ScriptTest {
|
||||
private static final ScriptEngineManager factory = new ScriptEngineManager();
|
||||
|
||||
public static void main(String[] args) throws ScriptException {
|
||||
ScriptEngine gvEngine = factory.getEngineByName("groovy");
|
||||
gvEngine.eval("def signatureLen() {\n" +
|
||||
" return println(\"123\")\n" +
|
||||
"}");
|
||||
|
||||
Bindings bindings = new SimpleBindings();
|
||||
bindings.put("dd", 321);
|
||||
|
||||
|
||||
Bindings bindings2 = new SimpleBindings();
|
||||
bindings.put("aa", "aa");
|
||||
|
||||
gvEngine.eval(" \n\n signatureLen()", bindings);
|
||||
gvEngine.eval(" \n\n println(dd)");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Status {
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
SydApi4j api = (SydApi4j) new SydApi4j();//.connect("wuyong.fullstack.club" , 8889, null,1000);
|
||||
api.connect("172.16.17.162", 8889, null, 5000);
|
||||
|
||||
RetWrap r = api.getStatus();
|
||||
System.out.println( r.get("CPU") );
|
||||
System.out.println( r.get("MEM") );
|
||||
System.out.println( r.get("DISK") );
|
||||
|
||||
api.disconnect();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.cert.X509;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
public class Test74 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.17.162", 8889, 1000);
|
||||
|
||||
SydApi4j api = (SydApi4j) new SydApi4j();
|
||||
|
||||
|
||||
String pk = "03420004C9FD0B37230DF91621F6880C8123A445CB14FFB1B1342D0AC9449374876A4B1E00A15B9E8DF307EE538526883F093568C5B70C5A61BEF5F880C827DDC90366B5";
|
||||
String sk = "00010000C530EFBC1971D6526BDAB640370EE9197BFB0D78F88417C1ED49981FFEF226980000000000000000000000000000000000000000000000000000000000000000";
|
||||
byte[] skByte = Util.hexString2Bytes(sk);
|
||||
byte[] pkByte = Util.hexString2Bytes(pk);
|
||||
|
||||
String data = "MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>";
|
||||
|
||||
|
||||
String sign3 = api.SYD_SM2_Sign_HA(
|
||||
SydApi.DATA_ORIGIN,
|
||||
skByte,
|
||||
pkByte,
|
||||
data.getBytes()
|
||||
);
|
||||
System.out.print("\n\n----- SM2 算法签名 结果: ");
|
||||
System.out.println(sign3);
|
||||
|
||||
|
||||
System.out.println(api.SYD_SM2_Verify_HA(
|
||||
SydApi.DATA_ORIGIN,
|
||||
pkByte,
|
||||
data.getBytes(),
|
||||
sign3
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.sunyard.SydApi.ALG_AES;
|
||||
|
||||
/**
|
||||
* SydApi AES256
|
||||
* 调用方法参考如下,加密机需要相应的设置。
|
||||
*/
|
||||
public class TestAESEnDeApi {
|
||||
|
||||
public static void write(String file, String content) {
|
||||
write(file, content.getBytes());
|
||||
}
|
||||
|
||||
public static void write(String file, byte[] content) {
|
||||
try {
|
||||
File f = new File(file);
|
||||
if (!f.exists()) {
|
||||
f.createNewFile();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
fos.write(content);
|
||||
} catch (Exception e) {
|
||||
System.out.println("写入文件 " + file + " 异常");
|
||||
}
|
||||
}
|
||||
|
||||
public static String read(String file) {
|
||||
try {
|
||||
File f = new File(file);
|
||||
if (!f.exists()) {
|
||||
return null;
|
||||
}
|
||||
FileInputStream fis = new FileInputStream(f);
|
||||
byte[] buff = new byte[5024];
|
||||
int len = fis.read(buff);
|
||||
return new String(buff, 0, len);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 连接加密机
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.18.99", 8889, null, 1000);
|
||||
|
||||
|
||||
try {
|
||||
|
||||
|
||||
byte[] testData = "<xml></xml>".getBytes();
|
||||
|
||||
// 生成密钥
|
||||
// 注意 'L' 表示 AES 所用的密钥
|
||||
String seesionKey = "L" + api.GenerateRandom(64 );
|
||||
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 CBC -----");
|
||||
|
||||
byte[] enDataCBC = api.SYMEncryptDataCBC(SydApi.NALG_AES, seesionKey, testData);
|
||||
System.out.print("密文 : ");
|
||||
System.out.println(Util.bytes2HexString(enDataCBC));
|
||||
write("./EnData.bin", enDataCBC);
|
||||
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 CBC -----");
|
||||
byte[] deDataCBC = api.SYMDecryptDataCBC(SydApi.NALG_AES, seesionKey, enDataCBC);
|
||||
System.out.print("解密 : ");
|
||||
System.out.println(Util.bytes2HexString(deDataCBC));
|
||||
write("./DeData.bin", deDataCBC);
|
||||
|
||||
// 原始报文是字符串,还原原始报文
|
||||
System.out.println( new String(testData) );
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class TestBB {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
byte[] d = new byte[ 1024 ];
|
||||
ByteBuffer bb = ByteBuffer.wrap( d );
|
||||
|
||||
bb.position( d.length );
|
||||
bb.flip();
|
||||
bb.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TestByteBuffer {
|
||||
public static void main(String[] args) {
|
||||
ByteBuffer bb = ByteBuffer.allocate(2);
|
||||
bb.put(0, (byte) 1);
|
||||
bb.put(0, (byte) 2);
|
||||
System.out.println(Arrays.toString(bb.array()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.inf.SydPledge;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
|
||||
public class TestCB
|
||||
{
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
|
||||
System.out.println("SydApi 测试程序启动");
|
||||
|
||||
SydApi key = new SydApiBuilder()
|
||||
.setIp("192.168.0.222")
|
||||
//.useEBCDMode()
|
||||
.build();
|
||||
|
||||
|
||||
|
||||
String srcKey = "303030303030303030303030303030323030413030303030303030";
|
||||
String desKey = "583234364637434543324546303941374138463034373543364231434534423035";
|
||||
String sPin = "3244454345364241344134413345453531413130423034313945393539354339";
|
||||
String primaryAccount = "313233343536373839303132";
|
||||
|
||||
RetWrap retWrap = key.generateDE("100", (byte) 1);
|
||||
String seesionKey = (String) retWrap.get("SessionKey");
|
||||
byte[] bytePin = key.transPinFrOneKeyToAno( "XK" + srcKey, desKey, 2, sPin, primaryAccount);
|
||||
|
||||
System.out.println("执行结束\n\n" );
|
||||
key.disconnect();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
public class TestChar {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String s="headername";
|
||||
String[] a=s.split("\\.");
|
||||
System.out.println(a.length);
|
||||
|
||||
|
||||
|
||||
//25CFC2EC2EB59D63836E20BBB2CB36C12699A22D4857B694B43F14A4B51A1B3BC44192F927BAE721FC223D27E9FE42EB61C43BD9D1853E32AAC03476BEB67419F6166167E93D087708649F582EA8E6B7FA3168B87BE793201BC49F43E058467781492348
|
||||
|
||||
//0383 = 899
|
||||
//0000000000000000
|
||||
//8017
|
||||
//0000
|
||||
//02EB = 747
|
||||
//8303330373034303134370000883033343230303034333632393745393446433332314536343637453346314330353632344142384336424230304139364237303137303532313737384637374633373732433931374145344232344233323546313443393145433638454433333839433442444330463236333330463239433238313131413335434244314645413843333141313830433D434E2C4F3D4368696E612046696E616E6369616C2043657274696669636174696F6E20417574686F726974792C434E3D43464341205445535420534D32204F4341310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003130303432383234353100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000433D434E2C4F3D43464341204F4341312C4F553D594343412C4F553D496E646976696475616C2D322C434E3D5943434140BBC6BDF0BDBBD2D7CBF9405A6875616E676A4031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032303137303330373034303134370032303137559323476553030794C324E79624445774F44457559334A734D41344741315564447745422F775145417749477744416442674E56485134450A46675155517044723068616D52584250334750786C744E784A5578516B714177485159445652306C42425977464159494B7759424251554841774947434373470A4151554642774D454D41774743430000
|
||||
|
||||
|
||||
//System.out.println( '0' == "1230".charAt(3));
|
||||
|
||||
// ByteBuffer bb = ByteBuffer.allocate(10);
|
||||
// bb.put((byte) 1);
|
||||
// bb.put(new byte[3]);
|
||||
// bb.put((byte) 1);
|
||||
// System.out.println(Arrays.toString(bb.array()));038300000000000000008017000002EB433D434E2C4F3D4368696E612046696E616E6369616C2043657274696669636174696F6E20417574686F726974792C434E3D43464341205445535420534D32204F4341310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003130303432383234353100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000433D434E2C4F3D43464341204F4341312C4F553D594343412C4F553D496E646976696475616C2D322C434E3D5943434140BBC6BDF0BDBBD2D7CBF9405A6875616E676A40310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000323031373033303730343031343700323031383033303730343031343700008830333432303030343336323937453934464333323145363436374533463143303536323441423843364242303041393642373031373035323137373846373746333737324339313741453442323442333235463134433931454336384544333338394334424443304632363333304632394332383131314133354342443146454138433331413138307559323476553030794C324E79624445774F44457559334A734D41344741315564447745422F775145417749477744416442674E56485134450A46675155517044723068616D52584250334750786C744E784A5578516B714177485159445652306C42425977464159494B7759424251554841774947434373470A4151554642774D454D41774743430000
|
||||
|
||||
|
||||
//System.out.println(Integer.valueOf(3) == Integer.valueOf(3));
|
||||
|
||||
// System.out.println(Util.bytes2HexString("time".getBytes()));
|
||||
// System.out.println(Util.bytes2HexString("ping".getBytes()));
|
||||
// System.out.println(Util.bytes2HexString("pong".getBytes()));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
|
||||
public class TestDecryptDataWithFile
|
||||
{
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
System.out.println("SydApi 测试程序启动");
|
||||
SydApi key = new SydApi4j().connect("172.16.18.74",8889,null,10000);
|
||||
System.out.println("连接成功");
|
||||
|
||||
long startTime = System.currentTimeMillis(); //获取开始时间
|
||||
|
||||
byte[] bytes = Util.hexString2Bytes("CBB5DF1ECDB7564EFDA62076632F459BD8F618DC060A5AC368848C5A1D78A85CAFA26F8228F446E2ABA5AEA8F32CF91B606CFD2125766DD3A4E47F4DD22D3A198C2000E9C6F1B73FA33BFE13A00D3612DC9D7C2811A7C1ABAEDBAEEBE8E18D9A2CD670A2526E98C50C4F9205FDE32162E7C8583154D5DDEF2D1B71C6C1636F684BCF865A8EC852C389DEB381728806AC5659E7980651528C0B6F86A47881A66F2C21317D778253786765D60EAA73BC7C6C4CE658BB5231A4FE7282646B0DC774E0B56E38DA29FBA654DB6973661BC65227751E98AB2DD1EBB8076E32D1DB8712");
|
||||
|
||||
|
||||
String inputPath = "c:\\Users\\MrYang\\Desktop\\dataEncrypt.txt";
|
||||
String outputPath = "c:\\Users\\MrYang\\Desktop\\dataDncrypt.txt";
|
||||
try {
|
||||
FileOutputStream fileWriter =new FileOutputStream(inputPath);
|
||||
fileWriter.write(bytes);
|
||||
fileWriter.flush();
|
||||
fileWriter.close();
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
key.SYMDecryptDataWithFile(1, "X246F7CEC2EF09A7A8F0475C6B1CE4B05", inputPath, outputPath);
|
||||
|
||||
long endTime=System.currentTimeMillis(); //获取结束时间
|
||||
System.out.println("程序运行时间: "+(endTime-startTime)+"ms");
|
||||
|
||||
System.out.println("执行结束\n\n" );
|
||||
key.disconnect();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
|
||||
public class TestECBWithFile
|
||||
{
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
|
||||
System.out.println("SydApi 测试程序启动");
|
||||
/*SydApi key = new SydApi4j().connect("172.16.18.72",8889,null,10000);
|
||||
System.out.println("连接成功");
|
||||
|
||||
|
||||
|
||||
int lenIndata = 0;
|
||||
try {
|
||||
lenIndata = getInDataLen("d:\\TestFile.txt");
|
||||
}catch (Exception e)
|
||||
{}
|
||||
byte[] data = new byte[lenIndata];
|
||||
try {
|
||||
data = getInData("d:\\TestFile.txt");
|
||||
} catch (Exception e)
|
||||
{}
|
||||
|
||||
byte[] encryptData = key.SYMEncryptData(0x01, "X246F7CEC2EF09A7A8F0475C6B1CE4B05",data);
|
||||
|
||||
try {
|
||||
outData2file(encryptData, "d:\\TestFileEncrypt.txt");
|
||||
} catch (Exception e)
|
||||
{}
|
||||
|
||||
byte[] decryptData = key.SYMDecryptData(0x01, "X246F7CEC2EF09A7A8F0475C6B1CE4B05",encryptData);*/
|
||||
|
||||
// byte[] decryptDataWithFile = key.SYMDecryptDataWithFile(0x01, "X246F7CEC2EF09A7A8F0475C6B1CE4B05","d:\\TestFileEncrypt.txt");
|
||||
byte a = 1;
|
||||
int x = (a- 0x30);
|
||||
System.out.println("执行结束\n\n:"+ x);
|
||||
// key.disconnect();
|
||||
|
||||
}
|
||||
|
||||
// 读取文件长度
|
||||
public static int getInDataLen(String filePath) throws Exception
|
||||
{
|
||||
FileInputStream tmpInput = new FileInputStream(filePath);
|
||||
int lenInData = tmpInput.available();
|
||||
|
||||
return lenInData;
|
||||
}
|
||||
|
||||
// 读取文件内容
|
||||
public static byte[] getInData(String fileName) throws Exception {
|
||||
FileInputStream tmpInput = new FileInputStream(fileName);
|
||||
int InDataLen = tmpInput.available();
|
||||
|
||||
byte[] InData = new byte[InDataLen];
|
||||
|
||||
tmpInput.read(InData);
|
||||
tmpInput.close();
|
||||
|
||||
System.out.println("[Info] Read File:{" + fileName + "}, Read Length:{" + InDataLen + "} ...");
|
||||
|
||||
return InData;
|
||||
}
|
||||
|
||||
// 写入文件内容
|
||||
public static void outData2file(byte[] outData, String filePath) throws Exception
|
||||
{
|
||||
FileOutputStream tmpOutput = new FileOutputStream(filePath);
|
||||
tmpOutput.write(outData);
|
||||
tmpOutput.close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* SydApi 网联相关接口
|
||||
* 调用方法参考如下,加密机需要相应的设置。
|
||||
*/
|
||||
public class TestEnDeApi {
|
||||
|
||||
public static void write(String file, String content) {
|
||||
write(file, content.getBytes());
|
||||
}
|
||||
|
||||
public static void write(String file, byte[] content) {
|
||||
try {
|
||||
File f = new File(file);
|
||||
if (!f.exists()) {
|
||||
f.createNewFile();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
fos.write(content);
|
||||
} catch (Exception e) {
|
||||
System.out.println("写入文件 " + file + " 异常");
|
||||
}
|
||||
}
|
||||
|
||||
public static String read(String file) {
|
||||
try {
|
||||
File f = new File(file);
|
||||
if (!f.exists()) {
|
||||
return null;
|
||||
}
|
||||
FileInputStream fis = new FileInputStream(f);
|
||||
byte[] buff = new byte[5024];
|
||||
int len = fis.read(buff);
|
||||
return new String(buff, 0, len);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
// 连接加密机
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.1.226", 8889, null, 1000);
|
||||
|
||||
|
||||
|
||||
final String testSN1 = "1004282451";
|
||||
final String testSN2 = "1004282452";
|
||||
final String testPubKey = "0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614";
|
||||
final String testPubKey1 = "034200040B2FCF5E2B15D341FC12A9B6A88631D83A7B79DC6BABF9E49FFF624BD148E2FA44A9F1B7F1E36E39B22AA6BD79B7EA527DB912617148A62CB94760CB80EE3A68";
|
||||
byte[] testData = new byte[ 10 ];
|
||||
Arrays.fill(testData, (byte) 0x88);
|
||||
testData[testData.length - 3] = (byte) 0xFF;
|
||||
testData[testData.length - 2] = (byte) 0xFF;
|
||||
testData[testData.length - 1] = (byte) 0xFF;
|
||||
final String testUser = "8012";
|
||||
|
||||
|
||||
try {
|
||||
|
||||
|
||||
// // testData = "<xml></xml>".getBytes();
|
||||
// System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 -----");
|
||||
// String sessionKey = read("./SessionKey.bin");
|
||||
// byte[] enSm4Data = api.SYMEncryptData(SydApi.NALG_SM4, sessionKey, testData);
|
||||
// System.out.print("密文 : ");
|
||||
// System.out.println(Util.bytes2HexString(enSm4Data));
|
||||
// write("./EnData.bin", enSm4Data);
|
||||
|
||||
//
|
||||
// System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 -----");
|
||||
// byte[] deSM4Data = api.SYMDecryptData(SydApi.NALG_SM4, sessionKey, enSm4Data);
|
||||
// System.out.print("解密 : ");
|
||||
// System.out.println(Util.bytes2HexString(deSM4Data));
|
||||
// write("./DeData.bin", enSm4Data);
|
||||
//
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 CBC -----");
|
||||
String sessionKeyCBC = "X12345678123456781234567812345678"; //read("./SessionKey.bin");
|
||||
byte[] enDataCBC = api.SYMEncryptDataCBC(SydApi.NALG_SM4, sessionKeyCBC, testData);
|
||||
System.out.print("密文 : ");
|
||||
System.out.println(Util.bytes2HexString(enDataCBC));
|
||||
write("./EnData.bin", enDataCBC);
|
||||
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 CBC -----");
|
||||
byte[] deDataCBC = api.SYMDecryptDataCBC(SydApi.NALG_SM4, sessionKeyCBC, enDataCBC);
|
||||
System.out.print("解密 : ");
|
||||
System.out.println(Util.bytes2HexString(deDataCBC));
|
||||
write("./DeData.bin", deDataCBC);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.SydApiException;
|
||||
|
||||
public class TestException {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
//System.out.println( new SydApiException("通信数据错误", -3) );
|
||||
|
||||
|
||||
new SydApiException("通信数据错误", -3).printStackTrace();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
public class TestGongYin
|
||||
{
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
|
||||
System.out.println("工银亚洲测试功能测试");
|
||||
byte[] testData = new byte[17000];
|
||||
Arrays.fill(testData, (byte) 0x88);
|
||||
|
||||
SydApi api = new SydApiBuilder()
|
||||
.setIp("192.168.0.222")
|
||||
.useEBCDMode()
|
||||
.useDebugMode()
|
||||
.useETEncrypt()
|
||||
.build();
|
||||
|
||||
// SydApi api = new SydApi4j().connect("192.168.0.222", 8889, null, 3000);
|
||||
|
||||
try {
|
||||
|
||||
String r32 = api.GenerateRandom(32);
|
||||
System.out.println( r32 );
|
||||
|
||||
|
||||
//
|
||||
// 6A000163C9300000000009CX
|
||||
RetWrap wrapNum = api.generateDE("1000000020", SydApi.ALG_SM4);
|
||||
System.out.print("Session Key : ");
|
||||
System.out.println(wrapNum.get(SydApi.RET_SESSION_KEY));
|
||||
System.out.print("Cipher Key : ");
|
||||
System.out.println(wrapNum.get(SydApi.RET_CIPHER_KEY));
|
||||
System.out.print("KCV: ");
|
||||
System.out.println(wrapNum.get(SydApi.RET_KCV));
|
||||
|
||||
|
||||
|
||||
String ck = wrapNum.get(SydApi.RET_CIPHER_KEY).toString();
|
||||
RetWrap wrap = api.decryptDE("1000000020", ck);
|
||||
System.out.print("Session Key : ");
|
||||
System.out.println(wrap.get(SydApi.RET_SESSION_KEY));
|
||||
String sk = (String) wrap.get(SydApi.RET_SESSION_KEY);
|
||||
|
||||
System.out.print("KCV : ");
|
||||
System.out.println(wrap.get(SydApi.RET_KCV));
|
||||
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 -----");
|
||||
byte[] enSm4Data = api.SYMEncryptData(SydApi.NALG_SM4, sk, testData);
|
||||
System.out.print("密文 : ");
|
||||
System.out.println(Util.bytes2HexString(enSm4Data));
|
||||
|
||||
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 -----");
|
||||
byte[] deSM4Data = api.SYMDecryptData(SydApi.NALG_SM4, sk, enSm4Data);
|
||||
System.out.print("解密 : ");
|
||||
System.out.println(Util.bytes2HexString(deSM4Data));
|
||||
|
||||
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 CBC -----");
|
||||
byte[] enDataCBC = api.SYMEncryptDataCBC(SydApi.NALG_SM4, sk, testData);
|
||||
System.out.print("密文 : ");
|
||||
System.out.println(Util.bytes2HexString(enDataCBC));
|
||||
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 CBC -----");
|
||||
byte[] deDataCBC = api.SYMDecryptDataCBC(SydApi.NALG_SM4, sk, enDataCBC);
|
||||
System.out.print("解密 : ");
|
||||
System.out.println(Util.bytes2HexString(deDataCBC));
|
||||
|
||||
|
||||
}finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.cert.X509;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class TestHAApi {
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
|
||||
|
||||
SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.17.162", 8889 , 1000);
|
||||
|
||||
SydApi4j api = (SydApi4j) new SydApi4j();//.connect("wuyong.fullstack.club" , 8889, null,1000);
|
||||
|
||||
|
||||
|
||||
System.out.println("\n\n----- 获取公钥 () -----");
|
||||
String pk = api.SYD_SM2_Get_Id_PublicKey_HA("1234", 0);
|
||||
System.out.print("\r\n公钥 : ");
|
||||
System.out.println( pk );
|
||||
|
||||
|
||||
String pk1 = api.SYD_SM2_Get_Dn_PublicKey_HA("C=CN,O=Sunyard,OU=8001,CN=8001".getBytes("GBK"), 0);
|
||||
System.out.print("\r\n公钥 : ");
|
||||
System.out.println( pk1 );
|
||||
//
|
||||
//
|
||||
// // 签名
|
||||
String data="<MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>";
|
||||
final String testPubKey = "0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614";
|
||||
// System.out.println("\n\n----- SM2 算法签名 (原始数据) -----");
|
||||
// String sign = api.SYD_SM2_Sign_HA(
|
||||
// "1234",
|
||||
// SydApi.DATA_ORIGIN,
|
||||
// Util.hexString2Bytes(testPubKey),
|
||||
// data.getBytes()
|
||||
// );
|
||||
// System.out.print("\n\n----- SM2 算法签名 结果: ");
|
||||
// System.out.println( sign );
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// System.out.println("\n\n----- SM2 算法验签 (原始数据) -----");
|
||||
// boolean SM2VerifyRet = api.SYD_SM2_Verify_HA(
|
||||
// SydApi.DATA_ORIGIN,
|
||||
// Util.hexString2Bytes(testPubKey), data.getBytes() , sign);
|
||||
// if (SM2VerifyRet){
|
||||
// System.out.println("验签通过");
|
||||
// }else{
|
||||
// System.err.println("验签失败");
|
||||
// throw new RuntimeException("验签失败");
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// // 签名验签 2
|
||||
// System.out.println("\n\n----- 签名验签 2 -----");
|
||||
// String sign2 = api.SYD_SM2_DetachedSign_HA( data.getBytes() , "C=CN,O=Sunyard,OU=8001,CN=8001");
|
||||
// System.out.println( sign2 );
|
||||
|
||||
|
||||
String sign2 = "MIICpQYKKoEcz1UGAQQCAqCCApUwggKRAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIIByTCCAcUwggFooAMCAQICCDyTAAAAAAAlMAwGCCqBHM9VAYN1BQAwJjELMAkGA1UEBhMCQ04xFzAVBgNVBAMMDlN1bnlhcmRTTTJSb290MB4XDTE3MDUxNzAyNTI0NFoXDTIyMDcyNTAyNTI0NFowPTELMAkGA1UEBhMCQ04xEDAOBgNVBAoMB1N1bnlhcmQxDTALBgNVBAsMBDgwMDExDTALBgNVBAMMBDgwMDEwWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAAQ+2joQe3zDXMAFx/vwu05rQ6B+4U42BgPSLsoqYAstD6AwVdQA0SQDAPVGSLhJ0T9QszD/FDUbVkWxNoaCCmW7o2cwZTAOBgNVHQ8BAf8EBAMCAMAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwHwYDVR0jBBgwFoAU93/arv8hxtk6eq2g+6z+AqVO1cEwHQYDVR0OBBYEFAMWZaY2AwaQTNiFLpsa0dyCzBZ6MAwGCCqBHM9VAYN1BQADSQAwRgIhAIl2ZHGfln5hedcousARzZ2yeUjUbxSFMmhMmr5t6Q6nAiEAvqYX/KpIcvnPyB/Yiil+oq6DFdVM6P3vDxBhU/8taXExgaAwgZ0CAQEwMjAmMQswCQYDVQQGEwJDTjEXMBUGA1UEAwwOU3VueWFyZFNNMlJvb3QCCDyTAAAAAAAlMAwGCCqBHM9VAYMRBQAwDQYJKoEcz1UBgi0BBQAERzBFAiATwLIYiylt7xHmBkH6EclrchClxzLlKWC5guxxzkr58gIhANSw+owu8cyypdJtHGrGqjSiB1BVzGva+irUHelx/GbC";
|
||||
sign2 = "MIID7gYKKoEcz1UGAQQCAqCCA94wggPaAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIIC2jCCAtYwggJ6oAMCAQICBUACgAF0MAwGCCqBHM9VAYN1BQAwYTELMAkGA1UEBhMCQ04xMDAuBgNVBAoMJ0NoaW5hIEZpbmFuY2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEgMB4GA1UEAwwXQ0ZDQSBBQ1MgVEVTVCBTTTIgT0NBMzEwHhcNMTcxMTE2MDY1NDQ1WhcNMjIxMTE2MDY1NDQ1WjCBgzELMAkGA1UEBhMCQ04xHDAaBgNVBAoME0NGQ0EgVEVTVCBTTTIgT0NBMzExDjAMBgNVBAsMBVNIQ1BFMRkwFwYDVQQLDBBPcmdhbml6YXRpb25hbC0xMSswKQYDVQQDDCIwNTFA5LiK5rW356Wo5o2u5Lqk5piT5omAQEFBQUFBQUA4MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEYPA9UQRL/ZaThEN0nc3SwkOHw4hPDXG9hZeKiBnNdhgPy1EtX4My2bpNFpYMmQ0nvkJUM4qpJrF7MSqEws6rLaOB+TCB9jA/BggrBgEFBQcBAQQzMDEwLwYIKwYBBQUHMAGGI2h0dHA6Ly9vY3NwdGVzdC5jZmNhLmNvbS5jbjo4MC9vY3NwMB8GA1UdIwQYMBaAFATHvPlZAWk+jDQ2IGIYPN68tbsMMAwGA1UdEwEB/wQCMAAwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovLzIxMC43NC40Mi4zL09DQTMxL1NNMi9jcmwxLmNybDAOBgNVHQ8BAf8EBAMCBsAwHQYDVR0OBBYEFKJnS7XYRDWG9eqXtSzUZXK+De2/MB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDBDAMBggqgRzPVQGDdQUAA0gAMEUCIGaSRoaUSpoH4lW3at1ABluiNwFDH21jHesHmy0F5gjqAiEA0sUykW9E36F3qQ91YDvasQg8EnOMp1idhgt6pq/NUAYxgdgwgdUCAQEwajBhMQswCQYDVQQGEwJDTjEwMC4GA1UECgwnQ2hpbmEgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MSAwHgYDVQQDDBdDRkNBIEFDUyBURVNUIFNNMiBPQ0EzMQIFQAKAAXQwDAYIKoEcz1UBgxEFADANBgkqgRzPVQGCLQEFAARHMEUCIQDH3ePzq4nYJ8pAodJyqPKqCQuQwmOpyj/rWcDILzFj2gIgUW5c9W6jD7u91opMcDwaw4aNEvEtGX6ks5XDIMIkUjI=";
|
||||
|
||||
|
||||
|
||||
// boolean pass = api.SYD_SM2_DetachedVerify_HA( "<MainBody><MsgId><Id>000000000000000201809181000008627</Id><CreDtTm>2018-09-17T19:06:39</CreDtTm></MsgId><CertNtfctnInf><ChngTp>CC00</ChngTp></CertNtfctnInf></MainBody>".getBytes(), sign2 );
|
||||
// System.out.println( pass );
|
||||
|
||||
// // 获取公钥
|
||||
X509 x = api.SYD_Get_X509_CertInfo_HA( "<MainBody><MsgId><Id>000000000000000201809181000008627</Id><CreDtTm>2018-09-17T19:06:39</CreDtTm></MsgId><CertNtfctnInf><ChngTp>CC00</ChngTp></CertNtfctnInf></MainBody>".getBytes(), sign2 );
|
||||
System.out.println( Util.bytes2HexString( x.getPubKey() ) );
|
||||
|
||||
|
||||
String sign3 = api.SYD_SM2_Sign_HA(
|
||||
"1234",
|
||||
SydApi.DATA_ORIGIN,
|
||||
x.getPubKey(),
|
||||
data.getBytes()
|
||||
);
|
||||
System.out.print("\n\n----- SM2 算法签名 结果: ");
|
||||
System.out.println( sign3 );
|
||||
|
||||
System.out.println( api.SYD_SM2_Verify_HA(
|
||||
SydApi.DATA_ORIGIN,
|
||||
x.getPubKey(),
|
||||
"<MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>".getBytes() ,
|
||||
"MEUCIQD59AIVnr01eVm7TQ5zyx6kc1P7OYbVQb50lSL+ydWYcQIgX0/j/Tjim9J8aalnjSK+ljZ60tQ51KDRsuqNUkScZkQ="
|
||||
) );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
801201484D61696E426F64793E3C4D736749643E3C49643E3130313535373030303034303837303230313830393139303030303030303030313C2F49643E3C4372654474546D3E323031382D30392D31395431303A31333A33393C2F4372654474546D3E3C2F4D736749643E3C517279723E3C4D627249643E3130313535373C2F4D627249643E3C427249643E3030303034303837303C2F427249643E3C2F517279723E3C5273706E723E3C4D627249643E3230313539373C2F4D627249643E3C427249643E3030303033393735343C2F427249643E3C2F5273706E723E3C42697A517279496E663E3C51727944743E323031382D30392D31393C2F51727944743E3C51727949643E30303030303030313C2F51727949643E3C436E74733E313233343536EFBC8CE6B58BE8AF953C2F436E74733E3C2F42697A517279496E663E3C2F4D61696E426F64793E01557141694541307355796B57394533364633715139315944766173516738456E4F4D703169646867743670712F4E55415978676467776764554341514577616A42684D517377435159445651514745774A44546A45774D433447413155454367776E51326870626D4567526D6C755957356A6157467349454E6C636E52705A6D6C6A59585270623234675158563061473979615852354D534177486759445651514444426444526B4E42494546445579425552564E5549464E4E4D6942505130457A4D51494651414B4141585177444159494B6F45637A315542677845464144414E42676B7167527A50565147434C514546414152484D455543495144483365507A71346E594A3870416F644A7971504B7143517551776D4F70796A2F72576344494C7A466A32674967555735633957366A44377539316F704D634477617734614E457645744758366B73355844494D496B556A493D0001
|
||||
|
||||
|
||||
801200A83C4D61696E426F64793E3C4D736749643E3C49643E3030303030303030303030303030303230313830393138313030303030383632373C2F49643E3C4372654474546D3E323031382D30392D31375431393A30363A33393C2F4372654474546D3E3C2F4D736749643E3C436572744E746663746E496E663E3C43686E6754703E434330303C2F43686E6754703E3C2F436572744E746663746E496E663E3C2F4D61696E426F64793E
|
||||
0155
|
||||
7141694541307355796B57394533364633715139315944766173516738456E4F4D703169646867743670712F4E55415978676467776764554341514577616A42684D517377435159445651514745774A44546A45774D433447413155454367776E51326870626D4567526D6C755957356A6157467349454E6C636E52705A6D6C6A59585270623234675158563061473979615852354D534177486759445651514444426444526B4E42494546445579425552564E5549464E4E4D6942505130457A4D51494651414B4141585177444159494B6F45637A315542677845464144414E42676B7167527A50565147434C514546414152484D455543495144483365507A71346E594A3870416F644A7971504B7143517551776D4F70796A2F72576344494C7A466A32674967555735633957366A44377539316F704D634477617734614E457645744758366B73355844494D496B556A493D0001
|
||||
801200A83C4D61696E426F64793E3C4D736749643E3C49643E3030303030303030303030303030303230313830393138313030303030383632373C2F49643E3C4372654474546D3E323031382D30392D31375431393A30363A33393C2F4372654474546D3E3C2F4D736749643E3C436572744E746663746E496E663E3C43686E6754703E434330303C2F43686E6754703E3C2F436572744E746663746E496E663E3C2F4D61696E426F64793E
|
||||
0544
|
||||
4D4949443767594B4B6F45637A31554741515143417143434139347767675061416745424D513477444159494B6F45637A315542677845464144414D42676F7167527A5056515942424149426F494943326A43434174597767674A366F414D434151494342554143674146304D41774743437142484D395641594E31425141775954454C4D416B474131554542684D43513034784D44417542674E5642416F4D4A304E6F6157356849455A70626D467559326C68624342445A584A3061575A7059324630615739754945463164476876636D6C30655445674D423447413155454177775851305A445153424251314D6756455654564342545454496754304E424D7A45774868634E4D5463784D5445324D4459314E4451315768634E4D6A49784D5445324D4459314E445131576A4342677A454C4D416B474131554542684D43513034784844416142674E5642416F4D45304E475130456756455654564342545454496754304E424D7A4578446A414D42674E564241734D42564E49513142464D526B77467759445651514C44424250636D6468626D6C365958527062323568624330784D5373774B51594456515144444349774E544641354C694B357257333536576F356F3275354C716B35706954356F6D415145464251554642515541344D466B77457759484B6F5A497A6A3043415159494B6F45637A3155426769304451674145595041395551524C2F5A615468454E306E633353776B4F487734685044584739685A654B69426E4E646867507931457458344D793262704E4670594D6D51306E766B4A554D3471704A7246374D537145777336724C614F422B544342396A412F4267677242674546425163424151517A4D4445774C7759494B775942425155484D41474749326830644841364C79397659334E776447567A6443356A5A6D4E684C6D4E766253356A626A6F344D43397659334E774D42384741315564497751594D4261414641544876506C5A41576B2B6A44513249474959504E36387462734D4D41774741315564457745422F7751434D4141774E67594456523066424338774C5441726F436D674A34596C6148523063446F764C7A49784D4334334E4334304D69347A4C30394451544D784C314E4E4D69396A636D77784C6D4E796244414F42
|
||||
|
||||
|
||||
|
||||
3045022012D85D4913F0628CFBEBC562DD31D2F18A92EFB5F019DACA916E7A55
|
||||
|
||||
1205CFF4022100D2AA5BEA6D173AE640D9C3F0FA17199C8D4F4D36E1EBFE132E1B38DF7AD35988
|
||||
|
||||
3045022012D85D4913F0628CFBEBC562DD31D2F18A92EFB5F019DACA916E7A55
|
||||
|
||||
1205CFF4022100D2AA5BEA6D173AE640D9C3F0FA17199C8D4F4D36E1EBFE132E
|
||||
|
||||
0220
|
||||
30440220
|
||||
|
||||
3044
|
||||
0220
|
||||
3045
|
||||
0220
|
||||
12D85D4913F0628CFBEBC562DD31D2F18A92EFB5F019DACA916E7A5502201205CFF4
|
||||
0221
|
||||
00D2AA5BEA6D173AE640D9C3F0FA17199C8D4F4D36E1EBFE132E
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
30440220
|
||||
|
||||
3045022012D85D4913F0628CFBEBC562DD31D2F18A92EFB5F019DACA916E7A551205CFF4022100D2AA5BEA6D173AE640D9C3F0FA17199C8D4F4D36E1EBFE132E
|
||||
3045022012D85D4913F0628CFBEBC562DD31D2F18A92EFB5F019DACA916E7A551205CFF4022100D2AA5BEA6D173AE640D9C3F0FA17199C8D4F4D36E1EBFE132E1B38DF7AD35988
|
||||
*/
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
|
||||
public class TestIt
|
||||
{
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
|
||||
System.out.println("SydApi 测试程序启动");
|
||||
|
||||
System.setProperty("com.sunyard.sydapi4j.debug","true");
|
||||
|
||||
|
||||
SydApi key = new SydApi4j().connect("172.16.18.73",8889,null,10000);
|
||||
System.out.println("连接成功");
|
||||
|
||||
/* //原始数据
|
||||
byte[] data = "asfkahfkahfkahdaghfashflsaldfasf".getBytes();
|
||||
//X509 证书的序列号
|
||||
String pCertSerial = "112233";
|
||||
//数据明文
|
||||
byte[] data2 = "asfkahfkahfkafadfhdaghfashadfaflsaldfasf".substring(0,32).getBytes();
|
||||
//PKCS1签名
|
||||
String netSign = key.netSign(pCertSerial, data);
|
||||
//PKCS1验签
|
||||
key.netVerify(pCertSerial,data,netSign);
|
||||
//PKCS#7签名
|
||||
String s = key.detachedSign(1, data, "DN");
|
||||
//PKCS#7验签
|
||||
key.detachedVerify(1,data,s);*/
|
||||
//生成数字信封
|
||||
RetWrap retWrap = key.generateDE("1004282452", (byte)1);
|
||||
String cipherKey = (String)retWrap.get("CipherKey");
|
||||
String seesionKey = (String) retWrap.get("SessionKey");
|
||||
//解密数字信封
|
||||
key.decryptDE("1004282452",cipherKey );
|
||||
//对称密钥加密-ECB
|
||||
// byte[] bytes = key.SYMEncryptData(1, seesionKey, data2);
|
||||
//对称密钥解密-ECB
|
||||
// key.SYMDecryptData(1,seesionKey,bytes);
|
||||
/* // 将PINBLOCK从一个密钥翻译到另一个密钥
|
||||
String srcKey = "000000000000000200A00000000"; // 源秘钥
|
||||
String desKey = seesionKey; // 目的秘钥
|
||||
String sPin = "2DECE6BA4A4A3EE51A10B0419E9595C9"; // 源Pin块
|
||||
String primaryAccount = "123456789012"; // 主账号
|
||||
byte[] bytePin = key.transPinFrOneKeyToAno(srcKey, desKey, 2, sPin, primaryAccount);*/
|
||||
System.out.println("执行结束\n\n" );
|
||||
key.disconnect();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
public class TestKey2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
SydApi hsm1 = (new SydApi4j()).connect("172.16.17.162", 8889,null , 10000);
|
||||
SydApi hsm2 = (new SydApi4j()).connect("172.16.18.72", 8889,null , 10000);
|
||||
|
||||
String hsm1_pk = "03420004DBF3A1BD52F4AC06E8F18A988104CC25F5F8DE85AA0BFFEE076CA6547C5C98CD49153C6B3F67A801F961890028AFF378A4F82166FDF6D2F02BDC17E6519FD09B";
|
||||
String hsm1_sk = "000100001EB9A893ED4589EA1AEF84D24EA52EE13FE1AE60D20E3BC9B3B0B87BDF1F14180000000000000000000000000000000000000000000000000000000000000000";
|
||||
|
||||
|
||||
String hsm2_pk = "0342000401A256CE599BDC6DFBD87FDB3D04F303A506EFE7E1A0569634703770BD4272C52B3BBCC13283B46204CA4EA34F7EA21764CDFC0AFCB8521BAEE6BD58DD8C4FB8";
|
||||
String hsm2_sk = "00010000EF3C17C8D971D52CD9F9561AA698CE1A28AD4894A73BE7F711BC3CCE6659BC730000000000000000000000000000000000000000000000000000000000000000";
|
||||
|
||||
|
||||
// 中心端
|
||||
String hsm1_keyA = "S6F91526D7E311230A768A31BB55C44FF"; // BBA1836255B9698C
|
||||
|
||||
String hsm1_keyB = "S01A6A301EAFB237CD87012C0FA8CCACA"; // 87F88C219C74B08FD6950081CCB5DAD5
|
||||
|
||||
|
||||
// S3DE99F29940CA73A4878CB36EE988ECB
|
||||
|
||||
// 会员端
|
||||
String hsm2_keyA = "SFB3989DB9783869658BC31CC8DB1D2DC"; // BBA1836255B9698C293987AA427D8E17
|
||||
|
||||
String hsm2_keyB = "SE0A2D5BDA20299CE687EB8EC87F1D4C3"; // 87F88C219C74B08F
|
||||
|
||||
// S39A06BA1B157DD513B97907AA5DD2EEF
|
||||
|
||||
|
||||
try {
|
||||
|
||||
|
||||
|
||||
byte[] o = hsm2.SYMDecryptDataCBC(0x01, hsm2_keyA, Util.hexString2Bytes("4649F0894D0905D8F7DA4E5D8B9CE3BA") );
|
||||
|
||||
|
||||
System.out.println( Util.bytes2HexString( o ) );
|
||||
System.out.println( new String( o ) );
|
||||
|
||||
|
||||
byte[] o1 = hsm1.SYMDecryptDataCBC(0x01, hsm1_keyA, Util.hexString2Bytes("4649F0894D0905D8F7DA4E5D8B9CE3BA") );
|
||||
|
||||
|
||||
System.out.println( Util.bytes2HexString( o1 ) );
|
||||
System.out.println( new String( o1 ) );
|
||||
|
||||
}finally {
|
||||
|
||||
hsm1.disconnect();
|
||||
hsm2.disconnect();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
public class TestKeyTool {
|
||||
|
||||
//4649F0894D0905D8F7DA4E5D8B9CE3BA
|
||||
public static void main(String[] args) {
|
||||
|
||||
SydApi hsm1 = (new SydApi4j()).connect("172.16.17.162", 8889,null , 10000);
|
||||
SydApi hsm2 = (new SydApi4j()).connect("172.16.18.72", 8889,null , 10000);
|
||||
|
||||
String hsm1_pk = "03420004DBF3A1BD52F4AC06E8F18A988104CC25F5F8DE85AA0BFFEE076CA6547C5C98CD49153C6B3F67A801F961890028AFF378A4F82166FDF6D2F02BDC17E6519FD09B";
|
||||
String hsm1_sk = "000100001EB9A893ED4589EA1AEF84D24EA52EE13FE1AE60D20E3BC9B3B0B87BDF1F14180000000000000000000000000000000000000000000000000000000000000000";
|
||||
|
||||
|
||||
String hsm2_pk = "0342000401A256CE599BDC6DFBD87FDB3D04F303A506EFE7E1A0569634703770BD4272C52B3BBCC13283B46204CA4EA34F7EA21764CDFC0AFCB8521BAEE6BD58DD8C4FB8";
|
||||
String hsm2_sk = "00010000EF3C17C8D971D52CD9F9561AA698CE1A28AD4894A73BE7F711BC3CCE6659BC730000000000000000000000000000000000000000000000000000000000000000";
|
||||
|
||||
|
||||
// 中心端
|
||||
String hsm1_keyA = "S8B28E4D9E92250209E9CF2F36663911D"; // BBA1836255B9698C
|
||||
|
||||
String hsm1_keyB = "S01A6A301EAFB237CD87012C0FA8CCACA"; // 87F88C219C74B08FD6950081CCB5DAD5
|
||||
|
||||
|
||||
// S3DE99F29940CA73A4878CB36EE988ECB
|
||||
|
||||
// 会员端
|
||||
String hsm2_keyA = "S1423772EC5960B0054D946279E172F36"; // BBA1836255B9698C293987AA427D8E17
|
||||
|
||||
String hsm2_keyB = "SE0A2D5BDA20299CE687EB8EC87F1D4C3"; // 87F88C219C74B08F
|
||||
|
||||
// S39A06BA1B157DD513B97907AA5DD2EEF
|
||||
|
||||
|
||||
try {
|
||||
|
||||
|
||||
|
||||
// RetWrap ret = hsm1.mixKey( hsm1_keyA, hsm1_keyB , "S" );
|
||||
//
|
||||
//
|
||||
// System.out.println( ret );
|
||||
//
|
||||
//
|
||||
// ret = hsm2.mixKey( hsm2_keyA, hsm2_keyB , "S" );
|
||||
//
|
||||
//
|
||||
// System.out.println( ret );
|
||||
|
||||
|
||||
// RetWrap ret = hsm1.SM2GenKeyPair();
|
||||
// String VK1 = Util.bytes2HexString((byte[]) ret.get("PublicKey"));
|
||||
// String SK1 = Util.bytes2HexString((byte[]) ret.get("PrivateKey"));
|
||||
//
|
||||
//
|
||||
//
|
||||
// String key2 = "S31A82D54F09B237D648B2F84347777C5";
|
||||
//
|
||||
//
|
||||
//
|
||||
// // lmk -> pken
|
||||
// String ek = hsm2.enKeyPk( VK1 , key2 );
|
||||
// System.out.println( ek );
|
||||
//
|
||||
// ret = hsm1.deKeyEx( SK1 , ek , "S");
|
||||
// String key1 = ret.get("lmk").toString();
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// System.out.println( key1 );
|
||||
// System.out.println( key2 );
|
||||
|
||||
|
||||
String key1 = "S376A03994307D447C63A225A2ADB1591";
|
||||
String key2 = "S1DE03BBD17083DABD4C1BF7ECD2D9193";
|
||||
|
||||
|
||||
// byte[] en1 = hsm1.SYMEncryptDataCBC(0x01, key1, "huangqian".getBytes() );
|
||||
// byte[] en2 = hsm2.SYMEncryptDataCBC(0x01, key2, "huangqian".getBytes() );
|
||||
//
|
||||
//
|
||||
// System.out.println( Util.bytes2HexString( en1 ) );
|
||||
// System.out.println( Util.bytes2HexString( en2 ) );
|
||||
|
||||
|
||||
byte[] w = new byte[0];//hsm2.SYMEncryptDataCBC( 0x01, key2, "<xml>d</xml>".getBytes() , Util.bytes2HexString("SHANGPIAOJIAOSUO".getBytes()).getBytes() );
|
||||
|
||||
|
||||
System.out.println( Util.bytes2HexString( w ) );
|
||||
|
||||
|
||||
byte[] o = hsm2.SYMDecryptDataCBC(0x01, key2, Util.hexString2Bytes("B8ACEBD675B5CBB5BCEAAE5BF41A9F813BE4CD94BA07745728E688FE8C27FE9C") );
|
||||
|
||||
|
||||
System.out.println( Util.bytes2HexString( o ) );
|
||||
System.out.println( new String( o ) );
|
||||
|
||||
|
||||
byte[] o1 = hsm1.SYMDecryptDataCBC(0x01, key1, Util.hexString2Bytes("B8ACEBD675B5CBB5BCEAAE5BF41A9F813BE4CD94BA07745728E688FE8C27FE9C") );
|
||||
|
||||
|
||||
System.out.println( Util.bytes2HexString( o1 ) );
|
||||
System.out.println( new String( o1 ) );
|
||||
|
||||
}finally {
|
||||
|
||||
hsm1.disconnect();
|
||||
hsm2.disconnect();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,816 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
public class TestLast {
|
||||
SydApi4j api;
|
||||
String keyTye = "000";
|
||||
String key1 = "1234567812345678";
|
||||
String key2 = "X12345678123456781234567812345678";
|
||||
String key6 = "U00000000000000000000000000000000";
|
||||
String key3 = "Y123456781234567812345678123456781234567812345678";
|
||||
String key4 = "X87654321876543218765432187654321";
|
||||
String key5 = "1234567812345678";
|
||||
String key7 = "12345678123456781234567812345678";
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.17.162", 8889, null, 1000);
|
||||
|
||||
String keyTye = "000";
|
||||
String key1 = "1234567812345678";
|
||||
String key2 = "X12345678123456781234567812345678";
|
||||
String key6 = "U00000000000000000000000000000000";
|
||||
String key3 = "Y123456781234567812345678123456781234567812345678";
|
||||
String key4 = "X87654321876543218765432187654321";
|
||||
String key5 = "1234567812345678";
|
||||
String key7 = "12345678123456781234567812345678";
|
||||
|
||||
/* //RetWrap retWrap = api.conversionKey("000", key2, 'X'); ->pass
|
||||
//2.2由2到9个ZMK成份组成一个ZMK(=) GY-> : code = 23 ( 0x17 ) msg = 未定义的错误
|
||||
String s1 = Util.bytes2HexString(key1.getBytes());
|
||||
String s2 = Util.bytes2HexString(key1.getBytes());
|
||||
RetWrap retWrap= api.genComposeKey(new String[]{s1,s2});
|
||||
System.out.println(retWrap);*//*
|
||||
//将ZMK由ZMK转为LMK加密(+) BY -> pass
|
||||
// RetWrap retWrap = api.changZMK2LMK( key2, key1);
|
||||
//获取加密机cpu,内存,磁盘使用状况 HI ->接收数据超时
|
||||
// RetWrap retWrap = api.getStatus();
|
||||
//24.2获取加密机设备信息 -> pass
|
||||
//RetWrap retWrap = api.getVersion("1234");
|
||||
//22.1计算HASH散列值(HMAC-MD5\SHA1\SHA256)(+) ->code = 129 ( 0x81 ) msg = 未定义的错误 等待消息
|
||||
// RetWrap retWrap = api.CalcHash(key1, 2, "0000",new byte[]{001,010});
|
||||
//System.out.println(retWrap);
|
||||
//二十一章,80,81,7E三条指令 -> code = 33 ( 0x21 ) msg = 检索的数据或密钥不存在*/
|
||||
/**/
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
*/
|
||||
/* */
|
||||
|
||||
/**/
|
||||
|
||||
/* */
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
/* RetWrap retWrap = api.SM2GenKeyPair();
|
||||
String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey"));
|
||||
String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"));
|
||||
System.out.println(pk);
|
||||
System.out.println(sk);*/
|
||||
|
||||
/*RetWrap retWrap = api.SM2OrRSAGenKeyPair(1,"006",256);
|
||||
String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey"));
|
||||
String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"));
|
||||
System.out.println(pk);
|
||||
System.out.println(sk);
|
||||
|
||||
//15.7计算HASH散列值(MD5\SHA1\SHA256)(+) -> pass
|
||||
RetWrap retWrap2 = api.conutHash(1,0, key2.getBytes(), key1.getBytes());
|
||||
String hash = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap2.get("hash"))));
|
||||
System.out.println(hash);
|
||||
|
||||
/* //15.3私钥加密指令(?) -> code = 13 ( 0xd ) msg = 未定义的错误(无返回加密数据)
|
||||
byte[] bytes = api.encryptBySk(0, sk, "001".getBytes());
|
||||
System.out.println(bytes);
|
||||
|
||||
byte[] bytes1 = api.decryptByPk(0, pk, bytes);
|
||||
System.out.println(new String(bytes1));*/
|
||||
|
||||
/*//每一次重新生成都要更换索引值
|
||||
RetWrap retWrap = api.SM2OrRSAGenKeyPair(0,"0000000000000005",1024);
|
||||
System.out.println(Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")));
|
||||
//获取私钥
|
||||
String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"));
|
||||
System.out.println("sk:"+sk);
|
||||
//获取公钥
|
||||
String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey"));
|
||||
System.out.println("pk:"+pk);
|
||||
|
||||
//15.7计算HASH散列值(MD5\SHA1\SHA256)(+) -> pass
|
||||
RetWrap retWrap1 = api.conutHash(1,0, key2.getBytes(), key1.getBytes());
|
||||
String hash = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("hash"))));
|
||||
System.out.println(hash);
|
||||
System.out.println(retWrap1);
|
||||
|
||||
//15.5 RSA私钥签名(+) -> pass
|
||||
byte[] bytes = api.RSASignC("0000000000000005", 1, 0,(byte[]) retWrap1.get("hash"));
|
||||
System.out.println(bytes);
|
||||
//15.6 RSA验证签名(+) -> pass
|
||||
boolean hash1 = api.RSAVerify(1, 0, (byte[]) retWrap.get("PublicKey"), (byte[]) retWrap1.get("hash"), bytes);
|
||||
System.out.println(hash1);*/
|
||||
|
||||
|
||||
/* //10.1装载对称密钥至用户存储区(=) -> pass
|
||||
RetWrap retWrap1 = api.genSymmetricKey(keyTye, 'X');
|
||||
String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey"))));
|
||||
String keyCheck = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("keyCheck"))));
|
||||
System.out.println(lmkKey);
|
||||
System.out.println(keyCheck);
|
||||
Boolean loadKey = api.loadKey("999999999999999900000000003", lmkKey,keyCheck);
|
||||
System.out.println(loadKey);*/
|
||||
|
||||
/*//10.2从用户存储区读取对称密钥(=) -> pass
|
||||
RetWrap retWrap1 = api.readKey("999999999999999900000000003");
|
||||
System.out.println(retWrap1);
|
||||
System.out.println(retWrap1.get("key"));
|
||||
String key = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("key"))));
|
||||
System.out.println(key);*/
|
||||
|
||||
/*//10.3更新对称密钥至用户存储区(=) -> pass
|
||||
RetWrap retWrap1 = api.genSymmetricKey(keyTye, 'X');
|
||||
String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey"))));
|
||||
String keyCheck = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("keyCheck"))));
|
||||
System.out.println(lmkKey);
|
||||
System.out.println(keyCheck);
|
||||
Boolean updateKey = api.updateKey("999999999999999900000000012", lmkKey,keyCheck);
|
||||
System.out.println(updateKey);*/
|
||||
|
||||
|
||||
/*//9.2 数据转加密指令(Y0)(=) -> pass 密文数据那项不一定需要传加密出来的数据
|
||||
//生成DEK
|
||||
RetWrap retWrap1 = api.genSymmetricKey("000", 'X');
|
||||
System.out.println("sDEK:"+ new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey")))));
|
||||
String sDEK = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey"))));
|
||||
|
||||
RetWrap retWrap2 = api.genSymmetricKey("000", 'X');
|
||||
String dDEK = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap2.get("lmkKey"))));
|
||||
System.out.println("dDEK:"+dDEK);
|
||||
|
||||
byte[] bytes1 = api.switchEncryY("000", 1, "000", 1, 2, sDEK, dDEK, key1.getBytes(), key1);
|
||||
System.out.println(new String(key1.getBytes()));
|
||||
System.out.println(bytes1);*/
|
||||
|
||||
|
||||
/* //8.3用对大消息生成MAC(MAB)(*) -> pass
|
||||
//8.4对大消息生成MAC(MAB)(PBOC3.0方式)(*) -> pass
|
||||
//生成TAK
|
||||
RetWrap retWrap = api.genTAK(key2);
|
||||
System.out.println(retWrap);
|
||||
String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey"))));
|
||||
System.out.println(lmkKey);
|
||||
String tmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("tmkKey"))));
|
||||
System.out.println(tmkKey);
|
||||
|
||||
byte[] bytes = api._calcPBOCMAC(0, 0, lmkKey, key1.getBytes(), 0, key1.getBytes());
|
||||
System.out.println(bytes);
|
||||
|
||||
RetWrap retWrap1 = api.genMAB(0, 0, 0, lmkKey, key1.getBytes(), key1.getBytes());
|
||||
System.out.println(retWrap1);
|
||||
*/
|
||||
|
||||
/* //7.1生成一个随机的PIN(=) -> pass 不能传算法标识和加密算法这两项,否则报错
|
||||
String s = api.genPIN("123456789123");
|
||||
System.out.println(s);*/
|
||||
|
||||
/* //7.2解密PINBLOCK, 并打印PIN 明文(=) -> : code = -2 ( 0xfffffffe ) msg = 接收数据超时
|
||||
String s = api.genPIN("123456789123");
|
||||
System.out.println(s);
|
||||
Boolean c = api.decryPINBAndPrint('B', "123456789123", 1, s);
|
||||
System.out.println(c);
|
||||
*/
|
||||
|
||||
/* //生成: LMK对(02-03)下加密的导出PINBLOCK
|
||||
String account="123456789123";
|
||||
String s1 = api.genPIN(account);
|
||||
System.out.println("7.1LMK对(02-03)下加密的导出PINBLOCK:"+s1);
|
||||
//7.5将PINBLOCK从LMK翻译到ZPK(*) ->pass
|
||||
String s2 = api.transPINFromLMKToZPK(key4, 0, 1, 01, s1, account);
|
||||
System.out.println("7.5将PINBLOCK从LMK翻译到ZPK(*):"+s2);
|
||||
//7.3将PINBLOCK从一个ZPK翻译到另一个ZPK(*) ->pass
|
||||
String s3 = api.transPINFromZPKToZPK(key4, key2, 1, 1,01,01, s2, account);
|
||||
System.out.println("7.3将PINBLOCK从一个ZPK翻译到另一个ZPK(*)"+s3);
|
||||
//7.4将PINBLOCK从ZPK翻译到LMK(*) ->pass
|
||||
String s4 = api.transPINFromZPKToLMK(key2, 1, 1, 01, s3, account);
|
||||
System.out.println("7.4将PINBLOCK从ZPK翻译到LMK(*)"+s4);*/
|
||||
/* //7.6将PINBLOCK从TPK翻译到ZPK(=) -> pass
|
||||
String s2 = api.transPINFromLMKToZPK(key4, 0, 0, 01, s1, account);
|
||||
System.out.println("7.5将PINBLOCK从LMK翻译到ZPK(*):"+s2);
|
||||
String s10 = api.transPinFrOneKeyToAno("001", "002", key4, key2, 0, 0, s2, account);
|
||||
System.out.println("LMK对(14-15)下加密:"+s10);
|
||||
String s6 = api.transPINFromTPKToZPK(key2, key4, 0, 0, 01, 01, s10, account);
|
||||
System.out.println("7.6将PINBLOCK从TPK翻译到ZPK(=):"+s6);*/
|
||||
/*//7.7将PINBLOCK从TPK翻译到LMK(=) -> pass
|
||||
String s2 = api.transPINFromLMKToZPK(key4, 0, 0, 01, s1, account);
|
||||
System.out.println("7.5将PINBLOCK从LMK翻译到ZPK(*):"+s2);
|
||||
String s10 = api.transPinFrOneKeyToAno("001", "002", key4, key2, 0, 0, s2, account);
|
||||
System.out.println("LMK对(14-15)下加密:"+s10);
|
||||
String s7 = api.transPINFromTPKToLMK(key2, 0, 1, 01, s10, account);
|
||||
System.out.println("7.7将PINBLOCK从TPK翻译到LMK(=):"+s7);*/
|
||||
/* //7.8 加密一个明文的PIN(*) -> pass
|
||||
String s2 = api.encryPIN(0, "06123486FFFFFFFF", account);
|
||||
System.out.println(s2);
|
||||
//7.9解密一个已加密的PIN(*) -> 只解出原PIn,缺少参考数这一项
|
||||
String s3 = api.decryPIN(0, s2, account);
|
||||
System.out.println(s3);*/
|
||||
/* //7.10将PINBLOCK从一个密钥翻译到另一个密钥 -> pass
|
||||
String s2 = api.transPINFromLMKToZPK(key4, 0, 0, 01, s1, account);
|
||||
System.out.println("7.5将PINBLOCK从LMK翻译到ZPK(*):"+s2);
|
||||
String s = api.transPinFrOneKeyToAno("001", "001", key4, key2, 0, 0, s2, account);
|
||||
System.out.println(s);*/
|
||||
|
||||
/*//6.1生成一个TAK(=) : -> pass
|
||||
RetWrap retWrap = api.genSymmetricKey("002", 'Z');
|
||||
String tmk = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey"))));
|
||||
String keyCheck = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("keyCheck"))));
|
||||
System.out.println("tmk:"+tmk);
|
||||
System.out.println(keyCheck);
|
||||
RetWrap retWrap1 = api.genTAK(tmk);
|
||||
System.out.println(retWrap1);
|
||||
String lmk = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey"))));
|
||||
System.out.println("lmk:"+lmk);
|
||||
String tmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("tmkKey"))));
|
||||
System.out.println("tmk:"+tmkKey);
|
||||
//6.3将TAK从LMK转为ZMK加密(=) -> PASS
|
||||
RetWrap retWrap2 = api.transTAKFromLMKToZMK(key2, lmk);
|
||||
System.out.println(retWrap2);
|
||||
String zmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap2.get("zmkKey"))));
|
||||
System.out.println("6.3将TAK从LMK转为ZMK加密,zmkKey:"+zmkKey);
|
||||
//6.2将TAK从ZMK转为LMK加密(=) -> pass
|
||||
RetWrap retWrap3 = api.transTAKFromZMKToLMK(key2, zmkKey);
|
||||
System.out.println(retWrap3);
|
||||
String lmkKey3 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap3.get("lmkKey"))));
|
||||
System.out.println("6.2将TAK从ZMK转为LMK加密(=),lmkKey3:"+lmkKey3);
|
||||
//6.4将TAK从LMK转为TMK加密(=) -> PASS
|
||||
RetWrap retWrap4 = api.transTAKFromLMKToTMK(tmk, lmkKey3);
|
||||
System.out.println(retWrap4);
|
||||
String tmkKey4 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap4.get("tmkKey"))));
|
||||
System.out.println("6.4将TAK从LMK转为TMK加密,tmkKey4:"+tmkKey4);*/
|
||||
|
||||
/*//5.1生成一个TMK、TPK或PVK加密下的新密钥(=) -> PASS
|
||||
RetWrap retWrap = api.genSymmetricKey("002", 'Z');
|
||||
String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey"))));
|
||||
String keyCheck = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("keyCheck"))));
|
||||
System.out.println(lmkKey);
|
||||
System.out.println(keyCheck);
|
||||
RetWrap retWrap1 = api.genKeyByTMKOrTPKOrPVK(lmkKey);
|
||||
System.out.println(retWrap1);
|
||||
String lmkKey1 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey"))));
|
||||
String tmkKey1 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("tmkKey"))));
|
||||
System.out.println("当前的TMK (TPK或PVK)下加密的新密钥,tmkKey1:"+tmkKey1);
|
||||
System.out.println("LMK下加密的新密钥,lmkKey1:"+lmkKey1);
|
||||
//5.2将TMK、TPK或PVK从LMK转为另一TMK、TPK或PVK加密(+) -> PASS
|
||||
RetWrap retWrap2 = api.genSymmetricKey("002", 'Z');
|
||||
String lmkKey2 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey"))));
|
||||
RetWrap retWrap22 = api.tranKeyByTMKToAno(tmkKey1, lmkKey2);
|
||||
System.out.println(retWrap22);
|
||||
String tmkKey2 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap22.get("tmkKey"))));
|
||||
System.out.println("tmkKey2:"+tmkKey2);
|
||||
//5.4将TMK、TPK或PVK从LMK转为ZMK加密(=) ->PASS
|
||||
RetWrap retWrap4 = api.tranKeyByTMKFromLMKToZMK(key2, tmkKey2);
|
||||
System.out.println(retWrap4);
|
||||
String tmkKey4 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap4.get("tmkKey"))));
|
||||
System.out.println("5.4将TMK、TPK或PVK从LMK转为ZMK加密,tmkKey4:"+tmkKey4);
|
||||
//5.3将TMK、TPK或PVK从ZMK转为LMK加密(=) -> PASS
|
||||
RetWrap retWrap3 = api.tranKeyByTMKFromZMKToLMK(key2, tmkKey4);
|
||||
System.out.println(retWrap3);
|
||||
String tmkKey3 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap3.get("tmkKey"))));
|
||||
System.out.println("5.3将TMK、TPK或PVK从ZMK转为LMK加密(=):"+tmkKey3);*/
|
||||
|
||||
/* //4.1生成一个ZEK/ZAK(=) ->pass
|
||||
RetWrap retWrap = api.genZEKOrZAK(0, key2);
|
||||
System.out.println(retWrap);
|
||||
String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey"))));
|
||||
String zmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("zmkKey"))));
|
||||
System.out.println("lmkKey:"+lmkKey);
|
||||
System.out.println("zmkKey:"+zmkKey);
|
||||
|
||||
//4.2将ZEK/ZAK从ZMK转为LMK加密(=) -> pass
|
||||
RetWrap retWrap1 = api.tranZEAKFromZMKToLMK(0, key2, zmkKey);
|
||||
System.out.println(retWrap1);
|
||||
String lmkKey1 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey"))));
|
||||
System.out.println("4.2将ZEK/ZAK从ZMK转为LMK加密,lmkKey1:"+lmkKey1);
|
||||
|
||||
//4.3将ZEK/ZAK从LMK转为ZMK加密(=) -> pass
|
||||
RetWrap retWrap2 = api.tranZEAKFromLMKToZMK(0, key2, lmkKey);
|
||||
System.out.println(retWrap2);
|
||||
String zmkKey1 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap2.get("zmkKey"))));
|
||||
System.out.println("4.3将ZEK/ZAK从LMK转为ZMK加密,zmkKey1:"+zmkKey1);*/
|
||||
|
||||
/*//3.1生成一个ZPK(=) -> pass
|
||||
RetWrap retWrap = api.genZPK(key2);
|
||||
System.out.println(retWrap);
|
||||
String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey"))));
|
||||
String zmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("zmkKey"))));
|
||||
System.out.println("lmkKey:"+lmkKey);
|
||||
System.out.println("zmkKey:"+zmkKey);
|
||||
//3.2将ZPK由ZMK转为LMK加密(=)-> pass
|
||||
RetWrap retWrap1 = api.tranZPKFromZMKToLMK(key2, zmkKey);
|
||||
System.out.println(retWrap1);
|
||||
String zpkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("zpkKey"))));
|
||||
System.out.println("3.2将ZPK由ZMK转为LMK加密,zpkKey:"+zpkKey);
|
||||
//3.3将ZPK由LMK转为ZMK加密-> pass
|
||||
RetWrap retWrap2 = api.tranZPKFromLMKToZMK(key2, lmkKey);
|
||||
System.out.println(retWrap2);
|
||||
String zpkKey1 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap2.get("zpkKey"))));
|
||||
System.out.println("3.3将ZPK由LMK转为ZMK加密,zpkKey:"+zpkKey1);*/
|
||||
|
||||
/* //2.1生成并打印一个ZMK成份(=) -> : code = 23 ( 0x17 ) msg = 未定义的错误
|
||||
RetWrap retWrap = api.genZMKAndPrint();
|
||||
System.out.println(retWrap);
|
||||
//2.3将ZMK由ZMK转为LMK加密(+) BY -> pass
|
||||
RetWrap retWrap = api.changZMK2LMK( key2, key1);
|
||||
System.out.println(retWrap);
|
||||
String zmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("zmkKey"))));
|
||||
System.out.println(zmkKey);*/
|
||||
|
||||
/*//1.4由2-9个密钥成份组成一个密钥(=) ->: code = 23 ( 0x17 ) msg = 未定义的错误
|
||||
String s1 = Util.bytes2HexString(key2.getBytes());
|
||||
String s2 = Util.bytes2HexString(key2.getBytes());
|
||||
RetWrap retWrap = api.composeKey(keyTye, new String[]{s1, s2});
|
||||
System.out.println(retWrap);*/
|
||||
/* //1.1生成一个对称密钥(*) -> pass
|
||||
RetWrap retWrap = api.genSymKey(1,keyTye, 'X',key2);
|
||||
System.out.println(retWrap);
|
||||
String zmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("zmkKey"))));
|
||||
System.out.println(zmkKey);
|
||||
String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey"))));
|
||||
System.out.println(lmkKey);*/
|
||||
/*//2.2生成并打印一个成份(=) ->: code = 23 ( 0x17 ) msg = 未定义的错误
|
||||
RetWrap retWrap = api.genAndPrint(keyTye, "X");
|
||||
System.out.println(retWrap);*/
|
||||
/*//1.3生成一个密钥并以分开的成份形式打印(=) -> : code = -2 ( 0xfffffffe ) msg = 接收数据超时
|
||||
RetWrap retWrap = api.genAndPrintSplit(keyTye, 'X');
|
||||
System.out.println(retWrap);*/
|
||||
/* //1.5输入一个密钥(*) -> pass
|
||||
RetWrap retWrap1 = api.inputKey(keyTye, 'X', key1, zmkKey);
|
||||
System.out.println(retWrap1);
|
||||
String lmkKey1 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("key"))));
|
||||
System.out.println(lmkKey1);
|
||||
//1.6输出一个密钥(*)-> pass
|
||||
RetWrap retWrap2 = api.outputKey(keyTye, 'X', key2, lmkKey);
|
||||
System.out.println(retWrap2);
|
||||
String zmkKey2 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap2.get("key"))));
|
||||
System.out.println(zmkKey2);
|
||||
//1.7转换密钥方案(+) ->PASS
|
||||
RetWrap retWrap3 = api.conversionKey(keyTye, lmkKey, 'S');
|
||||
System.out.println(retWrap3);
|
||||
String lmkkey3 = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap3.get("lmkkey"))));
|
||||
System.out.println(lmkkey3);
|
||||
//1.8密钥合成(*,安徽农信) ->PASS
|
||||
RetWrap retWrap4 = api.genComposeKey(keyTye, 'Z', key1);
|
||||
System.out.println(retWrap4);
|
||||
String lmkkey4= new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap4.get("lmkKey"))));
|
||||
System.out.println(lmkkey4);*/
|
||||
|
||||
/*//8.1生成一个MAC(=) -> pass
|
||||
RetWrap retWrap = api.genTAK(key2);
|
||||
System.out.println(retWrap);
|
||||
String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey"))));
|
||||
System.out.println(lmkKey);
|
||||
String tmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("tmkKey"))));
|
||||
System.out.println(tmkKey);
|
||||
String s = api.MACCalc(0, 0, lmkKey, 0, key1.getBytes(), 2);
|
||||
System.out.println(s);
|
||||
//8.2校验一个MAC(=) -> pass
|
||||
api.MACCheck(0,0,lmkKey,0,key1.getBytes(),s);*/
|
||||
|
||||
/*//
|
||||
RetWrap retWrap = api.SM2OrRSAGenKeyPair(1,"001",256);
|
||||
System.out.println(Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")));
|
||||
//获取私钥
|
||||
String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"));
|
||||
System.out.println("sk:"+sk);
|
||||
//获取公钥
|
||||
String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey"));
|
||||
System.out.println("pk:"+pk);
|
||||
//15.1公钥加密指令(+) -> pass
|
||||
byte[] bytes = api.encryptByPk(1, pk, "001".getBytes());
|
||||
System.out.println("公钥加密数据:"+Util.bytes2HexString(bytes));
|
||||
//15.2私钥解密指令(+) -> pass
|
||||
byte[] data = api.decryptBySk(1, sk, bytes);
|
||||
System.out.println(new String(data));
|
||||
|
||||
//15.3私钥加密指令(?) -> code = 13 ( 0xd ) msg = 未定义的错误(无返回加密数据)
|
||||
byte[] bytes = api.encryptBySk(1, sk, key7.getBytes());
|
||||
System.out.println(bytes);
|
||||
//15.4公钥解密指令(?) -> 等待15.3
|
||||
byte[] bytes1 = api.decryptByPk(1, pk, bytes);
|
||||
System.out.println(new String(bytes1));*/
|
||||
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
api = (SydApi4j) new SydApi4j().connect("172.16.17.163", 8889, null, 1000);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
try {
|
||||
this.api.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//9.2 数据转加密指令(Y0)(=) -> pass 密文数据那项不一定需要传加密出来的数据
|
||||
@Test
|
||||
public void switchEncryY() {
|
||||
/* //生成DEK
|
||||
RetWrap retWrap = api.genSymmetricKey("100", 'X');
|
||||
System.out.println(new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey")))));
|
||||
String DEK = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey"))));
|
||||
|
||||
byte[] bytes = api.SYMEncryptDataCBC(1,DEK, "001".getBytes());
|
||||
System.out.println("加密:"+Util.bytes2HexString(bytes));
|
||||
|
||||
byte[] bytesx = api.SYMDecryptDataCBC(1, DEK, bytes);
|
||||
System.out.println("解密:"+Util.bytes2HexString(bytesx));*/
|
||||
|
||||
//生成DEK
|
||||
RetWrap retWrap1 = api.genSymmetricKey("000", 'X');
|
||||
System.out.println("sDEK:" + new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey")))));
|
||||
String sDEK = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey"))));
|
||||
|
||||
RetWrap retWrap2 = api.genSymmetricKey("002", 'X');
|
||||
String dDEK = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap2.get("lmkKey"))));
|
||||
System.out.println("dDEK:" + dDEK);
|
||||
|
||||
byte[] bytes1 = api.switchEncryY("000", 1, "002", 1, 2, sDEK, dDEK, "0000000000123123".getBytes(), "9965432112345699");
|
||||
String cipherData = new String(Util.hexString2Bytes(Util.bytes2HexString(bytes1)));
|
||||
System.out.println(cipherData);
|
||||
}
|
||||
|
||||
/* //10.1装载对称密钥至用户存储区(=) -> pass(需更换索引地址)
|
||||
@Test
|
||||
public void loadKey(){
|
||||
RetWrap retWrap1 = api.genSymmetricKey(keyTye, 'X');
|
||||
String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey"))));
|
||||
String keyCheck = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("keyCheck"))));
|
||||
System.out.println(lmkKey);
|
||||
System.out.println(keyCheck);
|
||||
Boolean loadKey = api.loadKey("999999999999999900000000007", lmkKey,keyCheck);
|
||||
System.out.println(loadKey);
|
||||
}*/
|
||||
|
||||
//10.2从用户存储区读取对称密钥(=) -> pass(秘钥校验值暂时无法获取)
|
||||
@Test
|
||||
public void readKey() {
|
||||
RetWrap retWrap1 = api.readKey("999999999999999900000000003");
|
||||
System.out.println(retWrap1);
|
||||
String key = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("key"))));
|
||||
System.out.println(key);
|
||||
}
|
||||
|
||||
/*//10.3更新对称密钥至用户存储区(=) -> pass(需更换索引地址)
|
||||
@Test
|
||||
public void updateKey(){
|
||||
RetWrap retWrap1 = api.genSymmetricKey(keyTye, 'X');
|
||||
String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey"))));
|
||||
String keyCheck = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("keyCheck"))));
|
||||
System.out.println(lmkKey);
|
||||
System.out.println(keyCheck);
|
||||
Boolean updateKey = api.updateKey("999999999999999900000000012", lmkKey,keyCheck);
|
||||
System.out.println(updateKey);
|
||||
}*/
|
||||
|
||||
|
||||
//15.1公钥加密指令(+) -> pass
|
||||
@Test
|
||||
public void encryptByPk() {
|
||||
RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "001", 256);
|
||||
System.out.println(Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")));
|
||||
//获取私钥
|
||||
String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"));
|
||||
System.out.println("sk:" + sk);
|
||||
//获取公钥
|
||||
String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey"));
|
||||
System.out.println("pk:" + pk);
|
||||
|
||||
byte[] bytes = api.encryptByPk(1, pk, "001".getBytes());
|
||||
System.out.println("公钥加密数据:" + Util.bytes2HexString(bytes));
|
||||
}
|
||||
|
||||
//15.2私钥解密指令(+) -> pass
|
||||
@Test
|
||||
public void decryptBySk() {
|
||||
RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "001", 256);
|
||||
System.out.println(Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")));
|
||||
//获取私钥
|
||||
String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"));
|
||||
//获取公钥
|
||||
String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey"));
|
||||
byte[] bytes = api.encryptByPk(1, pk, "001".getBytes());
|
||||
byte[] data = api.decryptBySk(1, sk, bytes);
|
||||
System.out.println(new String(data));
|
||||
}
|
||||
|
||||
/* //15.3私钥加密指令(?) -> code = 13 ( 0xd ) msg = 未定义的错误(无返回加密数据)
|
||||
@Test
|
||||
public void encryptBySk(){
|
||||
RetWrap retWrap = api.SM2OrRSAGenKeyPair(1,"001",256);
|
||||
System.out.println(Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")));
|
||||
//获取私钥
|
||||
String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"));
|
||||
//获取公钥
|
||||
String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey"));
|
||||
byte[] bytes = api.encryptBySk(0, sk, "001".getBytes());
|
||||
System.out.println(bytes);
|
||||
byte[] bytes1 = api.decryptByPk(0, pk, bytes);
|
||||
System.out.println(new String(bytes1));
|
||||
}
|
||||
*/
|
||||
|
||||
/* //15.5 RSA私钥签名(+) ->
|
||||
@Test
|
||||
public void RSASignC(){
|
||||
RetWrap retWrap1 = api.conutHash(1,0, key2.getBytes(), key1.getBytes());
|
||||
byte[] bytes = api.RSASignC("0000000000000005", 1, 0,(byte[]) retWrap1.get("hash"));
|
||||
System.out.println(bytes);
|
||||
}*/
|
||||
|
||||
|
||||
/* //15.6 RSA验证签名(+)
|
||||
@Test
|
||||
public void RSAVerify(){
|
||||
RetWrap retWrap = api.SM2OrRSAGenKeyPair(0,"0000000000000005",1024);
|
||||
//15.7计算HASH散列值(MD5\SHA1\SHA256)(+) -> pass
|
||||
RetWrap retWrap1 = api.conutHash(1,0, key2.getBytes(), key1.getBytes());
|
||||
String hash = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("hash"))));
|
||||
System.out.println(hash);
|
||||
System.out.println(retWrap1);
|
||||
//15.5 RSA私钥签名(+)
|
||||
byte[] bytes = api.RSASignC("0000000000000005", 1, 0,(byte[]) retWrap1.get("hash"));
|
||||
System.out.println(bytes);
|
||||
boolean hash1 = api.RSAVerify(1, 0, (byte[]) retWrap.get("PublicKey"), (byte[]) retWrap1.get("hash"), bytes);
|
||||
System.out.println(hash1);
|
||||
}
|
||||
*/
|
||||
|
||||
//15.7计算HASH散列值(MD5\SHA1\SHA256)(+) -> pass
|
||||
@Test
|
||||
public void RSASignC() {
|
||||
RetWrap retWrap1 = api.conutHash(1, 0, key2.getBytes(), key1.getBytes());
|
||||
System.out.println(retWrap1);
|
||||
}
|
||||
|
||||
//16.1 RSA、SM2非对称密钥产生(*) ->pass
|
||||
@Test
|
||||
public void SM2GenSessionKey() {
|
||||
RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "", 256);
|
||||
//RetWrap retWrap = api.SM2GenKeyPair();
|
||||
String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey"));
|
||||
System.out.println(pk);
|
||||
String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"));
|
||||
System.out.println(sk);
|
||||
}
|
||||
|
||||
//16.2产生随机密钥,由公钥加密并且以LMK加密输出(+) ->pass
|
||||
@Test
|
||||
public void SM2OrRSAGenKeyPair() {
|
||||
RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "006", 256);
|
||||
String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey"));
|
||||
String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"));
|
||||
System.out.println(pk);
|
||||
System.out.println(sk);
|
||||
RetWrap retWrap1 = api.SM2GenSessionKey(pk);
|
||||
System.out.println(retWrap1);
|
||||
}
|
||||
|
||||
//16.3由私钥解密随机密钥并以LMK加密输出(+) -> pass
|
||||
@Test
|
||||
public void SM2ConfirmSessionKey() {
|
||||
RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "006", 256);
|
||||
String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey"));
|
||||
String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"));
|
||||
System.out.println(pk);
|
||||
System.out.println(sk);
|
||||
//16.2产生随机密钥,由公钥加密并且以LMK加密输出(+) ->pass
|
||||
RetWrap retWrap1 = api.SM2GenSessionKey(pk);
|
||||
System.out.println(retWrap1);
|
||||
String CipherKey = retWrap1.get(SydApi.RET_CIPHER_KEY).toString();
|
||||
|
||||
RetWrap retWrap2 = api.SM2ConfirmSessionKey(sk, CipherKey);
|
||||
System.out.println(retWrap2);
|
||||
|
||||
byte[] bytes = api.SM3Hash(pk, "0001".getBytes());
|
||||
System.out.println(Util.bytes2HexString(bytes));
|
||||
}
|
||||
|
||||
//16.5 SM2私钥签名(+) ->pass
|
||||
@Test
|
||||
public void SYD_SM2_Sign_HA() {
|
||||
RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "006", 256);
|
||||
String s = api.SYD_SM2_Sign_HA(1, (byte[]) retWrap.get("PrivateKey"), (byte[]) retWrap.get("PublicKey"), key7.getBytes());
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
//16.6 SM2公钥验签(+)->pass (仅签名数据类型为原数据通过)
|
||||
@Test
|
||||
public void SYD_SM2_Verify_HA() {
|
||||
RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "006", 256);
|
||||
String s = api.SYD_SM2_Sign_HA(1, (byte[]) retWrap.get("PrivateKey"), (byte[]) retWrap.get("PublicKey"), key7.getBytes());
|
||||
System.out.println(s);
|
||||
boolean b = api.SYD_SM2_Verify_HA(1, (byte[]) retWrap.get("PublicKey"), key7.getBytes(), s);
|
||||
System.out.println(b);
|
||||
}
|
||||
|
||||
//16.7 LMK加密密钥转公钥加密输出 ->pass
|
||||
@Test
|
||||
public void LMK2SM2() {
|
||||
RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, "006", 256);
|
||||
String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey"));
|
||||
RetWrap retWrap2 = api.LMK2SM2(Util.hexString2Bytes(pk), key2);
|
||||
System.out.println(retWrap2);
|
||||
}
|
||||
|
||||
/* //16.8 ECC密钥生成 -> code = 129 ( 0x81 ) msg = 未定义的错误, 服务器代码问题
|
||||
@Test
|
||||
public void genKeyPair(){
|
||||
RetWrap retWrap2 = api.genKeyPair(0415, 1234);
|
||||
System.out.println(retWrap2);
|
||||
}*/
|
||||
|
||||
/* //17.8 获取传输保护密钥(+) -> code = 18 ( 0x12 ) msg = 未定义的错误
|
||||
@Test
|
||||
public void getTransmissionKey(){
|
||||
RetWrap transmissionKey = api.getTransmissionKey();
|
||||
System.out.println(transmissionKey);
|
||||
}*/
|
||||
|
||||
/* //17.9 角色认证(+) -> : code = 2 ( 0x2 ) msg = 签名验证错误
|
||||
@Test
|
||||
public void roleVerify(){
|
||||
RetWrap retWrap = api.roleVerify("0000000000000012");
|
||||
System.out.println(retWrap);
|
||||
}*/
|
||||
|
||||
//17.10 获取随机数(=) -> PASS
|
||||
@Test
|
||||
public void GenerateRandom() {
|
||||
String s = api.GenerateRandom(012);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
//17.11 获取应用密钥明文(+) -> PASS
|
||||
@Test
|
||||
public void getPlainText() {
|
||||
RetWrap retWrap = api.genSymmetricKey("002", 'X');
|
||||
System.out.println(retWrap);
|
||||
String lmkKey = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("lmkKey"))));
|
||||
RetWrap plainText = api.getPlainText(lmkKey, 0);
|
||||
System.out.println(plainText);
|
||||
}
|
||||
|
||||
//18.1加押指令(+) -> pass
|
||||
@Test
|
||||
public void impose() {
|
||||
RetWrap retWrap = api.impose(keyTye, key2, "000".getBytes());
|
||||
System.out.println(retWrap);
|
||||
}
|
||||
|
||||
//18.2核押指令(+) -> pass
|
||||
@Test
|
||||
public void verifyImpose() {
|
||||
//获取密押
|
||||
RetWrap impose = api.impose(keyTye, key2, "000".getBytes());
|
||||
//byte[] secret = Util.hexString2Bytes(Util.bytes2HexString((byte[]) impose.get("MAC")));
|
||||
System.out.println(impose);
|
||||
Boolean verifyImpose = api.verifyImpose(keyTye, key2, impose.get("MAC").toString().getBytes(), "000".getBytes());
|
||||
System.out.println(verifyImpose);
|
||||
}
|
||||
|
||||
//18.3加解密指令(+) -> pass
|
||||
@Test
|
||||
public void encryAndDecry() {
|
||||
RetWrap impose = api.impose(keyTye, key2, "000".getBytes());
|
||||
RetWrap retWrap = api.encryAndDecry(keyTye, key2, impose.get("MAC").toString().getBytes());
|
||||
System.out.println(retWrap.get("info").toString());
|
||||
}
|
||||
|
||||
//18.4转加密指令(+) -> pass
|
||||
@Test
|
||||
public void switchEncry() {
|
||||
RetWrap impose = api.impose(keyTye, key2, "000".getBytes());
|
||||
RetWrap retWrap = api.switchEncry(keyTye, key2, key4, impose.get("MAC").toString().getBytes());
|
||||
System.out.println(retWrap);
|
||||
|
||||
String info = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap.get("info"))));
|
||||
System.out.println(Util.bytes2HexString((byte[]) retWrap.get("info")));
|
||||
}
|
||||
|
||||
//18.5 PIN加解密指令(+) -> pass
|
||||
@Test
|
||||
public void encryAndDecry4PIN() {
|
||||
String s1 = api.encryPIN(0, "06123456FFFFFFFF", "123456789123");
|
||||
System.out.println(s1);
|
||||
System.out.println(Util.hexString2Bytes(s1));
|
||||
byte[] bytes = api.encryAndDecry4PIN(key2, Util.hexString2Bytes(s1));
|
||||
System.out.println(bytes);
|
||||
String s = Util.bytes2HexString(bytes);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
//18.6 PIN转加密指令(+) -> pass
|
||||
@Test
|
||||
public void switchEncry4PIN() {
|
||||
String s1 = api.encryPIN(0, "06123456FFFFFFFF", "123456789123");
|
||||
System.out.println(s1);
|
||||
System.out.println(Util.hexString2Bytes(s1));
|
||||
byte[] bytes = api.switchEncry4PIN(key2, key4, Util.hexString2Bytes(s1));
|
||||
System.out.println(bytes);
|
||||
}
|
||||
|
||||
|
||||
/* // 19.1解密数据并由公钥加密输出 ->: code = 19 ( 0x13 ) msg = 数据解密错(C3)
|
||||
@Test
|
||||
public void decryptAndEncryptByP(){
|
||||
//生成公钥
|
||||
//RetWrap retWrap = api.SM2OrRSAGenKeyPair(0,"001",256);
|
||||
RetWrap retWrap = api.SM2GenKeyPair();
|
||||
String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey"));
|
||||
System.out.println(pk);
|
||||
//生成DEK
|
||||
RetWrap retWrap1 = api.genSymmetricKey("100", 'X');
|
||||
System.out.println(new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey")))));
|
||||
String DEK = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey"))));
|
||||
|
||||
byte[] bytes = api.SYMEncryptDataCBC(1,DEK, "001".getBytes());
|
||||
System.out.println("加密:"+Util.bytes2HexString(bytes));
|
||||
|
||||
byte[] bytesx = api.SYMDecryptDataCBC(1, DEK, bytes);
|
||||
System.out.println("解密:"+Util.bytes2HexString(bytesx));
|
||||
|
||||
retWrap = api.decryptAndEncryptByP(DEK,bytes, 1, (byte[]) retWrap.get("PublicKey"));
|
||||
System.out.println(retWrap);
|
||||
}*/
|
||||
|
||||
/* //19.2由私钥解密密文数据并经过DEK加密后输出 ->code = 21 ( 0x15 ) msg = 输入的数据格式错误
|
||||
@Test
|
||||
public void decryptAndEncryptByS(){
|
||||
RetWrap retWrap = api.SM2OrRSAGenKeyPair(1,"001",256);
|
||||
System.out.println(Util.bytes2HexString((byte[]) retWrap.get("PrivateKey")));
|
||||
//获取私钥
|
||||
String sk = Util.bytes2HexString((byte[]) retWrap.get("PrivateKey"));
|
||||
System.out.println("sk:"+sk);
|
||||
//获取公钥
|
||||
String pk = Util.bytes2HexString((byte[]) retWrap.get("PublicKey"));
|
||||
System.out.println("pk:"+pk);
|
||||
//公钥加密
|
||||
byte[] bytes = api.encryptByPk(1, pk, "001".getBytes());
|
||||
System.out.println("公钥加密数据:"+Util.bytes2HexString(bytes));
|
||||
//私钥解密
|
||||
byte[] data = api.decryptBySk(1, sk, bytes);
|
||||
System.out.println(new String(data));
|
||||
RetWrap retWrap1 = api.genSymmetricKey("0D0", 'X');
|
||||
String s = new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) retWrap1.get("lmkKey"))));
|
||||
RetWrap retWrap2 = api.decryptAndEncryptByS(s,bytes,sk);
|
||||
System.out.println(retWrap2);
|
||||
}*/
|
||||
|
||||
|
||||
/*//20.1生成数字信封 -> : code = 33 ( 0x21 ) msg = 检索的数据或密钥不存在
|
||||
@Test
|
||||
public void generateDE(){
|
||||
RetWrap retWrap = api.generateDE("1004282452", (byte) 0x31);
|
||||
System.out.println(retWrap);
|
||||
}*/
|
||||
|
||||
/*//24.1获取加密机cpu,内存,磁盘使用状况 HI ->: code = -2 ( 0xfffffffe ) msg = 接收数据超时
|
||||
@Test
|
||||
public void getStatus(){
|
||||
RetWrap retWrap = api.getStatus();
|
||||
System.out.println(retWrap);
|
||||
}*/
|
||||
|
||||
//24.2获取加密机设备信息 -> pass
|
||||
@Test
|
||||
public void getVersion() {
|
||||
RetWrap version = api.getVersion("1234");
|
||||
System.out.println(version);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void directBytes() {
|
||||
String s = "00DF00000000000000023738313939393939393939393939393939393939393939393939393939393030363800010000339C7BFC0EA0E75D8165F1539889D9932AD64F6117FA66649850D6E331CB797A000000000000000000000000000000000000000000000000000000000000000030313039306B02204A99C4E0B610AE7452277896A22E1D551E45F9FF9CAF3241497AF3C85AA7CCB002206E15B65AE8F16A1990BCD51FC29235943A92D17C36F493BE7E3D694CC46B1E830420CD099F4BC3B8E1FD475134183E16E2CDF65F8615760BE94CB72738545399B48104039C1D29";
|
||||
byte[] bytes1 = Util.hexString2Bytes(s);
|
||||
byte[] bytes = api.directBytes(bytes1);
|
||||
String s1 = Util.bytes2HexString(bytes);
|
||||
System.out.println(s1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
public class TestMixKey {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SydApi sydApi = (new SydApi4j()).connect("172.16.17.163", 8889,null , 10000);
|
||||
String pk = "0342000417CCD26D6DD2D1A4022C2A94DCF6CE07229C153DA9729D45274F5C6BF6BB9CF5B9C1FA3B2C7113C54C7873470D01B174501498BC5640A164F883E9C4A6844FCF";
|
||||
String sk = "00010000160C81E621BBCC2348FABAF7C812F2D2E014C75C5F94820E7DD52A23C59759A90000000000000000000000000000000000000000000000000000000000000000";
|
||||
|
||||
|
||||
String id = "012345678901234567890123456789";
|
||||
|
||||
String enData = sydApi.SM2Encrypt(
|
||||
Util.hexString2Bytes(pk),
|
||||
(id + "123456").getBytes()
|
||||
);
|
||||
|
||||
System.out.println( enData );
|
||||
|
||||
// sydApi.SM2DecryptC()
|
||||
|
||||
|
||||
|
||||
// RetWrap ret = sydApi.genKeyEx( pk , "000000");
|
||||
//
|
||||
// // key 258
|
||||
// System.out.println( ret );
|
||||
//
|
||||
//
|
||||
// ret = sydApi.deKeyEx( sk , ret.get("key").toString() , "S");
|
||||
//
|
||||
//
|
||||
// System.out.println( ret );
|
||||
//
|
||||
// String lmk = ret.get("lmk").toString();
|
||||
//
|
||||
// ret = sydApi.mixKey( lmk, lmk , "S" );
|
||||
//
|
||||
//
|
||||
// System.out.println( ret );
|
||||
//
|
||||
//
|
||||
// // lmk -> pken
|
||||
// String ek = sydApi.enKeyPk( pk , lmk );
|
||||
// System.out.println( ek );
|
||||
//
|
||||
// ret = sydApi.deKeyEx( sk , ek , "S");
|
||||
// System.out.println( ret );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
public class TestPJS {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String ip = "172.16.18.72"; //"172.16.18.72"; //"172.16.17.162";
|
||||
byte[] pInData = Util.hexString2Bytes("4649F0894D0905D8F7DA4E5D8B9CE3BA");
|
||||
String seesionKey = "S203AE74FEE98FE440E232B9EDCF0EA61";
|
||||
|
||||
|
||||
|
||||
SydApi sydApi = (new SydApi4j()).connect(ip, 8889,null , 10000);
|
||||
byte[] ret = sydApi.SYMDecryptDataCBC(0x01, seesionKey, pInData );
|
||||
|
||||
System.out.println( new String(ret) );
|
||||
|
||||
|
||||
// SydApi sydApi = (new SydApi4j()).connect(ip, 8889,null , 10000);
|
||||
// byte[] ret = sydApi.SYMEncryptDataCBC(0x01, seesionKey, pInData, Util.bytes2HexString("SHANGPIAOJIAOSUO".getBytes()).getBytes());
|
||||
//
|
||||
//
|
||||
// System.out.println( Util.bytes2HexString(ret) );
|
||||
//
|
||||
//
|
||||
// ret = sydApi.SYMDecryptDataCBC(0x01, seesionKey, ret, Util.bytes2HexString("TEST-PIAOJIAOSUO".getBytes()).getBytes());
|
||||
//
|
||||
// System.out.println( Util.bytes2HexString(ret) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
|
||||
public class TestPKCS1 {
|
||||
|
||||
private static final String testData = "<MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>";
|
||||
private static final String testCertNo = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 连接加密机
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.17.162", 8889, null, 1000);
|
||||
|
||||
|
||||
try {
|
||||
|
||||
// 原始数据模式
|
||||
case1(api);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
api.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public static void case1(SydApi api) {
|
||||
// 签名验签 1
|
||||
System.out.println("\n\n----- 裸签名 -----");
|
||||
byte[] sign = api.SYD_NakedSign(testData.getBytes(), testCertNo);
|
||||
System.out.println("签名结果 " + Util.bytes2HexString(sign) );
|
||||
|
||||
|
||||
boolean pass = api.SYD_NakedVerify(testData.getBytes(), sign, testCertNo);
|
||||
System.out.println("验签结果 " + pass);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
|
||||
public class TestPKCS7 {
|
||||
|
||||
private static final String testData = "<MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>";
|
||||
private static final String testPubKey = "034200043EDA3A107B7CC35CC005C7FBF0BB4E6B43A07EE14E360603D22ECA2A600B2D0FA03055D400D1240300F54648B849D13F50B330FF14351B5645B13686820A65BB";
|
||||
private static final String testCertNo = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 连接加密机
|
||||
// SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.17.162", 8889, null, 1000);
|
||||
SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.18.69", 8889, 1000);
|
||||
SydApi4j api = (SydApi4j) new SydApi4j();
|
||||
|
||||
try {
|
||||
|
||||
// 基础接口 原始数据模式
|
||||
case1( api );
|
||||
/*
|
||||
// 基础接口 HASH 数据模式
|
||||
case2( api );
|
||||
|
||||
// 原始数据模式专用接口
|
||||
case3( api );
|
||||
|
||||
// HASH 模式专用接口
|
||||
case4( api );*/
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
api.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public static void case1(SydApi api) {
|
||||
System.out.println("\n\n----- PKCS7 签名验签 基础接口原始数据模式 -----");
|
||||
String sign = api.detachedSign(
|
||||
SydApi.DATA_ORIGIN,
|
||||
testData.getBytes(),
|
||||
testCertNo
|
||||
);
|
||||
|
||||
System.out.println("\t签名结果: " + sign);
|
||||
|
||||
boolean verify = api.detachedVerify(
|
||||
SydApi.DATA_ORIGIN,
|
||||
testData.getBytes(),
|
||||
sign
|
||||
);
|
||||
|
||||
System.out.println("\t验签结果: " + verify);
|
||||
}
|
||||
|
||||
public static void case2(SydApi api) {
|
||||
System.out.println("\n\n----- PKCS7 签名验签 基础接口 hash 数据模式 -----");
|
||||
byte[] hash = api.SM3Hash(testPubKey, testData.getBytes());
|
||||
|
||||
String sign = api.detachedSign(
|
||||
SydApi.DATA_HASH,
|
||||
hash,
|
||||
TestPKCS7.testCertNo
|
||||
);
|
||||
|
||||
System.out.println("\t签名结果: " + sign);
|
||||
|
||||
boolean verify = api.detachedVerify(
|
||||
SydApi.DATA_HASH,
|
||||
hash,
|
||||
sign
|
||||
);
|
||||
|
||||
System.out.println("\t验签结果: " + verify);
|
||||
}
|
||||
|
||||
public static void case3(SydApi api) {
|
||||
System.out.println("\n\n----- PKCS7 签名验签 原始数据模式 -----");
|
||||
|
||||
String sign = api.SYD_DetachedSign(
|
||||
testData.getBytes(),
|
||||
testCertNo
|
||||
);
|
||||
|
||||
System.out.println("\t签名结果: " + sign);
|
||||
|
||||
boolean verify = api.SYD_DetachedVerify(
|
||||
testData.getBytes(),
|
||||
sign
|
||||
);
|
||||
|
||||
System.out.println("\t验签结果: " + verify);
|
||||
}
|
||||
|
||||
public static void case4(SydApi api) {
|
||||
System.out.println("\n\n----- PKCS7 签名验签 hash 数据模式 -----");
|
||||
|
||||
String sign = api.sm3AndDetachedSign(
|
||||
testData.getBytes(),
|
||||
testPubKey,
|
||||
TestPKCS7.testCertNo
|
||||
);
|
||||
|
||||
System.out.println("\t签名结果: " + sign);
|
||||
|
||||
boolean verify = api.sm3AndDetachedVerify(
|
||||
testData.getBytes(),
|
||||
testPubKey,
|
||||
sign
|
||||
);
|
||||
|
||||
System.out.println("\t验签结果: " + verify);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* SydApi 测试程序!
|
||||
* 调用方法参考如下,加密机需要相应的设置。
|
||||
*/
|
||||
public class TestPool {
|
||||
|
||||
public static void write(String file, String content) {
|
||||
write(file, content.getBytes());
|
||||
}
|
||||
|
||||
public static void write(String file, byte[] content) {
|
||||
try {
|
||||
File f = new File(file);
|
||||
if (!f.exists()) {
|
||||
f.createNewFile();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
fos.write(content);
|
||||
} catch (Exception e) {
|
||||
System.out.println("写入文件 " + file + " 异常");
|
||||
}
|
||||
}
|
||||
|
||||
public static String read(String file) {
|
||||
try {
|
||||
File f = new File(file);
|
||||
if (!f.exists()) {
|
||||
return null;
|
||||
}
|
||||
FileInputStream fis = new FileInputStream(f);
|
||||
byte[] buff = new byte[5024];
|
||||
int len = fis.read(buff);
|
||||
return new String(buff, 0, len);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
int total = 1;
|
||||
try {
|
||||
total = Integer.valueOf(args[0]);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
doit(total);
|
||||
}
|
||||
|
||||
|
||||
public static void doit(int total) {
|
||||
System.out.println("SydApi 测试程序启动");
|
||||
|
||||
final String testSN1 = "1004282451";
|
||||
final String testSN2 = "1004282452";
|
||||
final String testPubKey = "0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614";
|
||||
final String testPubKey1 = "034200040B2FCF5E2B15D341FC12A9B6A88631D83A7B79DC6BABF9E49FFF624BD148E2FA44A9F1B7F1E36E39B22AA6BD79B7EA527DB912617148A62CB94760CB80EE3A68";
|
||||
|
||||
final String testUser = "8012";
|
||||
byte[] testData = new byte[100];
|
||||
Arrays.fill(testData, (byte) 0x88);
|
||||
testData[testData.length - 3] = (byte) 0xFF;
|
||||
testData[testData.length - 2] = (byte) 0xFF;
|
||||
testData[testData.length - 1] = (byte) 0xFF;
|
||||
|
||||
|
||||
System.out.println("\n\n----- connect -----");
|
||||
SydApi sydApi = null;
|
||||
|
||||
//
|
||||
// // 建议从配置文件读取配置
|
||||
// // 单服务器测试使用
|
||||
// PoolManager.INSTANCE.createPool("default", "{\n" +
|
||||
// " \"mode\" : \"solo\", // (必填)\n" +
|
||||
// " \"oipc\" : \"com.sunyard.pool4sydapi.SydApiInPool\", " +
|
||||
// " \"ip\" : \"172.16.18.69\", // (必填)\n" +
|
||||
// " \"port\": 8889, // (必填)【数字】\n" +
|
||||
// " \"pwd\": \"\", // 没有就不填写此项\n" +
|
||||
// " \"timeout\": 1000 //【数字】不限超时时间就不填写此项\n" +
|
||||
// "}");
|
||||
|
||||
|
||||
// // 推荐配置
|
||||
// PoolManager.INSTANCE.createPool("default", "{\n" +
|
||||
// " \"mode\" : \"round-robin\", // (必填)\n" +
|
||||
// " \"oipc\" : \"com.sunyard.pool4sydapi.SydApiInPool\", // (必填)\n" +
|
||||
// " \"ips\" : [ // (必填)\n" +
|
||||
// " \"172.16.18.69\",\n" +
|
||||
// " \"172.16.18.70\"\n" +
|
||||
// " ],\n" +
|
||||
// " \"port\": 8889, //(必填)【数字】\n" +
|
||||
// " \"pwd\": \"\", //【数字】没有就不填写此项\n" +
|
||||
// " \"timeout\": 1000 , //【数字】【数字】链接和响应超时时限,不限超时时间就不填写此项\n" +
|
||||
// " \"connectTimeout\" : 1000, //【数字】【数字】链接超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" +
|
||||
// " \"waitRecvTimeout\" : 1000, //【数字】【数字】响应超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" +
|
||||
// " \"maxContinuousErrorTime\" : 3, //【数字】 单台加密机连续出错次数\n" +
|
||||
// " \"recoveryTime\" : 300000, //【数字】 恢复时间,单位毫秒,默认 5 分钟,最大 2^63\n" +
|
||||
// " \"keepAlive\" : 1, //【数字】 保持链接个数,默认是链接池个数的一半\n" +
|
||||
// " \"maxAliveTime\" : 300000000, //【数字】 最大生存时间\n" +
|
||||
// " \"maxIdleTime\" : 300000 , //【数字】 最大空闲时间,默认 5 分钟,最大 2^63\n" +
|
||||
// " \"checkMode\" : \"before/after/deamon\", // 链接检测模式,使用前/使用后/后台轮询\n" +
|
||||
// " \"checkGap\" : 300000 // 后台轮询检测间隔\n" +
|
||||
// "}");
|
||||
|
||||
|
||||
// // 自定义配置
|
||||
// PoolManager.INSTANCE.createPool("default", "{\n" +
|
||||
// " \"mode\" : \"weighted-round-robin\", // (必填)\n" +
|
||||
// " \"oipc\" : \"com.sunyard.pool4sydapi.SydApiInPool\", // (必填)\n" +
|
||||
// " \"ips\" : { // (必填)\n" +
|
||||
// " \"172.16.18.69\" : 1,\n" +
|
||||
// " \"172.16.18.70\" : 3\n" +
|
||||
// " },\n" +
|
||||
// " \"port\": 8889, //(必填)【数字】\n" +
|
||||
// " \"pwd\": \"\", //【数字】没有就不填写此项\n" +
|
||||
// " \"timeout\": 1000 , //【数字】【数字】链接和响应超时时限,不限超时时间就不填写此项\n" +
|
||||
// " \"connectTimeout\" : 1000, //【数字】【数字】链接超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" +
|
||||
// " \"waitRecvTimeout\" : 1000, //【数字】【数字】响应超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" +
|
||||
// " \"maxContinuousErrorTime\" : 3, //【数字】 单台加密机连续出错次数\n" +
|
||||
// " \"recoveryTime\" : 300000, //【数字】 恢复时间,单位毫秒,默认 5 分钟,最大 2^63\n" +
|
||||
// " \"keepAlive\" : 1, //【数字】 保持链接个数,默认是链接池个数的一半\n" +
|
||||
// " \"maxAliveTime\" : 300000000, //【数字】 最大生存时间\n" +
|
||||
// " \"maxIdleTime\" : 300000 , //【数字】 最大空闲时间,默认 5 分钟,最大 2^63\n" +
|
||||
// " \"checkMode\" : \"before/after/deamon\", // 链接检测模式,使用前/使用后/后台轮询\n" +
|
||||
// " \"checkGap\" : 300000 // 后台轮询检测间隔\n" +
|
||||
// "}");
|
||||
//
|
||||
//
|
||||
// long bt = 0;
|
||||
// long et = 0;
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// String data = "<root><MsgHeader><MsgVer>1000</MsgVer><SndDt>2018-03-05T09:53:29</SndDt><Trxtyp>0001</Trxtyp><IssrId>04639200</IssrId><Drctn>12</Drctn><SignSN>4000370700</SignSN><EncSN></EncSN><EncKey></EncKey><MDAlgo>1</MDAlgo><SignEncAlgo>1</SignEncAlgo><EncAlgo></EncAlgo></MsgHeader><MsgBody><BizTp>100001</BizTp><TrxInf><TrxId>0305095329000043</TrxId><SettlmtDt>2018-03-05</SettlmtDt></TrxInf><SysRtnInf><SysRtnCd>WKA0023</SysRtnCd><SysRtnDesc>WKA0023卡号不合法或不存在</SysRtnDesc><SysRtnTm>2018-03-05T09:54:49</SysRtnTm><ValBtMp></ValBtMp></SysRtnInf><RcverInf><RcverAcctIssrId>04639200</RcverAcctIssrId><RcverAcctId></RcverAcctId><RcverAcctTp></RcverAcctTp><Smskey></Smskey></RcverInf><SderInf><SderIssrId>W0ACQ001</SderIssrId><SderAcctIssrId>W0ACQ001</SderAcctIssrId></SderInf></MsgBody></root>";
|
||||
//
|
||||
// System.out.println("\n\n----- SM2 算法签名 (原始数据) -----");
|
||||
// byte[] hash = sydApi.SM3Hash(
|
||||
// null,
|
||||
// data.getBytes()
|
||||
// );
|
||||
//
|
||||
// String sign = sydApi.SM2SignC(
|
||||
// "1234",
|
||||
// "1234567812345678",
|
||||
// SydApi.DATA_ORIGIN,
|
||||
// Util.hexString2Bytes(testPubKey),
|
||||
// hash
|
||||
// );
|
||||
// System.out.print("\n\n----- SM2 算法签名 结果: ");
|
||||
// System.out.println(sign);
|
||||
//
|
||||
//
|
||||
// System.out.println("\n\n----- SM2 算法验签 (原始数据) -----");
|
||||
//
|
||||
// boolean SM2VerifyRet = sydApi.SM2Verify(
|
||||
// "1234567812345678",
|
||||
// SydApi.DATA_ORIGIN,
|
||||
// Util.hexString2Bytes(testPubKey), hash, sign);
|
||||
// if (SM2VerifyRet) {
|
||||
// System.out.println("验签通过");
|
||||
// } else {
|
||||
// System.err.println("验签失败");
|
||||
// throw new RuntimeException("验签失败");
|
||||
// }
|
||||
//
|
||||
// System.out.println("\n\n----- SM3 hash -----");
|
||||
// bt = System.currentTimeMillis();
|
||||
// byte[] sm3 = null;
|
||||
// for (int i = 0; i < total; i++) {
|
||||
// sm3 = sydApi.SM3Hash(
|
||||
// testPubKey,
|
||||
// testData
|
||||
// );
|
||||
// }
|
||||
// et = System.currentTimeMillis();
|
||||
// System.out.print("\n\n----- SM3 hash 时间: ");
|
||||
// System.out.println(et - bt);
|
||||
//
|
||||
// System.out.print("Hash : ");
|
||||
// write("./Hash.bin", sm3);
|
||||
// System.out.println(Util.bytes2HexString(hash));
|
||||
// System.out.print("\n\n\n\n\n");
|
||||
//
|
||||
//
|
||||
// System.out.print("\n\n----- SM2 算法签名 Customized");
|
||||
// bt = System.currentTimeMillis();
|
||||
// String sm2sign = null;
|
||||
// for (int i = 0; i < total; i++) {
|
||||
// sm2sign = sydApi.SM2SignCustomized(
|
||||
// "1004282451",
|
||||
// testData
|
||||
// );
|
||||
// }
|
||||
// et = System.currentTimeMillis();
|
||||
// System.out.print("\n\n----- SM2 算法签名 结果: ");
|
||||
// System.out.println(sm2sign);
|
||||
// System.out.print("\n\n----- SM2 算法签名 时间: ");
|
||||
// System.out.println(et - bt);
|
||||
// System.out.print("\n\n\n\n\n");
|
||||
//
|
||||
//
|
||||
// System.out.println("\n\n----- SM2 算法验签 Customized -----");
|
||||
// bt = System.currentTimeMillis();
|
||||
// boolean SM2VerifyCustomizedRet = false;
|
||||
// for (int i = 0; i < total; i++) {
|
||||
// SM2VerifyCustomizedRet = sydApi.SM2VerifyCustomized(
|
||||
// "1004282451",
|
||||
// testData,
|
||||
// sm2sign);
|
||||
// if (SM2VerifyCustomizedRet) {
|
||||
// System.out.println("验签通过");
|
||||
// } else {
|
||||
// System.err.println("验签失败");
|
||||
// throw new RuntimeException("验签失败");
|
||||
// }
|
||||
// }
|
||||
// et = System.currentTimeMillis();
|
||||
// System.out.print("\n\n----- SM2 算法验签 时间: ");
|
||||
// System.out.println(et - bt);
|
||||
// System.out.print("\n\n\n\n\n");
|
||||
//
|
||||
//
|
||||
// System.out.println("\n\n----- SM2 公钥加密数据 -----");
|
||||
// bt = System.currentTimeMillis();
|
||||
// String enData = null;
|
||||
// for (int i = 0; i < total; i++) {
|
||||
// enData = sydApi.SM2Encrypt(
|
||||
// Util.hexString2Bytes(testPubKey1),
|
||||
// testData
|
||||
// );
|
||||
// }
|
||||
// et = System.currentTimeMillis();
|
||||
// System.out.print("\n\n----- SM2 公钥加密时间 ");
|
||||
// System.out.println(et - bt);
|
||||
// System.out.println(enData);
|
||||
// System.out.print("\n\n\n\n\n");
|
||||
//
|
||||
//
|
||||
// System.out.println("\n\n----- SM2 私钥解密数据 -----");
|
||||
// bt = System.currentTimeMillis();
|
||||
// byte[] odata = null;
|
||||
// for (int i = 0; i < total; i++) {
|
||||
// odata = sydApi.SM2DecryptC(
|
||||
// testUser,
|
||||
// enData
|
||||
// );
|
||||
// }
|
||||
// et = System.currentTimeMillis();
|
||||
// System.out.print("\n\n----- SM2 私钥解密数据 时间");
|
||||
// System.out.println(et - bt);
|
||||
// System.out.println(Util.bytes2HexString(odata));
|
||||
// System.out.print("\n\n\n\n\n");
|
||||
//
|
||||
//
|
||||
// System.out.println("\n\n----- 生成密钥对 -----");
|
||||
// RetWrap key = null;
|
||||
// bt = System.currentTimeMillis();
|
||||
// for (int i = 0; i < total; i++) {
|
||||
// key = sydApi.SM2GenKeyPair();
|
||||
// }
|
||||
// et = System.currentTimeMillis();
|
||||
// System.out.print("\n\n----- 生成密钥对 时间: ");
|
||||
// System.out.println(et - bt);
|
||||
// System.out.print("Public Key : ");
|
||||
// write("./PubKey.bin", (byte[]) key.get(SydApi.RET_PUBLIC_KEY));
|
||||
// System.out.println(Util.bytes2HexString((byte[]) key.get(SydApi.RET_PUBLIC_KEY)));
|
||||
// System.out.print("Private Key : ");
|
||||
// write("./PriKey.bin", (byte[]) key.get(SydApi.RET_PRIVATE_KEY));
|
||||
// System.out.println(Util.bytes2HexString((byte[]) key.get(SydApi.RET_PRIVATE_KEY)));
|
||||
// System.out.print("\n\n\n\n\n");
|
||||
//
|
||||
//
|
||||
// System.out.println("\n\n----- 获取公钥 () -----");
|
||||
// String pk = sydApi.SM2GetPublicKeyC("1234", 0);
|
||||
// write("./PubKey.bin", pk);
|
||||
// System.out.print("\r\n公钥 : ");
|
||||
// System.out.println(pk);
|
||||
//
|
||||
//
|
||||
// } finally {
|
||||
// System.out.println("\n\n----- disconnect -----");
|
||||
// sydApi.disconnect();
|
||||
// }
|
||||
|
||||
|
||||
System.out.println("执行结束\n\n");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* SydApi 网联相关接口
|
||||
* 调用方法参考如下,加密机需要相应的设置。
|
||||
*/
|
||||
public class TestQNUCApi {
|
||||
|
||||
public static void write(String file, String content) {
|
||||
write(file, content.getBytes());
|
||||
}
|
||||
|
||||
public static void write(String file, byte[] content) {
|
||||
try {
|
||||
File f = new File(file);
|
||||
if (!f.exists()) {
|
||||
f.createNewFile();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
fos.write(content);
|
||||
} catch (Exception e) {
|
||||
System.out.println("写入文件 " + file + " 异常");
|
||||
}
|
||||
}
|
||||
|
||||
public static String read(String file) {
|
||||
try {
|
||||
File f = new File(file);
|
||||
if (!f.exists()) {
|
||||
return null;
|
||||
}
|
||||
FileInputStream fis = new FileInputStream(f);
|
||||
byte[] buff = new byte[5024];
|
||||
int len = fis.read(buff);
|
||||
return new String(buff, 0, len);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 连接加密机
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.18.226", 8889, null, 1000);
|
||||
|
||||
final String testSN1 = "1004282451";
|
||||
final String testSN2 = "1004282452";
|
||||
final String testPubKey = "0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614";
|
||||
final String testPubKey1 = "034200040B2FCF5E2B15D341FC12A9B6A88631D83A7B79DC6BABF9E49FFF624BD148E2FA44A9F1B7F1E36E39B22AA6BD79B7EA527DB912617148A62CB94760CB80EE3A68";
|
||||
byte[] testData = new byte[100];
|
||||
Arrays.fill(testData, (byte) 0x88);
|
||||
testData[testData.length - 3] = (byte) 0xFF;
|
||||
testData[testData.length - 2] = (byte) 0xFF;
|
||||
testData[testData.length - 1] = (byte) 0xFF;
|
||||
final String testUser = "8012";
|
||||
|
||||
|
||||
try {
|
||||
System.out.println("\n\n----- 用指定的证书私钥对指定的数据进行数字签名。 -----");
|
||||
String signPri = api.netSign(testSN1, testData);
|
||||
System.out.print("sign : ");
|
||||
System.out.println(signPri);
|
||||
|
||||
write("./Sign.b64", signPri);
|
||||
|
||||
|
||||
System.out.println("\n\n----- 用指定证书对指定的原始数据进行数字签名验证。 -----");
|
||||
signPri = read("./Sign.b64");
|
||||
if (api.netVerify(testSN1, testData, signPri)) {
|
||||
System.out.println("验证通过");
|
||||
} else {
|
||||
System.out.println("验证失败");
|
||||
}
|
||||
|
||||
|
||||
System.out.println("\n\n----- 通过证书的 DN,获取证书的序号。 -----");
|
||||
String sn = null;
|
||||
try {
|
||||
sn = api.getX509SN(SydApi.ALG_AES, "C=CN,O=Sunyard,OU=8001,CN=8001".getBytes("GBK"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.print("sn : ");
|
||||
System.out.println(sn);
|
||||
|
||||
|
||||
System.out.println("\n\n----- 生成数字信封 -----");
|
||||
RetWrap wrapNum = api.generateDE(testSN2, SydApi.ALG_SM4);
|
||||
System.out.print("Session Key : ");
|
||||
System.out.println(wrapNum.get(SydApi.RET_SESSION_KEY));
|
||||
System.out.print("Cipher Key : ");
|
||||
System.out.println(wrapNum.get(SydApi.RET_CIPHER_KEY));
|
||||
System.out.print("KCV: ");
|
||||
System.out.println(wrapNum.get(SydApi.RET_KCV));
|
||||
|
||||
|
||||
write("./CipherKey.b64", (String) wrapNum.get(SydApi.RET_CIPHER_KEY));
|
||||
write("./SessionKey.bin", (String) wrapNum.get(SydApi.RET_SESSION_KEY));
|
||||
|
||||
|
||||
System.out.println("\n\n----- 解密数字信封 -----");
|
||||
String cipherKey = read("./CipherKey.b64");
|
||||
System.out.print("Cipher Key : ");
|
||||
System.out.println(cipherKey);
|
||||
|
||||
|
||||
RetWrap wrap = api.decryptDE(testSN2, cipherKey);
|
||||
System.out.print("Session Key : ");
|
||||
System.out.println(wrap.get(SydApi.RET_SESSION_KEY));
|
||||
|
||||
System.out.print("KCV : ");
|
||||
System.out.println(wrap.get(SydApi.RET_KCV));
|
||||
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 -----");
|
||||
String sessionKey = read("./SessionKey.bin");
|
||||
byte[] enSm4Data = api.SYMEncryptData(SydApi.NALG_SM4, sessionKey, testData);
|
||||
System.out.print("密文 : ");
|
||||
System.out.println(Util.bytes2HexString(enSm4Data));
|
||||
write("./EnData.bin", enSm4Data);
|
||||
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 -----");
|
||||
byte[] deSM4Data = api.SYMDecryptData(SydApi.NALG_SM4, sessionKey, enSm4Data);
|
||||
System.out.print("解密 : ");
|
||||
System.out.println(Util.bytes2HexString(deSM4Data));
|
||||
write("./DeData.bin", enSm4Data);
|
||||
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行加密处理。 CBC -----");
|
||||
String sessionKeyCBC = read("./SessionKey.bin");
|
||||
byte[] enDataCBC = api.SYMEncryptDataCBC(SydApi.NALG_SM4, sessionKeyCBC, testData);
|
||||
System.out.print("密文 : ");
|
||||
System.out.println(Util.bytes2HexString(enDataCBC));
|
||||
write("./EnData.bin", enDataCBC);
|
||||
|
||||
|
||||
System.out.println("\n\n----- 用输入的会话密钥,对指定报文数据进行解密处理。 CBC -----");
|
||||
byte[] deDataCBC = api.SYMDecryptDataCBC(SydApi.NALG_SM4, sessionKeyCBC, enDataCBC);
|
||||
System.out.print("解密 : ");
|
||||
System.out.println(Util.bytes2HexString(deDataCBC));
|
||||
write("./DeData.bin", deDataCBC);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class TestReflection {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Class<?> clazz = Class.forName("com.sunyard." + "Util");
|
||||
Method method = clazz.getMethod("hello",String.class);
|
||||
method.invoke(clazz.newInstance(),"123");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.cert.X509;
|
||||
import com.sunyard.inf.customize.SydSDNXApiImpl;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
public class TestSDNXApi {
|
||||
|
||||
private static final String testCertNo = "C=cn,O=CFCA TEST CA,OU=NCS2,OU=Enterprises,CN=041@Z402451000010@ShanDong@00000001";
|
||||
//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=Sunyard,OU=8001,CN=8001";
|
||||
//private static final String testData = "<MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>";
|
||||
private static final String testData = "<MainBody><MsgId><Id>000000000000000201902231000012910</Id><CreDtTm>2019-02-23T09:29:19</CreDtTm></MsgId><CertNtfctnInf><ChngTp>CC00</ChngTp></CertNtfctnInf></MainBody>";
|
||||
private static final String testUser = "201597";
|
||||
//private static final String testUser = "8001";
|
||||
//private static final String testUser = "402030000011";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
SydApi api = null;
|
||||
System.out.println("\n\n----- connect -----");
|
||||
|
||||
// 建议从配置文件读取配置
|
||||
|
||||
// 单服务器测试使用
|
||||
// PoolManager.INSTANCE.createPool("default", "{\n" +
|
||||
// " \"mode\" : \"solo\", // (必填)\n" +
|
||||
// " \"oipc\" : \"com.sunyard.pool4sydapi.SydApiSDNXInPool\", " +
|
||||
// " \"ip\" : \"172.16.18.71\", // (必填)\n" +
|
||||
// " \"port\": 8889, // (必填)【数字】\n" +
|
||||
// " \"pwd\": \"\", // 没有就不填写此项\n" +
|
||||
// " \"timeout\": 1000 //【数字】不限超时时间就不填写此项\n" +
|
||||
// "}");
|
||||
|
||||
|
||||
// // 推荐配置
|
||||
// PoolManager.INSTANCE.createPool("default", "{\n" +
|
||||
// " \"mode\" : \"round-robin\", // (必填)\n" +
|
||||
// " \"oipc\" : \"com.sunyard.pool4sydapi.SydApiSDNXInPool\", // (必填)\n" +
|
||||
// " \"ips\" : [ // (必填)\n" +
|
||||
// " \"172.16.18.69\",\n" +
|
||||
// " \"172.16.18.70\"\n" +
|
||||
// " ],\n" +
|
||||
// " \"port\": 8889, //(必填)【数字】\n" +
|
||||
// " \"pwd\": \"\", //【数字】没有就不填写此项\n" +
|
||||
// " \"timeout\": 1000 , //【数字】【数字】链接和响应超时时限,不限超时时间就不填写此项\n" +
|
||||
// " \"connectTimeout\" : 1000, //【数字】【数字】链接超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" +
|
||||
// " \"waitRecvTimeout\" : 1000, //【数字】【数字】响应超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" +
|
||||
// " \"maxContinuousErrorTime\" : 3, //【数字】 单台加密机连续出错次数\n" +
|
||||
// " \"recoveryTime\" : 300000, //【数字】 恢复时间,单位毫秒,默认 5 分钟,最大 2^63\n" +
|
||||
// " \"keepAlive\" : 1, //【数字】 保持链接个数,默认是链接池个数的一半\n" +
|
||||
// " \"maxAliveTime\" : 300000000, //【数字】 最大生存时间\n" +
|
||||
// " \"maxIdleTime\" : 300000 , //【数字】 最大空闲时间,默认 5 分钟,最大 2^63\n" +
|
||||
// " \"checkMode\" : \"before/after/deamon\", // 链接检测模式,使用前/使用后/后台轮询\n" +
|
||||
// " \"checkGap\" : 300000 // 后台轮询检测间隔\n" +
|
||||
// "}");
|
||||
|
||||
// 自定义配置
|
||||
// PoolManager.INSTANCE.createPool("default", "{\n" +
|
||||
// " \"mode\" : \"weighted-round-robin\", // (必填)\n" +
|
||||
// " \"oipc\" : \"com.sunyard.pool4sydapi.SydApiSDNXInPool\", // (必填)\n" +
|
||||
// " \"ips\" : { // (必填)\n" +
|
||||
// " \"172.16.18.69\" : 1,\n" +
|
||||
// " \"172.16.18.70\" : 3\n" +
|
||||
// " },\n" +
|
||||
// " \"port\": 8889, //(必填)【数字】\n" +
|
||||
// " \"pwd\": \"\", //【数字】没有就不填写此项\n" +
|
||||
// " \"timeout\": 1000 , //【数字】【数字】链接和响应超时时限,不限超时时间就不填写此项\n" +
|
||||
// " \"connectTimeout\" : 1000, //【数字】【数字】链接超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" +
|
||||
// " \"waitRecvTimeout\" : 1000, //【数字】【数字】响应超时时限,如果没有传递,但是存在 timeout 就等于 timeout 的值\n" +
|
||||
// " \"maxContinuousErrorTime\" : 3, //【数字】 单台加密机连续出错次数\n" +
|
||||
// " \"recoveryTime\" : 300000, //【数字】 恢复时间,单位毫秒,默认 5 分钟,最大 2^63\n" +
|
||||
// " \"keepAlive\" : 1, //【数字】 保持链接个数,默认是链接池个数的一半\n" +
|
||||
// " \"maxAliveTime\" : 300000000, //【数字】 最大生存时间\n" +
|
||||
// " \"maxIdleTime\" : 300000 , //【数字】 最大空闲时间,默认 5 分钟,最大 2^63\n" +
|
||||
// " \"checkMode\" : \"before/after/deamon\", // 链接检测模式,使用前/使用后/后台轮询\n" +
|
||||
// " \"checkGap\" : 300000 // 后台轮询检测间隔\n" +
|
||||
// "}");
|
||||
|
||||
|
||||
try {
|
||||
|
||||
|
||||
//热备模式连接
|
||||
SydApi4j.SYD_Set_Parameter_HA("unkown", "122.224.86.107", 8889, 1000);
|
||||
api = new SydApi4j();
|
||||
|
||||
|
||||
// 链接池和负载均衡模式
|
||||
//api = (SydSDNXApiImpl) PoolManager.INSTANCE.getPool().get().getOrigin();
|
||||
|
||||
System.out.println("连接加密机成功");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
|
||||
|
||||
//用证书DN签名
|
||||
//case1(api);
|
||||
|
||||
//根据机构号验签,上传并返回证书内容,并更新机构号
|
||||
case2(api);
|
||||
|
||||
|
||||
//裸签名
|
||||
//case3(api);
|
||||
|
||||
//验签
|
||||
//case4(api);
|
||||
|
||||
} finally {
|
||||
System.out.println("\n\n----- disconnect -----");
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
System.out.println("执行结束\n\n");
|
||||
}
|
||||
|
||||
public static void case1(SydSDNXApiImpl api) {
|
||||
|
||||
System.out.println("\n\n----- 签名 基础接口原始数据模式 -----");
|
||||
String sign = api.detachedSign(SydApi4j.DATA_ORIGIN, testData.getBytes(), testCertNo);
|
||||
System.out.println("\t签名结果: " + sign);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//需要上传验签结果,测试的时候签名和验签不能同时进行,签名以后要删除数据库数据才可以验签(仅限测试可以这样操作)
|
||||
public static void case2(SydApi api) {
|
||||
|
||||
System.out.println("\n\n----- 验签 ,上传并返回证书内容,并更新机构号 -----");
|
||||
|
||||
String sign = "MIIEYQYKKoEcz1UGAQQCAqCCBFEwggRNAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIIDUjCCA04wggLyoAMCAQICBUCEF1MkMAwGCCqBHM9VAYN1BQAwXDELMAkGA1UEBhMCQ04xMDAuBgNVBAoMJ0NoaW5hIEZpbmFuY2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEbMBkGA1UEAwwSQ0ZDQSBBQ1MgU00yIE9DQTMxMB4XDTE4MDExNzAxMTExMFoXDTIzMDExNzAxMTExMFowgYIxCzAJBgNVBAYTAkNOMRswGQYDVQQKDBJDRkNBIEFDUyBTTTIgT0NBMzExDjAMBgNVBAsMBVNIQ1BFMRkwFwYDVQQLDBBPcmdhbml6YXRpb25hbC0xMSswKQYDVQQDDCIwNTFA5LiK5rW356Wo5o2u5Lqk5piT5omAQEFBQUFBQUAxMFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEz79HajSQLou2kkL6n26pCKkcKcbHTWR6MbArRQruWY+WDiyPhRaYLU4W6d8wBTDTOS6T5dCtSNZBxeb5qoeeNaOCAXYwggFyMGwGCCsGAQUFBwEBBGAwXjAoBggrBgEFBQcwAYYcaHR0cDovL29jc3AuY2ZjYS5jb20uY24vb2NzcDAyBggrBgEFBQcwAoYmaHR0cDovL2NybC5jZmNhLmNvbS5jbi9vY2EzMS9vY2EzMS5jZXIwHwYDVR0jBBgwFoAUCNjRJsRIfZzsrJjp8X9iuYDOqUUwDAYDVR0TAQH/BAIwADBIBgNVHSAEQTA/MD0GCGCBHIbvKgEEMDEwLwYIKwYBBQUHAgEWI2h0dHA6Ly93d3cuY2ZjYS5jb20uY24vdXMvdXMtMTQuaHRtMDsGA1UdHwQ0MDIwMKAuoCyGKmh0dHA6Ly9jcmwuY2ZjYS5jb20uY24vb2NhMzEvU00yL2NybDcyLmNybDAOBgNVHQ8BAf8EBAMCBsAwHQYDVR0OBBYEFIzDvi38AZLlWA/Wqfk93ZPe7qNgMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDBDAMBggqgRzPVQGDdQUAA0gAMEUCICDVyelEL86xbj0mAeMl3knQD0n2QKERtni/e82bQz/nAiEAjq5SKIaVJu9T/lkds3QQfgLpBX65Rwj2Scgc7cC2dVcxgdMwgdACAQEwZTBcMQswCQYDVQQGEwJDTjEwMC4GA1UECgwnQ2hpbmEgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MRswGQYDVQQDDBJDRkNBIEFDUyBTTTIgT0NBMzECBUCEF1MkMAwGCCqBHM9VAYMRBQAwDQYJKoEcz1UBgi0BBQAERzBFAiEA03ogUebmqNyLjD5/OXr4gSdVQfqp3yqrVVPgRmGPy1QCIBkHrzpSxw/ZPloL+t1GHlEp2rW7qVgy966/lQqE7UVH";
|
||||
X509 x509 = api.SYD_Get_X509_CertInfo_HA(testData.getBytes(), sign);
|
||||
System.out.println("验签结果" + x509);
|
||||
}
|
||||
|
||||
|
||||
public static void case3(SydSDNXApiImpl api) {
|
||||
|
||||
System.out.println("\n\n----- 裸签名 -----");
|
||||
String sign = api.nakedSign(testData.getBytes(), testCertNo);
|
||||
System.out.println("签名结果 " + sign);
|
||||
}
|
||||
|
||||
public static void case4(SydSDNXApiImpl api) {
|
||||
|
||||
System.out.println("\n\n----- 裸签名 -----");
|
||||
String sign = api.nakedSign(testData.getBytes(), testCertNo);
|
||||
System.out.println("签名结果 " + sign);
|
||||
//String sign = "dFOUuU+JVNEZO8494MV+xtPuMVhEjnXlilHlymK9Cz/jQ3m+lRKTbv4tfyo5Eb7MM7lqQi6cdwKZ/CLnkOa+Vsye4DDYYSweqsraLwdtrVcc1sw2KDHeJUao2SXIhdhgxSw+puiOCDq/4FsJADdnYprIp+GSLfjj7tuhbBBb0JCV6rnTutIozq2QDPQKEspzMxQ2TtbVQezfL3uMA5GuYNdJYz4eAasQtxTQS5dhe3/CaWbjBeL2kKhsvuMbP6wsx2HeuXvaf99OEBkyXq2fFPJtuU7WB4SIYKN1wI0BK/IMa0ULj1Q1SBakd5+iO8ckrokJJ6E2JH3Nd/mT+5DdRg==";
|
||||
|
||||
System.out.println("\n\n----- 验签 -----");
|
||||
boolean pass = api.SYD_NakedVerify(testData.getBytes(), sign, testUser);
|
||||
System.out.println("验签结果 " + pass);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
public class TestSM3 {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug","true");
|
||||
SydApi sydApi = (new SydApi4j()).connect("172.16.18.72", 8889,null , 10000);
|
||||
|
||||
byte[] data = new byte[64];
|
||||
data = "0000000000001234000000000000123411223312".getBytes();
|
||||
// data = "0000000000001234".getBytes();
|
||||
/*
|
||||
byte[] hash = sydApi.SM3Hash(
|
||||
null,
|
||||
data
|
||||
);
|
||||
|
||||
System.out.println(Util.bytes2HexString(hash) );*/
|
||||
byte[] bytes = sydApi.SYD_Encrypt_Data(2,"000012345600000101000000000", data,null,2,"0000001100000011".getBytes());
|
||||
// System.out.println("000012345600000100300000000".length());
|
||||
sydApi.SYD_Decrypt_Data(2, "000012345600000101000000000", bytes,null,2,"0000001100000011".getBytes());
|
||||
|
||||
|
||||
|
||||
sydApi.SYD_MAC_Data("000012345600000100300000000","1239172397129300","0000001100000011".getBytes(),null,1,2);
|
||||
// sydApi.MAC_Data("000012345600000100300000000","12391723971293",null);
|
||||
// sydApi.SYD_Disperse("000012345600000100300000000",0,1,"0000123400001234".getBytes(), 6, 0);
|
||||
sydApi.disconnect();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
public class TestSignDev {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
// // LMK 加密
|
||||
// String mpk = "0342000444764761741DB405927EA722AD11D9740B9884CE5FDFF8D55CAFA5D0A2A8AF2509FE98DCDD57D86029FB6760526FAC9CC8339B7346BCDF7900185835596DC5EE";
|
||||
// String msk = "000100006EAE89B76EA4852B3EA389BE3B5F4AA5AB433DB210B5A76BE2B0E1ED63016CC90000000000000000000000000000000000000000000000000000000000000000";
|
||||
//
|
||||
// String devchk = "313230303131313131313131313131313434333233363330343434353331343359ED844B507EE2D2F1A4AB1E27A75F6F55AFAEC33CD7A7E6D32FA92D3376A72C8F1DBF5A3DB27B45C005BA62978E97F7DAB8EBF119037F6624945596D5CC13ED";
|
||||
//
|
||||
// // 用会员端的设备做签名
|
||||
// SydApi member = (new SydApi4j()).connect("47.111.95.168", 8889,null , 10000);
|
||||
// RetWrap ret = member.SM2SignDEV(
|
||||
//
|
||||
// Util.hexString2Bytes( msk ),
|
||||
// Util.hexString2Bytes( mpk ),
|
||||
// "hq".getBytes()
|
||||
// );
|
||||
//
|
||||
// byte[] sign = (byte[]) ret.get("sign");
|
||||
// System.out.println( "sign " + Util.bytes2HexString( sign ) );
|
||||
|
||||
|
||||
// // 使用中心端加密机做验签
|
||||
// SydApi center = (new SydApi4j()).connect("172.16.17.162", 8889,null , 10000);
|
||||
//
|
||||
// byte[] v = Util.hexString2Bytes( devchk );
|
||||
// byte[] d = "hq".getBytes();
|
||||
// byte[] s = new byte[ v.length + d.length ];
|
||||
// System.arraycopy( d, 0 , s, 0, d.length );
|
||||
// System.arraycopy( v, 0 ,s, d.length, v.length );
|
||||
//
|
||||
// boolean r = center.SM2VerifyDEV(
|
||||
// sign,
|
||||
// Util.hexString2Bytes( mpk ),
|
||||
// s
|
||||
// );
|
||||
//
|
||||
// System.out.println( r ? "pass" : "ban");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestTps {
|
||||
|
||||
public void send(int threadNum, final int times) throws InterruptedException {
|
||||
|
||||
SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.17.162", 8889, 1000);
|
||||
final SydApi4j api = (SydApi4j) new SydApi4j();
|
||||
String pk = "03420004C9FD0B37230DF91621F6880C8123A445CB14FFB1B1342D0AC9449374876A4B1E00A15B9E8DF307EE538526883F093568C5B70C5A61BEF5F880C827DDC90366B5";
|
||||
String sk = "00010000C530EFBC1971D6526BDAB640370EE9197BFB0D78F88417C1ED49981FFEF226980000000000000000000000000000000000000000000000000000000000000000";
|
||||
final byte[] skByte = Util.hexString2Bytes(sk);
|
||||
final byte[] pkByte = Util.hexString2Bytes(pk);
|
||||
final String data = "MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>";
|
||||
|
||||
|
||||
//开始时间
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
List<Thread> list = new ArrayList<Thread>();
|
||||
for (int i = 0; i < threadNum; i++) {
|
||||
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int j = 0; j < times; j++) {
|
||||
api.SYD_SM2_Sign_HA(
|
||||
SydApi.DATA_ORIGIN,
|
||||
skByte,
|
||||
pkByte,
|
||||
data.getBytes()
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
list.add(thread);
|
||||
}
|
||||
|
||||
try {
|
||||
for(Thread thread : list){
|
||||
thread.join();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
//结束时间
|
||||
long endTime = System.currentTimeMillis();
|
||||
long useTime = endTime - startTime;
|
||||
long tps = (threadNum * times * 1000) / useTime;
|
||||
System.out.println(threadNum + "个线程,tps:" + tps);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
|
||||
TestTps testTps = new TestTps();
|
||||
int times = 100;
|
||||
testTps.send(2, times);
|
||||
// testTps.send(2, times);
|
||||
// testTps.send(4, times);
|
||||
// testTps.send(8, times);
|
||||
// testTps.send(12, times);
|
||||
// testTps.send(16, times);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
public void computeTps(int threadNum, final int times) {
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
//System.out.println(" main startTime:"+startTime);
|
||||
|
||||
//send(threadNum, times);
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
//System.out.println("main useTime:"+(endTime - startTime));
|
||||
|
||||
long useTime = endTime - startTime;
|
||||
// System.out.println("send useTime" + useTime);
|
||||
|
||||
long tps = (threadNum * times * 1000) / useTime;
|
||||
System.out.println(threadNum + "个线程,tps:" + tps);
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.trans.PacketSN;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TestUtil {
|
||||
public static void main(String[] args) throws Exception {
|
||||
/* PacketSN sn = PacketSN.gen();
|
||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||
packet.put("header", sn.getSn().array());
|
||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||
data.put("alg$option", 0);
|
||||
data.put("certificateModel$option", 0);
|
||||
data.put("certificateSn", "113123");
|
||||
data.put("keyType", "X");
|
||||
packet.put("data", data);
|
||||
SectionWrap s=new SectionWrap();
|
||||
HashMap<String, Section> sc = new HashMap<String, Section>();
|
||||
SectionValue s2=new SectionValue();
|
||||
s2.setValue("L".getBytes());
|
||||
sc.put("data",s2);
|
||||
s.setSections(sc);*/
|
||||
// HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||
// HashMap<String, Object> data = new HashMap<String, Object>();
|
||||
// packet.put("data", data);
|
||||
// PacketSN sn = PacketSN.gen();
|
||||
// packet.put("header", sn.getSn().array());
|
||||
// data.put("algorithmId$option", 0x1);
|
||||
// data.put("keyLength", 256);
|
||||
//
|
||||
// try {
|
||||
// byte[] a=(byte[]) Util.eval("ResE2","getKeyLen",packet,null,null);
|
||||
// System.out.println(a[0]);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
public class TestXianfeng {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug","true");
|
||||
|
||||
|
||||
SydApi sydApi = (new SydApi4j()).connect("172.16.18.72", 8889,null , 10000);
|
||||
|
||||
|
||||
// byte[] data = "0000000000001234000000000000123411223312".getBytes();
|
||||
// byte[] bytes = sydApi.SYD_Encrypt_Data(2,"000012345600000101000000000", data,null,2,"0000001100000011".getBytes());
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// sydApi.SYD_Decrypt_Data(2, "000012345600000101000000000", bytes,null,2,"0000001100000011".getBytes());
|
||||
|
||||
|
||||
|
||||
|
||||
byte[] mac = sydApi.SYD_MAC_Data("000012345600000100300000000","0000000a0200000000000120190927175528", "00000011000000110000001100000011".getBytes(),"1234567812345678",2,2);
|
||||
|
||||
|
||||
System.out.print("mac = ");
|
||||
System.out.println( Util.bytes2HexString(mac) );
|
||||
|
||||
|
||||
sydApi.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
public class TestY8 {
|
||||
|
||||
public static void testY8(){
|
||||
//SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.18.69", 8889, 1000);
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.18.226", 8500, null, 1000);
|
||||
api.GenerateRandom(8);
|
||||
System.out.println("===============");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
testY8();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.SydApiException;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
|
||||
class Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SydApi sydApi = null;
|
||||
try {
|
||||
System.out.println("SydApi 测试程序启动");
|
||||
//设置为调试模式 上线使用不需要
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
//建立链接
|
||||
sydApi = (new SydApi4j()).connect("172.16.17.162", 8889, null, 30000);
|
||||
System.out.println("连接成功");
|
||||
|
||||
//原始数据
|
||||
byte[] data = "cdb1af4bb0ab6de6".getBytes("UTF-8");
|
||||
//加解密密钥
|
||||
String key1 = "000079500100000101000000000";
|
||||
//MAC密钥
|
||||
String key2 = "000079500100000100300000001";
|
||||
//MAC数据
|
||||
String data2 = "000000000600000000000120190927164948";
|
||||
//分散因子
|
||||
String data3 = "0000000000002456aece4be200050001";
|
||||
// 随机数
|
||||
String pRandom = "0000000000000000";
|
||||
//加密
|
||||
byte[] bytes = sydApi.SYD_Encrypt_Data(2, key1, data, null, 2, data3.getBytes());
|
||||
System.out.println("Encrypt:" + new String(bytes, "UTF-8"));
|
||||
//解密
|
||||
sydApi.SYD_Decrypt_Data(2, key1, bytes, null, 2, data3.getBytes());
|
||||
//生成MAC
|
||||
byte[] macBytes = sydApi.SYD_MAC_Data(key2, data2, data3.getBytes(), pRandom, 2, 2);
|
||||
|
||||
System.out.println("MAC:" + new String(macBytes, "UTF-8"));
|
||||
|
||||
System.out.println("执行结束");
|
||||
sydApi.disconnect();
|
||||
} catch (SydApiException e) {
|
||||
System.out.print("执行错误1:" + e);
|
||||
|
||||
} catch (Exception ex) {
|
||||
System.out.print("执行错误2:" + ex);
|
||||
} finally {
|
||||
if (sydApi != null) {
|
||||
sydApi.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.sunyard.sydapi.test
|
||||
|
||||
import com.sunyard.proto.Util
|
||||
import kotlin.experimental.xor
|
||||
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
// val k1 = Util.hexString2Bytes(String(Util.hexString2Bytes("61613030313131313131313131313131")))
|
||||
// val k2 = Util.hexString2Bytes( String( Util.hexString2Bytes("33303435333533353331343133353338")))
|
||||
//
|
||||
//
|
||||
// println( String(k1) )
|
||||
// println( String(k2) )
|
||||
//
|
||||
//
|
||||
// val d = ByteArray(8)
|
||||
// for ( i in 0..7 ){
|
||||
// d[i] = k1[i] xor k2[i]
|
||||
// }
|
||||
//
|
||||
// println(Util.bytes2HexString(d) )
|
||||
// println( String(d) )
|
||||
|
||||
|
||||
val k1 = Util.hexString2Bytes("61613030313131313131313131313131")
|
||||
val k2 = Util.hexString2Bytes("33303435333533353331343133353338")
|
||||
|
||||
|
||||
println( String(k1) )
|
||||
println( String(k2) )
|
||||
|
||||
|
||||
val d = ByteArray(16)
|
||||
for ( i in 0..15 ){
|
||||
d[i] = k1[i] xor k2[i]
|
||||
}
|
||||
|
||||
println( Util.bytes2HexString(d) )
|
||||
println( String(d) )
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.proto.ProtocolParser;
|
||||
import com.sunyard.proto.ProtocolSet;
|
||||
import com.sunyard.proto.Util;
|
||||
import com.sunyard.proto.loader.Loader;
|
||||
import com.sunyard.proto.loader.ResourceLoader;
|
||||
|
||||
public class parseTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String test = "00C600000000000000013642303030313031303034323832343532303136384D4877434944674F4A375A327A6262447368426C456D394479506541444B4656366B376F473050526E5348743343654841694541734F58682F35694138574E5736676A483855445849376F464E744B597A69536A4F5939757048474F3845384549424935357438424E4E744556754E4E415A4472645762676F59414D6F6C487534344D56327973785153586E42424F794B43464B34316D4F303845382B2B592F524E67646349736558";
|
||||
byte[] indata = Util.hexString2Bytes(test);
|
||||
Loader loader = new ResourceLoader( "^packet.racal.sunyard.*");
|
||||
ProtocolSet pset = new ProtocolSet(loader);
|
||||
ProtocolParser parser = pset.getProtocolResParse();
|
||||
//Packet packet = parser.parse(ByteBuffer.wrap(indata));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//System.out.println(packet.toMap());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.proto.ProtocolRender;
|
||||
import com.sunyard.proto.ProtocolSet;
|
||||
import com.sunyard.proto.Util;
|
||||
import com.sunyard.proto.loader.Loader;
|
||||
import com.sunyard.proto.loader.ResourceLoader;
|
||||
import com.sunyard.trans.PacketSN;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class rendTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Loader loader = new ResourceLoader( "^packet.racal.sunyard.*");
|
||||
ProtocolSet pset = new ProtocolSet(loader);
|
||||
ProtocolRender render = pset.getProtocolReqRender("E2");
|
||||
|
||||
// 填充数据
|
||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||
packet.put("data",data);
|
||||
PacketSN sn = PacketSN.gen();
|
||||
packet.put("header", sn.getSn().array());
|
||||
data.put("algorithmId", 0x1);
|
||||
data.put("keyLength", 256);
|
||||
|
||||
ByteBuffer buf = render.rend( packet );
|
||||
System.out.println(Util.bytes2HexString(Util.toArray(buf)));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.sunyard.sydapi.test
|
||||
|
||||
def a = "P".charAt(0)
|
||||
|
||||
println 'P' == a
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<img src="http://www.sydtech.com.cn:32123/images/捕获.PNG">
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,185 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import com.sunyard.DaToSHCA;
|
||||
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
|
||||
public class testDemo {
|
||||
public static DaToSHCA.da_handle tmpHandle = new DaToSHCA.da_handle();
|
||||
public static DaToSHCA tmpTest = new DaToSHCA();
|
||||
|
||||
public static byte[] HashData;
|
||||
public static String SignData;
|
||||
|
||||
public static void mainHandle() {
|
||||
System.out.println("/*---------------------*/");
|
||||
System.out.println("/* 1. SM3分步哈希 ");
|
||||
System.out.println("/* 2. SM2签名 ");
|
||||
System.out.println("/* 3. SM2验证 ");
|
||||
System.out.println("/* 0. exit ");
|
||||
System.out.println("/*---------------------*/");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
//==============创建连接=============
|
||||
boolean OpenFlag = tmpTest.DA_OpenHsmServer(tmpHandle, "172.16.18.73",8889);
|
||||
if (!OpenFlag) {
|
||||
System.out.println("[ERROR] DA_OpenHsmServer error ...");
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
System.out.println("[SUCCESS] DA_OpenHsmServer success ...");
|
||||
}
|
||||
|
||||
while(true) {
|
||||
mainHandle();
|
||||
Scanner scan = new Scanner(System.in);
|
||||
System.out.print("Please Input Number: ");
|
||||
int choice = scan.nextInt();
|
||||
|
||||
switch(choice) {
|
||||
case 1:
|
||||
try {
|
||||
testSM3Hash();
|
||||
} catch (Exception e) {
|
||||
System.out.println("[ERROR] testSM3: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
try {
|
||||
testDA_SM2Sgin();
|
||||
} catch (Exception e) {
|
||||
System.out.println("[ERROR] testDA_SM2Sgin: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
try {
|
||||
testDA_SM2Verify();
|
||||
} catch (Exception e) {
|
||||
System.out.println("[ERROR] testDA_SM2Verify: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
scan.close();
|
||||
// ==============释放连接=============
|
||||
boolean CloseFlag = tmpTest.DA_CloseHsmServer(tmpHandle);
|
||||
if (!CloseFlag) {
|
||||
System.out.println("[ERROR] DA_CloseHsmServer error ...");
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
System.out.println("[SUCCESS] DA_CloseHsmServer success ...");
|
||||
}
|
||||
return ;
|
||||
default:
|
||||
System.out.println("Number Error, Please Input Again ...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void testSM3Hash() throws Exception {
|
||||
byte[] InData = getInData("d:\\TestFile.txt");
|
||||
|
||||
// 获取 SM3 Hash运算公钥
|
||||
byte[] sm2Pub = tmpTest.DA_GetSM2PublicKey(tmpHandle, 3).getEncoded();
|
||||
|
||||
// SM3 初始化
|
||||
tmpTest.SM3_Init(tmpHandle, sm2Pub);
|
||||
|
||||
// SM3 Updata
|
||||
int p = InData.length/128;
|
||||
int q = InData.length%128;
|
||||
|
||||
for(int i=0; i<p; i++) {
|
||||
byte[] Data = new byte[128];
|
||||
System.arraycopy(InData, 128*i, Data, 0, 128);
|
||||
tmpTest.SM3_Updata(tmpHandle, Data);
|
||||
}
|
||||
byte[] Data = new byte[q];
|
||||
System.arraycopy(InData, 128*p, Data, 0, q);
|
||||
tmpTest.SM3_Updata(tmpHandle, Data);
|
||||
|
||||
// SM3 结束
|
||||
HashData = tmpTest.SM3_Final(tmpHandle);
|
||||
if (HashData == null) {
|
||||
System.out.println("[ERROR] DA_DigestTmp error ...");
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
System.out.println("[SUCCESS] DA_DigestTmp success ...\n");
|
||||
|
||||
// 打印16进制 SM3 Hash数据
|
||||
System.out.println(">>>> Hex HashData[" + HashData.length + "] = ");
|
||||
System.out.println(bin2HexString(HashData));
|
||||
}
|
||||
}
|
||||
|
||||
public static void testDA_SM2Sgin() throws Exception {
|
||||
// 对数据进行 SM2签名
|
||||
SignData = new String(tmpTest.DA_SM2Sgin(tmpHandle, 3,HashData ));
|
||||
if (SignData == null) {
|
||||
System.out.println("[ERROR] DA_SM2Sgin error ...");
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
System.out.println("[SUCCESS] DA_SM2Sgin success ...\n");
|
||||
|
||||
// 打印 Base64编码后的 DER格式的 SM2签名数据
|
||||
System.out.println(">>>> Base64 Der SignData[" + SignData.length() + "] = ");
|
||||
System.out.println(SignData);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void testDA_SM2Verify() throws Exception {
|
||||
// 获取SM2公钥
|
||||
byte[] sm2Pub = tmpTest.DA_GetSM2PublicKey(tmpHandle, 3).getEncoded();
|
||||
|
||||
// 对数据及签名值进行 SM2验签
|
||||
boolean VerifyFlag = tmpTest.DA_SM2Verify(tmpHandle, HashData, SignData, sm2Pub);
|
||||
if (!VerifyFlag) {
|
||||
System.out.println("[ERROR] DA_SM2Verify error ...");
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
System.out.println("[SUCCESS] DA_SM2Verify success ...");
|
||||
}
|
||||
}
|
||||
|
||||
// 读取文件内容
|
||||
public static byte[] getInData(String fileName) throws Exception {
|
||||
FileInputStream tmpInput = new FileInputStream(fileName);
|
||||
int InDataLen = tmpInput.available();
|
||||
|
||||
byte[] InData = new byte[InDataLen];
|
||||
|
||||
tmpInput.read(InData);
|
||||
tmpInput.close();
|
||||
|
||||
System.out.println("[Info] Read File:{" + fileName + "}, Read Length:{" + InDataLen + "} ...");
|
||||
|
||||
return InData;
|
||||
}
|
||||
|
||||
// 2进制数组 转化为 16进制字符串
|
||||
public static String bin2HexString(byte[] tmpBin) {
|
||||
StringBuilder tmpStrB = new StringBuilder();
|
||||
|
||||
for(int i=0; i<tmpBin.length; i++) {
|
||||
tmpStrB.append(String.format("%02x ", tmpBin[i]));
|
||||
if (i%16 == 15) {
|
||||
tmpStrB.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return new String(tmpStrB);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.sunyard.sydapi.test;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.SydApiException;
|
||||
public class tt22 {
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
SydApi key=null;
|
||||
try{
|
||||
System.out.println("SydApi 测试程序启动");
|
||||
|
||||
System.setProperty("com.sunyard.sydapi4j.debug","true");
|
||||
|
||||
key = new SydApi4j().connect("172.16.18.226",8889,null,10000);
|
||||
System.out.println("连接成功");
|
||||
|
||||
//原始数据
|
||||
byte[] data = "asfkahfkahfkahdaghfashflsaldfasf".getBytes();
|
||||
//X509 证书的序列号
|
||||
String pCertSerial = "1004282452";
|
||||
//数据明文
|
||||
byte[] data2 = "asfkahfkahfkafadfhdaghfashadfaflsaldfasf".substring(0,32).getBytes();
|
||||
|
||||
//签名
|
||||
String bs = key.detachedSignbysn(0,data2,pCertSerial);
|
||||
// key.detachedSign(1,data2,1004282451);
|
||||
//验签
|
||||
key.SYD_Get_X509_CertInfo_HA(data2,new String(bs));
|
||||
|
||||
|
||||
System.out.println("执行结束\n\n" );
|
||||
key.disconnect();
|
||||
}catch(SydApiException e){
|
||||
System.out.print("执行错误:"+e);
|
||||
key.disconnect();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user