mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
Merge branch 'master' of gitee.com:willfree/min-dev-java
This commit is contained in:
commit
442b4e3544
2 files changed
+8
-6
No files matched your search
@@ -14,6 +14,7 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.jce.spec.ECParameterSpec;
|
||||
import org.bouncycastle.math.ec.ECPoint;
|
||||
import org.bouncycastle.math.ec.custom.gm.SM2P256V1Curve;
|
||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.math.BigInteger;
|
||||
@@ -187,11 +188,11 @@ public class SM2Base {
|
||||
**/
|
||||
public static byte[] byteArraytoHexByteArray(byte[] bytes){
|
||||
// 16进制表示法
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(int i=0;i < bytes.length;i++) {
|
||||
sb.append(String.format("%02x", bytes[i]));
|
||||
}
|
||||
String hexStr = sb.toString();
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// for(int i=0;i < bytes.length;i++) {
|
||||
// sb.append(String.format("%02x", bytes[i]));
|
||||
// }
|
||||
String hexStr = ByteUtils.toHexString(bytes);
|
||||
return hexStr.getBytes();
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public class SM2PrivateKey implements PrivateKeyInterface {
|
||||
*/
|
||||
// TODO 实现不同
|
||||
public boolean setBytes(byte[] d){
|
||||
if (d.length != 64 && d.length != 32 && d.length != 33)
|
||||
if (d.length != 64 && d.length != 66 && d.length != 32 && d.length != 33)
|
||||
return false;
|
||||
switch (d.length){
|
||||
case 32:
|
||||
@@ -83,6 +83,7 @@ public class SM2PrivateKey implements PrivateKeyInterface {
|
||||
privateKey = new ECPrivateKeyParameters(new BigInteger(d), SM2Base.DOMAIN_PARAMS);
|
||||
break;
|
||||
case 64:
|
||||
case 66:
|
||||
d = SM2Base.hexByteArrayToByteArray(d);
|
||||
privateKey = new ECPrivateKeyParameters(new BigInteger(d), SM2Base.DOMAIN_PARAMS);
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user