popezlotado / sm2java Goto Github PK
View Code? Open in Web Editor NEW国密SM2,SM3 Java实现
国密SM2,SM3 Java实现
所有分支最终都是通过获取完整的byte[]来生成hash,处理大文件会溢出,可以先获取输入流,每次读取64字节,最后一次不足64再做padding补齐
怎么在sm2密钥协商时自定义公钥和私钥?不用sm2自己生成的。
一直没理解ECDH密钥协商和SM2密钥协商算法的区别,请各位大佬解答!!!
BigInteger h = ecc_bc_spec.getH();
if (h != null) {
ECPoint S = publicKey.multiply(h);
if (S.isInfinity())
throw new IllegalStateException();
}
in my environment it warns in ECPoint S = publicKey.multiply(h) of NULLPoint Exception , please check Exception in thread "main" java.lang.NullPointerException
at com.SM2.encrypt(SM2.java:146)
at com.SM2.main(SM2.java:816)
怎样在使用同一个私钥的情况下,生成多套公钥?
这里只有sm2的公钥加密和私钥解密,有没有私钥加密公钥解密的呢
byte[] ENTLA = new byte[] { (byte) (entlenA & 0xFF00), (byte) (entlenA & 0x00FF) };
是不是应该是
byte[] ENTLA = new byte[] { (byte) (entlenA>>8 & 0xFF), (byte) (entlenA & 0x00FF) };
使用openssl中sm2算法生成的公私钥,用importPublicKey和importPrivateKey方法,会报错:
“Exception in thread "main" java.lang.IllegalArgumentException: Invalid point encoding 0x30
at org.bouncycastle.math.ec.ECCurve.decodePoint(Unknown Source)”
sm3 如何使用秘钥做盐,请教一下有没有资料
delete, nothing
1、生成key
SM2 sm02 = new SM2();
SM2KeyPair keys = sm02.generateKeyPair();
ECPoint pubKey = keys.getPublicKey();
// out 2ffa1c356eb368e0c01246d56b6332332843f445331612333588d8b36edfe50bca3ef3eeed3525e8e4ecbfa1dd67d1bcf837fe246006808672f4c06998d43b41fffffffeffffffffffffffffffffffffffffffff00000000fffffffffffffffc
BigInteger privKey = keys.getPrivateKey();
// out : 78880826087100835029051542171897323970932661971431311512363814016306171906887
2、js加密
https://github.com/lifesreason/SM2/
var encryptData = sm2Encrypt('测试数据', '2ffa1c356eb368e0c01246d56b6332332843f445331612333588d8b36edfe50bca3ef3eeed3525e8e4ecbfa1dd67d1bcf837fe246006808672f4c06998d43b41fffffffeffffffffffffffffffffffffffffffff00000000fffffffffffffffc');
3、java解密
BigInteger bi1=new BigInteger("78880826087100835029051542171897323970932661971431311512363814016306171906887");
System.out.println("解密后明文:" + sm02.decrypt(SM2.hex2String("043ef984f9b18adb082518a29141b033db6dbe64995a72fcfee14440e0ac92bea7890ba276283efbcdc0e54962d64b75a018a73d54250d8af5d91b787305e66c45f84c14526587936c251867531cedb859569d14a4632c0333dfbe51a58f1d096aada78f2b539be43073a67f62"), bi1));
解密失败
您好,我已经有正确的公私钥对,公钥的坐标记作(x,y)。请问在您的代码中,怎么使用已知的公钥坐标正确的实例化 ECPoint PublicKey?
谢谢!
socket通信的时候好麻烦.签名的长度总是变化的.
BigInteger 在转化为byte数组时会会出现一个补位,导致最后的sm3-Hash的计算作物,ZA计算错误
需要在计算sm3杂凑值时,做如下处理
byte[] array = bigInteger.toByteArray();
if (array[0] == 0) {
byte[] tmp = new byte[array.length - 1];
System.arraycopy(array, 1, tmp, 0, tmp.length);
array = tmp;
}
SM2.java中的byte[] ZA(String IDA,Ecpoint aPublicKey)中处理
//这一行的sm3hash中的参数都要做上面的处理
byte[] ZA=sm3hash(............................);
请参阅SM2椭圆曲线公钥密码算法-P54 用户其他信息一栏。
USERID非IDa
设用户A的身份是:[email protected]。用ASCII编码记ID A :
414C 49434531 32334059 41484F4F 2E434F4D。ENTL A =0090。
https://github.com/hyfree/SM2_SM3_SM4Encrypt/tree/add_pdf/pdf
KDF计算出来的结果跟国标文档里算出来的不一致。
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.