gmssl / gmssl-java Goto Github PK
View Code? Open in Web Editor NEWJava interface of the GmSSL library
Home Page: https://gmssl.github.io/GmSSL-Java
License: Apache License 2.0
Java interface of the GmSSL library
Home Page: https://gmssl.github.io/GmSSL-Java
License: Apache License 2.0
https://github.com/GmSSL/GmSSL-Java/blob/main/src/test/java/org/gmssl/Sm2Test.java
具体原因是因为 @BeforeTest 每次都重新生成key
@Before
public void beforeTest(){
sm2_key = new Sm2Key();
sm2_key.generateKey();
}
需要将key固化到磁盘,然后在其他的测试用例内加载,即可解决问题
class TestSm2 {
private val sm2Key = Sm2Key(has_private_key = true)
@Test
fun generateKeys() {
sm2Key.generateKey()
sm2Key.exportPublicKeyInfoPem("publickey.pem")
sm2Key.exportEncryptedPrivateKeyInfoPem("12345678", "privatekey.pk8")
}
private fun loadKeys() {
sm2Key.importPublicKeyInfoPem("publickey.pem")
sm2Key.importEncryptedPrivateKeyInfoPem("12345678", "privatekey.pk8")
}
@Test
fun testEncrypt() {
loadKeys()
val testStr = "gmssl"
val ciphertext = sm2Key.encrypt(testStr.toByteArray())
val textHex = HexUtil.byteToHex(ciphertext)
println(textHex)
}
@Test
fun testDecrypt() {
loadKeys()
val textHex = "306f0221008d769703b894dbf832409e2497f87a52bd203d83e7d56616a95ff8597ee0b5fb022100befc69ee3141f53e94ddfa2155f1bd3289e5c7b6cdc828bd4b7fdd49f4360d0f04206300ec08d80eab55c7999fb5c114da7398d76d575bc20ddf881627497fd14aa404051136b536c6"
val ciphertext = HexUtil.hexToByte(textHex)
val plaintext = sm2Key.decrypt(ciphertext)
val plaintextStr = String(plaintext)
println(plaintextStr)
}
}
GmSSL-Java/src/main/c/gmssljni.c:21:10: fatal error: 'gmssl/aead.h' file not found
[root@localhost build]# make [ 20%] Building C object CMakeFiles/gmssljni-native.dir/gmssljni.c.o /home/zc/GmSSL-Java-main/gmssljni.c:14:23: 致命错误:gmssl/sm2.h:没有那个文件或目录 #include <gmssl/sm2.h> ^ 编译中断。 make[2]: *** [CMakeFiles/gmssljni-native.dir/gmssljni.c.o] 错误 1 make[1]: *** [CMakeFiles/gmssljni-native.dir/all] 错误 2 make: *** [all] 错误 2
@yxk123 作者您好,请问为什么在maven仓库找不到GmSSLJNI依赖?
你好,请问什么时候支持zuc算法。
在Sm3、Sm4Cbc传入long sm4_cbc_ctx、sm3_cbc_ctx时,Java应用程序崩溃,发生了SIGSEGV信号,访问了无效的内存地址:
运行后错误提示
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\admin\AppData\Local\Temp\libgmssljni359268608746332705.dll: Can't load this .dll (machine code=0xbd) on a AMD 64-bit platform at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1934) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1817) at java.lang.Runtime.load0(Runtime.java:809) at java.lang.System.load(System.java:1086) at org.gmssl.NativeLoader.load(NativeLoader.java:60) at org.gmssl.GmSSLJNI.<clinit>(GmSSLJNI.java:360) at org.gmssl.Sm2Key.importPublicKeyInfoDer(Sm2Key.java:91) at cn.stylefeng.guns.base.BaseJunit.main(BaseJunit.java:47)
有人对接过UKey是直接使用目前库还是要找其他厂家要SKF库?
比如海泰、龙脉等厂家。
执行mvn clean package构建时出现如下错误, 我是从github这边clone的最新的包
[ 50%] Building C object CMakeFiles/gmssljni-native.dir/gmssljni.c.o
/mnt/filemanage/tools/GmSSL-Java/src/main/c/gmssljni.c:21:10: 致命错误:gmssl/aead.h:No such file or directory
21 | #include <gmssl/aead.h>
| ^~~~~~~~~~~~~~
编译中断。
gmake[2]: *** [CMakeFiles/gmssljni-native.dir/build.make:76:CMakeFiles/gmssljni-native.dir/gmssljni.c.o] 错误 1
gmake[1]: *** [CMakeFiles/Makefile2:83:CMakeFiles/gmssljni-native.dir/all] 错误 2
gmake: *** [Makefile:91:all] 错误 2
[WARNING] Command: [/mnt/filemanage/tools/GmSSL-Java/target/dependency/cmake/bin/cmake, --build, /mnt/filemanage/tools/GmSSL-Java/target/build]
[WARNING] Directory: null
看代码和描述没有GMTLS通信相关的能力
按文档编译指示,在Ubuntu22.04上命令行编译
mkdir build
cd build
cmake ..
这都没问题,但是make的时候报错以下,似乎是无法正确引用java依赖库:
[ 20%] Building C object CMakeFiles/gmssljni-native.dir/gmssljni.c.o
[ 40%] Linking C shared library libgmssljni.so
[ 40%] Built target gmssljni-native
[ 60%] Building Java objects for GmSSLJNI.jar
src/main/java/org/gmssl/NativeLoader.java:11: error: package org.apache.maven.model does not exist
import org.apache.maven.model.Model;
^
src/main/java/org/gmssl/NativeLoader.java:12: error: package org.apache.maven.model.io.xpp3 does not exist
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
^
src/main/java/org/gmssl/NativeLoader.java:13: error: package org.codehaus.plexus.util.xml.pull does not exist
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
^
src/main/java/org/gmssl/NativeLoader.java:159: error: cannot find symbol
Model model = new MavenXpp3Reader().read(new FileReader("pom.xml"));
^
symbol: class Model
location: class NativeLoader
src/main/java/org/gmssl/NativeLoader.java:159: error: cannot find symbol
Model model = new MavenXpp3Reader().read(new FileReader("pom.xml"));
^
symbol: class MavenXpp3Reader
location: class NativeLoader
src/main/java/org/gmssl/NativeLoader.java:161: error: cannot find symbol
} catch (IOException | XmlPullParserException e) {
^
symbol: class XmlPullParserException
location: class NativeLoader
6 errors
make[2]: *** [CMakeFiles/GmSSLJNI.dir/build.make:103: CMakeFiles/GmSSLJNI.dir/java_compiled_GmSSLJNI] Error 1
make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/GmSSLJNI.dir/all] Error 2
make: *** [Makefile:101: all] Error 2
Running org.gmssl.Sm2Test
Tests run: 7, Failures: 0, Errors: 7, Skipped: 0, Time elapsed: 0.115 sec <<< FAILURE!
computeZTest(org.gmssl.Sm2Test) Time elapsed: 0.069 sec <<< ERROR!
java.lang.UnsatisfiedLinkError: /home/hdq/trials/GmSSL-Java-main/target/classes/lib/libgmssljni.so: libgmssl.so.3: cannot open shared object file: No such file or directory
at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2450)
at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2506)
at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2705)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2635)
at java.base/java.lang.Runtime.load0(Runtime.java:768)
at java.base/java.lang.System.load(System.java:1854)
at org.gmssl.NativeLoader.loadLibFile(NativeLoader.java:126)
at org.gmssl.NativeLoader.load(NativeLoader.java:59)
at org.gmssl.GmSSLJNI.(GmSSLJNI.java:360)
at org.gmssl.Sm2Key.generateKey(Sm2Key.java:51)
at org.gmssl.Sm2Test.beforeTest(Sm2Test.java:33)
确认GmSSL已安装到/usr/local/lib,且GmSSL和GmSSL-Java都使用最新dev版,甚至均使用readme指示的zip代码也一样。
以上应该都是小问题,请教解决方法,谢谢。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.