mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
identity(without persist & without test)
This commit is contained in:
1 parent
9d370a5353
commit
755ddc2129
21 files changed
+588
-144
No files matched your search
+2
-4
@@ -1,6 +1,5 @@
|
||||
package minsecurity.crypto.sm2;
|
||||
|
||||
import minsecurity.Common;
|
||||
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
||||
import org.bouncycastle.crypto.generators.ECKeyPairGenerator;
|
||||
import org.bouncycastle.crypto.params.ECDomainParameters;
|
||||
@@ -17,7 +16,6 @@ import org.bouncycastle.math.ec.ECPoint;
|
||||
import org.bouncycastle.math.ec.custom.gm.SM2P256V1Curve;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.crypto.KeyGenerator;
|
||||
import java.math.BigInteger;
|
||||
import java.security.*;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
@@ -32,13 +30,13 @@ import static minsecurity.Common.ALGO_NAME_EC;
|
||||
* @Date: 18:48 2021/03/03
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class Sm2Base {
|
||||
public class SM2Base {
|
||||
|
||||
static {
|
||||
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
|
||||
}
|
||||
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Sm2Base.class);
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SM2Base.class);
|
||||
|
||||
/*
|
||||
* 以下为SM2推荐曲线参数
|
||||
+2
-2
@@ -7,8 +7,8 @@ package minsecurity.crypto.sm2;
|
||||
* @Date: 19:00 2021/03/03
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class Sm2Exception extends java.lang.Exception {
|
||||
public Sm2Exception(String msg){
|
||||
public class SM2Exception extends java.lang.Exception {
|
||||
public SM2Exception(String msg){
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
+10
-10
@@ -20,9 +20,9 @@ import java.security.SecureRandom;
|
||||
* @Date: 19:40 2021/03/03
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class Sm2PrivateKey implements PrivateKeyInterface {
|
||||
public class SM2PrivateKey implements PrivateKeyInterface {
|
||||
|
||||
public Sm2PrivateKey(){}
|
||||
public SM2PrivateKey(){}
|
||||
|
||||
/*
|
||||
* @param d
|
||||
@@ -37,24 +37,24 @@ public class Sm2PrivateKey implements PrivateKeyInterface {
|
||||
* @author hongyu guo
|
||||
* @date 2021/3/7
|
||||
**/
|
||||
public Sm2PrivateKey(byte[] d) {
|
||||
public SM2PrivateKey(byte[] d) {
|
||||
if(d.length == 32 || d.length == 33)
|
||||
privateKey = new ECPrivateKeyParameters(new BigInteger(d), Sm2Base.DOMAIN_PARAMS);
|
||||
privateKey = new ECPrivateKeyParameters(new BigInteger(d), SM2Base.DOMAIN_PARAMS);
|
||||
else {
|
||||
try {
|
||||
throw new Sm2Exception("SM2私钥中,参数d长度应为32/33");
|
||||
} catch (Sm2Exception e) {
|
||||
throw new SM2Exception("SM2私钥中,参数d长度应为32/33");
|
||||
} catch (SM2Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public Sm2PrivateKey(byte[] d, ECDomainParameters parameters){
|
||||
public SM2PrivateKey(byte[] d, ECDomainParameters parameters){
|
||||
if(d.length == 32 || d.length == 33)
|
||||
privateKey = new ECPrivateKeyParameters(new BigInteger(d), parameters);
|
||||
else {
|
||||
try {
|
||||
throw new Sm2Exception("SM2私钥中,参数d长度应为32/33");
|
||||
} catch (Sm2Exception e) {
|
||||
throw new SM2Exception("SM2私钥中,参数d长度应为32/33");
|
||||
} catch (SM2Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class Sm2PrivateKey implements PrivateKeyInterface {
|
||||
public boolean setBytes(byte[] d) {
|
||||
if(d.length != 32 && d.length != 33)
|
||||
return false;
|
||||
privateKey = new ECPrivateKeyParameters(new BigInteger(d), Sm2Base.DOMAIN_PARAMS);
|
||||
privateKey = new ECPrivateKeyParameters(new BigInteger(d), SM2Base.DOMAIN_PARAMS);
|
||||
return true;
|
||||
}
|
||||
|
||||
+7
-7
@@ -20,11 +20,11 @@ import java.security.SecureRandom;
|
||||
* @Date: 17:32 2021/03/03
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class Sm2PublicKey implements PublicKeyInterface {
|
||||
public class SM2PublicKey implements PublicKeyInterface {
|
||||
|
||||
public Sm2PublicKey(){}
|
||||
public SM2PublicKey(){}
|
||||
|
||||
public Sm2PublicKey(byte[] xBytes, byte[] yBytes, ECCurve curve, ECDomainParameters domainParameters){
|
||||
public SM2PublicKey(byte[] xBytes, byte[] yBytes, ECCurve curve, ECDomainParameters domainParameters){
|
||||
publicKey = createPublicKey(xBytes,yBytes,curve,domainParameters);
|
||||
}
|
||||
/**
|
||||
@@ -35,11 +35,11 @@ public class Sm2PublicKey implements PublicKeyInterface {
|
||||
* @author ghy
|
||||
* @date 2021/3/7
|
||||
**/
|
||||
public Sm2PublicKey(byte[] xBytes, byte[] yBytes){
|
||||
this(xBytes,yBytes, Sm2Base.CURVE, Sm2Base.DOMAIN_PARAMS);
|
||||
public SM2PublicKey(byte[] xBytes, byte[] yBytes){
|
||||
this(xBytes,yBytes, SM2Base.CURVE, SM2Base.DOMAIN_PARAMS);
|
||||
}
|
||||
|
||||
public Sm2PublicKey(byte[] bytes){
|
||||
public SM2PublicKey(byte[] bytes){
|
||||
setBytes(bytes);
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class Sm2PublicKey implements PublicKeyInterface {
|
||||
}
|
||||
|
||||
private static ECPublicKeyParameters createPublicKey(byte[] xBytes, byte[] yBytes){
|
||||
return createPublicKey(xBytes,yBytes,Sm2Base.CURVE,Sm2Base.DOMAIN_PARAMS);
|
||||
return createPublicKey(xBytes,yBytes, SM2Base.CURVE, SM2Base.DOMAIN_PARAMS);
|
||||
}
|
||||
|
||||
private static int getCurveLength(ECDomainParameters domainParams) {
|
||||
@@ -0,0 +1,14 @@
|
||||
package minsecurity.crypto.sm2;
|
||||
|
||||
/*
|
||||
* @Author: hongyu guo
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 15:19 2021/03/09
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class SM4Exception extends Exception{
|
||||
SM4Exception(String msg){
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user