diff --git a/pom.xml b/pom.xml index 19526e1..d34bf3d 100644 --- a/pom.xml +++ b/pom.xml @@ -56,5 +56,107 @@ + + + + org.apache.maven.plugins + maven-shade-plugin + 2.4.3 + + + package + + shade + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + ${project.artifactId}-${project.version} + + + com.sunyard.security.Main + + + + META-INF/spring.handlers + + + META-INF/spring.schemas + + + META-INF/spring.tooling + + + Apache CXF + + + META-INF/cxf/cxf.extension + + + META-INF/extensions.xml + + + META-INF/cxf/extensions.xml + + + META-INF/cxf/bus-extensions.txt + + + META-INF/cxf/bus-extensions.xml + + + META-INF/wsdl.plugin.xml + + + META-INF/cxf/java2wsbeans.xml + + + META-INF/spring.handlers + + + META-INF/spring.schemas + + + + + + + + + + + com.github.edwgiz + maven-shade-plugin.log4j2-cachefile-transformer + 2.6.1 + + + + + \ No newline at end of file diff --git a/src/main/java/com/sunyard/security/Main.java b/src/main/java/com/sunyard/security/Main.java new file mode 100644 index 0000000..74b58b4 --- /dev/null +++ b/src/main/java/com/sunyard/security/Main.java @@ -0,0 +1,69 @@ +package com.sunyard.security; + +import com.sun.jna.Pointer; +import com.sun.jna.ptr.PointerByReference; +import com.sunyard.security.sdf.SDFJna; +import com.sunyard.security.util.ByteUtil; + +public class Main { + private static PointerByReference phDeviceHandle = new PointerByReference(); + private static PointerByReference phSessionHandle = new PointerByReference();; + private static final byte[] data = new byte[16]; + private static final byte[] symKey = new byte[]{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9}; + private static final String ip = "172.16.17.245"; + + + public static void random(){ + + int oneSize = 16; + byte[] oneRadom = new byte[16]; // 注意这里初始化大小应为 oneSize + int ret = SDFJna.INSTANCE.SDF_GenerateRandom( phSessionHandle.getValue(), oneSize, oneRadom ); + + if (ret != 0) { + throw new RuntimeException(String.format("0x%02X", ret)); + } else { + System.out.println("调用成功"); + } + System.out.println( ByteUtil.bytes2HexString( oneRadom ) ); + } + + + public static void main(String[] args) { + + // 打开设备 + int ret = SDFJna.INSTANCE.SDF_OpenDevice( + phDeviceHandle, + ByteUtil.safeStringBytes(ip), + 8889, + 3000, + 3000, + 0); + + if (ret != 0) { + System.err.println("打开设备失败 错误码:" + String.format("0x%02X", ret)); + throw new RuntimeException(String.format("0x%02X", ret)); + } + Pointer hDeviceHandle = phDeviceHandle.getValue(); + // 打开会话 + ret = SDFJna.INSTANCE.SDF_OpenSession(hDeviceHandle, phSessionHandle); + if (ret != 0) { + System.err.println("打开设备失败 错误码:" + String.format("0x%02X", ret)); + throw new RuntimeException(String.format("0x%02X", ret)); + } + + + try { + random(); + + } finally { + if ( null != phSessionHandle.getValue() ) { + SDFJna.INSTANCE.SDF_CloseSession( phSessionHandle.getValue() ); + } + if ( null != phDeviceHandle.getValue() ) { + SDFJna.INSTANCE.SDF_CloseDevice(phDeviceHandle.getValue()); + } + } + + } + +} diff --git a/src/main/resources/linux-aarch64/libsdf.so b/src/main/resources/linux-aarch64/liblibsdf.so similarity index 100% rename from src/main/resources/linux-aarch64/libsdf.so rename to src/main/resources/linux-aarch64/liblibsdf.so diff --git a/src/main/resources/linux-x86-64/libsdf.so b/src/main/resources/linux-x86-64/liblibsdf.so similarity index 100% rename from src/main/resources/linux-x86-64/libsdf.so rename to src/main/resources/linux-x86-64/liblibsdf.so