本文整理汇总了Java中java.security.spec.ECParameterSpec.getOrder方法的典型用法代码示例。如果您正苦于以下问题:Java ECParameterSpec.getOrder方法的具体用法?Java ECParameterSpec.getOrder怎么用?Java ECParameterSpec.getOrder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.spec.ECParameterSpec
的用法示例。
在下文中一共展示了ECParameterSpec.getOrder方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapNonceGMWithECDH
import java.security.spec.ECParameterSpec; //导入方法依赖的package包/类
private static ECParameterSpec mapNonceGMWithECDH(final BigInteger nonceS,
final ECPoint sharedSecretPointH,
final ECParameterSpec params) {
// D~ = (p, a, b, G~, n, h) where G~ = [s]G + H
final ECPoint generator = params.getGenerator();
final EllipticCurve curve = params.getCurve();
final BigInteger a = curve.getA();
final BigInteger b = curve.getB();
final ECFieldFp field = (ECFieldFp)curve.getField();
final BigInteger p = field.getP();
final BigInteger order = params.getOrder();
final int cofactor = params.getCofactor();
final ECPoint ephemeralGenerator = add(multiply(nonceS, generator, params), sharedSecretPointH, params);
if (!toBouncyCastleECPoint(ephemeralGenerator, params).isValid()) {
LOGGER.warning("Se ha generado un punto invalido"); //$NON-NLS-1$
}
return new ECParameterSpec(new EllipticCurve(new ECFieldFp(p), a, b), ephemeralGenerator, order, cofactor);
}
示例2: mapNonceGMWithECDH
import java.security.spec.ECParameterSpec; //导入方法依赖的package包/类
private static ECParameterSpec mapNonceGMWithECDH(final BigInteger nonceS,
final ECPoint sharedSecretPointH,
final ECParameterSpec params) {
// D~ = (p, a, b, G~, n, h) where G~ = [s]G + H
final ECPoint generator = params.getGenerator();
final EllipticCurve curve = params.getCurve();
final BigInteger a = curve.getA();
final BigInteger b = curve.getB();
final ECFieldFp field = (ECFieldFp)curve.getField();
final BigInteger p = field.getP();
final BigInteger order = params.getOrder();
final int cofactor = params.getCofactor();
final ECPoint ephemeralGenerator = add(multiply(nonceS, generator, params), sharedSecretPointH, params);
if (!toSpongyCastleECPoint(ephemeralGenerator, params).isValid()) {
LOGGER.warning("Se ha generado un punto invalido"); //$NON-NLS-1$
}
return new ECParameterSpec(new EllipticCurve(new ECFieldFp(p), a, b), ephemeralGenerator, order, cofactor);
}
示例3: convertSpec
import java.security.spec.ECParameterSpec; //导入方法依赖的package包/类
public static org.bouncycastle.jce.spec.ECParameterSpec convertSpec(
ECParameterSpec ecSpec,
boolean withCompression)
{
ECCurve curve = convertCurve(ecSpec.getCurve());
return new org.bouncycastle.jce.spec.ECParameterSpec(
curve,
convertPoint(curve, ecSpec.getGenerator(), withCompression),
ecSpec.getOrder(),
BigInteger.valueOf(ecSpec.getCofactor()),
ecSpec.getCurve().getSeed());
}
示例4: toBouncyCastleECCurve
import java.security.spec.ECParameterSpec; //导入方法依赖的package包/类
private static ECCurve toBouncyCastleECCurve(final ECParameterSpec params) {
final EllipticCurve curve = params.getCurve();
final ECField field = curve.getField();
if (!(field instanceof ECFieldFp)) {
throw new IllegalArgumentException(
"Solo se soporta 'ECFieldFp' y se proporciono " + field.getClass().getCanonicalName() //$NON-NLS-1$
);
}
final int coFactor = params.getCofactor();
final BigInteger order = params.getOrder();
final BigInteger a = curve.getA();
final BigInteger b = curve.getB();
final BigInteger p = getPrime(params);
return new ECCurve.Fp(p, a, b, order, BigInteger.valueOf(coFactor));
}
示例5: toSpongyCastleECCurve
import java.security.spec.ECParameterSpec; //导入方法依赖的package包/类
private static ECCurve toSpongyCastleECCurve(final ECParameterSpec params) {
final EllipticCurve curve = params.getCurve();
final ECField field = curve.getField();
if (!(field instanceof ECFieldFp)) {
throw new IllegalArgumentException(
"Solo se soporta 'ECFieldFp' y se proporciono " + field.getClass().getCanonicalName() //$NON-NLS-1$
);
}
final int coFactor = params.getCofactor();
final BigInteger order = params.getOrder();
final BigInteger a = curve.getA();
final BigInteger b = curve.getB();
final BigInteger p = getPrime(params);
return new ECCurve.Fp(p, a, b, order, BigInteger.valueOf(coFactor));
}
示例6: isPrivateKeyValid
import java.security.spec.ECParameterSpec; //导入方法依赖的package包/类
/**
* Checks if the private key is a valid key (according to requirement [V2G2-823]) for the received contract
* certificate before saving it to the keystore.
* @param privateKey The private key corresponding to the contract certificate
* @param contractCertChain The received contract certificate chain
* @return True, if the private key is a valid key, false otherwise.
*/
private static boolean isPrivateKeyValid(ECPrivateKey privateKey, CertificateChainType contractCertChain) {
AlgorithmParameters parameters;
try {
parameters = AlgorithmParameters.getInstance("EC");
parameters.init(new ECGenParameterSpec("secp256r1"));
ECParameterSpec ecParameterSpec = parameters.getParameterSpec(ECParameterSpec.class);
// Now we need to check if the private key is correct (see requirement [V2G2-823])
BigInteger order = ecParameterSpec.getOrder();
ECPoint basePoint = ecParameterSpec.getGenerator();
BigInteger privateKeyValue = privateKey.getS();
X509Certificate contractCert = getCertificate(contractCertChain.getCertificate());
ECPublicKey publicKey = (ECPublicKey) contractCert.getPublicKey();
// 1. check
if (privateKeyValue.compareTo(order) != -1) {
getLogger().error("Validation of private key failed: its value is not strictly smaller than the "
+ "order of the base point");
return false;
}
// 2. check
/*
* TODO:
* No idea how to check for
* "multiplication of the base point with this value must generate a key matching the public key of
* the contract certificate"
* "this value" = value of private key
* -> some more expert knowledge on the arithmetic of elliptic curves is needed to tackle this!
*/
} catch (NoSuchAlgorithmException | InvalidParameterSpecException e) {
getLogger().error(e.getClass().getSimpleName() + " occurred when trying to get private key from raw bytes", e);
return false;
}
return true;
}
示例7: Verify
import java.security.spec.ECParameterSpec; //导入方法依赖的package包/类
private static boolean Verify(ECParameterSpec spec, byte[] id, byte[] msg, ECPoint pkey, Sm2Signature sig) {
do {
// 第一步 r在[1,n-1]范围
BigInteger order = spec.getOrder();
if (sig.r.compareTo(order) >= 0 || sig.r.compareTo(BigInteger.ONE) < 0) {
break;
}
// 第一步 s在[1,n-1]范围
if (sig.s.compareTo(order) >= 0 || sig.s.compareTo(BigInteger.ONE) < 0) {
break;
}
// 第三步 计算M^ = ZA||M
byte[] ZA = GetZA(spec, pkey, id);
byte[] M = new byte[ZA.length + msg.length];
System.arraycopy(ZA, 0, M, 0, ZA.length);
System.arraycopy(msg, 0, M, 32, msg.length);
// 第四步 计算e=Hv(M^)
byte[] stre = SM3Digest.Hash(M);
BigInteger e = new BigInteger(bytesToHex(stre), 16);
// 第五步 计算t=(r'+s')mod n
BigInteger t = sig.r.add(sig.s).mod(order);
if (t.compareTo(BigInteger.ZERO) == 0) {
break;
}
// 第六步 计算(x1,y1) = [s]G + [t]PA
ECPoint G = spec.getGenerator();
ECPoint tmp1 = PointMul(sig.s, G, spec.getCurve());
ECPoint tmp2 = PointMul(t, pkey, spec.getCurve());
ECPoint tmPoint = PointAdd(tmp1, tmp2, spec.getCurve());
// 第七步 R=(e' + x1') 验证R==r'?
BigInteger R = e.add(tmPoint.getAffineX()).mod(order);
if (R.compareTo(sig.r) != 0) {
break;
}
return true;
} while (false);
return false;
}