use of com.github.zhenwei.core.asn1.x9.DomainParameters in project opb-sdk-java by bianjieai.
the class BCECUtils method buildECPublicKeyByPrivateKey.
/**
* 根据EC私钥构造EC公钥
*
* @param priKey ECC私钥参数对象
* @return
*/
public static ECPublicKeyParameters buildECPublicKeyByPrivateKey(ECPrivateKeyParameters priKey) {
ECDomainParameters domainParameters = priKey.getParameters();
ECPoint q = new FixedPointCombMultiplier().multiply(domainParameters.getG(), priKey.getD());
return new ECPublicKeyParameters(q, domainParameters);
}
use of com.github.zhenwei.core.asn1.x9.DomainParameters in project opb-sdk-java by bianjieai.
the class BCECUtils method createECPublicKeyParameters.
/**
* @param xBytes 十六进制形式的公钥x分量,如果是SM2算法,应该是32字节
* @param yBytes 十六进制形式的公钥y分量,如果是SM2算法,应该是32字节
* @param curve EC曲线参数,一般是固定的,如果是SM2算法的可参考{@link SM2#CURVE}
* @param domainParameters EC Domain参数,一般是固定的,如果是SM2算法的可参考{@link SM2#DOMAIN_PARAMS}
* @return
*/
public static ECPublicKeyParameters createECPublicKeyParameters(byte[] xBytes, byte[] yBytes, ECCurve curve, ECDomainParameters domainParameters) {
final byte uncompressedFlag = 0x04;
int curveLength = getCurveLength(domainParameters);
xBytes = fixToCurveLengthBytes(curveLength, xBytes);
yBytes = fixToCurveLengthBytes(curveLength, yBytes);
byte[] encodedPubKey = new byte[1 + xBytes.length + yBytes.length];
encodedPubKey[0] = uncompressedFlag;
System.arraycopy(xBytes, 0, encodedPubKey, 1, xBytes.length);
System.arraycopy(yBytes, 0, encodedPubKey, 1 + xBytes.length, yBytes.length);
return new ECPublicKeyParameters(curve.decodePoint(encodedPubKey), domainParameters);
}
use of com.github.zhenwei.core.asn1.x9.DomainParameters in project anttu.code.github.io by anTtutu.
the class SM2Utils method decrypt.
/**
* SM2解密算法 - 私钥是字符串
* @param privateKey 私钥
* @param cipherData 密文数据
* @return
*/
public String decrypt(String privateKey, String cipherData) {
byte[] cipherDataByte = Hex.decode(cipherData);
// 获取一条SM2曲线参数
X9ECParameters sm2ECParameters = GMNamedCurves.getByName("sm2p256v1");
// 构造domain参数
ECDomainParameters domainParameters = new ECDomainParameters(sm2ECParameters.getCurve(), sm2ECParameters.getG(), sm2ECParameters.getN());
BigInteger privateKeyD = new BigInteger(privateKey, 16);
ECPrivateKeyParameters privateKeyParameters = new ECPrivateKeyParameters(privateKeyD, domainParameters);
SM2Engine sm2Engine = new SM2Engine();
sm2Engine.init(false, privateKeyParameters);
String result = null;
try {
byte[] arrayOfBytes = sm2Engine.processBlock(cipherDataByte, 0, cipherDataByte.length);
result = new String(arrayOfBytes, CHARSET);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
use of com.github.zhenwei.core.asn1.x9.DomainParameters in project jmulticard by ctt-gob-es.
the class ECUtil method getDomainParameters.
public static ECDomainParameters getDomainParameters(ProviderConfiguration configuration, X962Parameters params) {
ECDomainParameters domainParameters;
if (params.isNamedCurve()) {
ASN1ObjectIdentifier oid = ASN1ObjectIdentifier.getInstance(params.getParameters());
X9ECParameters ecP = ECUtil.getNamedCurveByOid(oid);
if (ecP == null) {
Map extraCurves = configuration.getAdditionalECParameters();
ecP = (X9ECParameters) extraCurves.get(oid);
}
domainParameters = new ECNamedDomainParameters(oid, ecP);
} else if (params.isImplicitlyCA()) {
org.bouncycastle.jce.spec.ECParameterSpec iSpec = configuration.getEcImplicitlyCa();
domainParameters = new ECDomainParameters(iSpec.getCurve(), iSpec.getG(), iSpec.getN(), iSpec.getH(), iSpec.getSeed());
} else {
X9ECParameters ecP = X9ECParameters.getInstance(params.getParameters());
domainParameters = new ECDomainParameters(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed());
}
return domainParameters;
}
use of com.github.zhenwei.core.asn1.x9.DomainParameters in project LinLong-Java by zhenwei1108.
the class ECUtil method getDomainParameters.
public static ECDomainParameters getDomainParameters(ProviderConfiguration configuration, X962Parameters params) {
ECDomainParameters domainParameters;
if (params.isNamedCurve()) {
ASN1ObjectIdentifier oid = ASN1ObjectIdentifier.getInstance(params.getParameters());
X9ECParameters ecP = ECUtil.getNamedCurveByOid(oid);
if (ecP == null) {
Map extraCurves = configuration.getAdditionalECParameters();
ecP = (X9ECParameters) extraCurves.get(oid);
}
domainParameters = new ECNamedDomainParameters(oid, ecP);
} else if (params.isImplicitlyCA()) {
com.github.zhenwei.provider.jce.spec.ECParameterSpec iSpec = configuration.getEcImplicitlyCa();
domainParameters = new ECDomainParameters(iSpec.getCurve(), iSpec.getG(), iSpec.getN(), iSpec.getH(), iSpec.getSeed());
} else {
X9ECParameters ecP = X9ECParameters.getInstance(params.getParameters());
domainParameters = new ECDomainParameters(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed());
}
return domainParameters;
}
Aggregations