当前位置: 首页>>代码示例>>Java>>正文


Java ECParameterSpec类代码示例

本文整理汇总了Java中java.security.spec.ECParameterSpec的典型用法代码示例。如果您正苦于以下问题:Java ECParameterSpec类的具体用法?Java ECParameterSpec怎么用?Java ECParameterSpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ECParameterSpec类属于java.security.spec包,在下文中一共展示了ECParameterSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertSpec

import java.security.spec.ECParameterSpec; //导入依赖的package包/类
public static ECParameterSpec convertSpec(
    EllipticCurve ellipticCurve,
    org.bouncycastle.jce.spec.ECParameterSpec spec)
{
    if (spec instanceof ECNamedCurveParameterSpec)
    {
        return new ECNamedCurveSpec(
            ((ECNamedCurveParameterSpec)spec).getName(),
            ellipticCurve,
            new ECPoint(
                spec.getG().getX().toBigInteger(),
                spec.getG().getY().toBigInteger()),
            spec.getN(),
            spec.getH());
    }
    else
    {
        return new ECParameterSpec(
            ellipticCurve,
            new ECPoint(
                spec.getG().getX().toBigInteger(),
                spec.getG().getY().toBigInteger()),
            spec.getN(),
            spec.getH().intValue());
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:27,代码来源:EC5Util.java

示例2: encodeECParameterSpec

import java.security.spec.ECParameterSpec; //导入依赖的package包/类
public static ECParameterSpec encodeECParameterSpec(EllipticCurveParameters params) {

        // Field
        final BigInteger pInt = new BigInteger(1, params.getP());
        final ECField field = new ECFieldFp(pInt);

        final BigInteger aInt = new BigInteger(1, params.getA());
        final BigInteger bInt = new BigInteger(1, params.getB());
        final EllipticCurve curve = new EllipticCurve(field, aInt, bInt);

        // Fixed Point G
        final BigInteger xInt = new BigInteger(1, params.getX());
        final BigInteger yInt = new BigInteger(1, params.getY());
        final ECPoint g = new ECPoint(xInt, yInt);

        // Order N
        final BigInteger nInt = new BigInteger(1, params.getN());

        return new ECParameterSpec(curve, g, nInt, params.getH());
    }
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:21,代码来源:EllipticCurveParameters.java

示例3: addPointsA

import java.security.spec.ECParameterSpec; //导入依赖的package包/类
private static BigInteger[] addPointsA(BigInteger[] P1, BigInteger[] P2,
    ECParameterSpec params) {
  final BigInteger p = ((ECFieldFp) params.getCurve().getField()).getP();

  if (P2[0] == null || P2[1] == null) return P1;

  if (P1[0] == null || P1[1] == null) return P2;

  BigInteger d = (P2[1].subtract(P1[1])).multiply((P2[0].subtract(P1[0]))
      .modInverse(p));
  BigInteger[] R = new BigInteger[2];
  R[0] = d.pow(2).subtract(P1[0]).subtract(P2[0]).mod(p);
  R[1] = d.multiply(P1[0].subtract(R[0])).subtract(P1[1]).mod(p);

  return R;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:EcCore.java

示例4: 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);
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:19,代码来源:JseCryptoHelper.java

示例5: JCEECPublicKey

import java.security.spec.ECParameterSpec; //导入依赖的package包/类
public JCEECPublicKey(
    String              algorithm,
    org.bouncycastle.jce.spec.ECPublicKeySpec     spec)
{
    this.algorithm = algorithm;
    this.q = spec.getQ();

    if (spec.getParams() != null) // can be null if implictlyCa
    {
        ECCurve curve = spec.getParams().getCurve();
        EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());

        this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
    }
    else
    {
        if (q.getCurve() == null)
        {
            org.bouncycastle.jce.spec.ECParameterSpec s = BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();

            q = s.getCurve().createPoint(q.getX().toBigInteger(), q.getY().toBigInteger(), false);
        }               
        this.ecSpec = null;
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:26,代码来源:JCEECPublicKey.java

示例6: BCDSTU4145PublicKey

import java.security.spec.ECParameterSpec; //导入依赖的package包/类
public BCDSTU4145PublicKey(
    org.bouncycastle.jce.spec.ECPublicKeySpec spec)
{
    this.q = spec.getQ();

    if (spec.getParams() != null) // can be null if implictlyCa
    {
        ECCurve curve = spec.getParams().getCurve();
        EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());

        this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
    }
    else
    {
        if (q.getCurve() == null)
        {
            org.bouncycastle.jce.spec.ECParameterSpec s = BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();

            q = s.getCurve().createPoint(q.getX().toBigInteger(), q.getY().toBigInteger(), false);
        }
        this.ecSpec = null;
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:24,代码来源:BCDSTU4145PublicKey.java

示例7: BCECPublicKey

import java.security.spec.ECParameterSpec; //导入依赖的package包/类
public BCECPublicKey(
    String algorithm,
    ECPublicKeyParameters params,
    ECParameterSpec spec,
    ProviderConfiguration configuration)
{
    ECDomainParameters      dp = params.getParameters();

    this.algorithm = algorithm;
    this.q = params.getQ();

    if (spec == null)
    {
        EllipticCurve ellipticCurve = EC5Util.convertCurve(dp.getCurve(), dp.getSeed());

        this.ecSpec = createSpec(ellipticCurve, dp);
    }
    else
    {
        this.ecSpec = spec;
    }

    this.configuration = configuration;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:BCECPublicKey.java

示例8: CfcaCurve

import java.security.spec.ECParameterSpec; //导入依赖的package包/类
public static ECParameterSpec CfcaCurve() {
	// 素数P
	BigInteger p = new BigInteger("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF", 16);

	// 基于素数P的有限域
	ECFieldFp gfp = new ECFieldFp(p);

	// 在有限域上的椭圆曲线y2 = x3 + ax + b
	EllipticCurve ellipticCurve = new EllipticCurve(gfp,
			new BigInteger("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC", 16),
			new BigInteger("28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93", 16));

	// 基点G
	ECPoint G = new ECPoint(new BigInteger("32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7", 16),
			new BigInteger("BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0", 16));

	// G的阶
	BigInteger n = new BigInteger("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123", 16);

	// 设置基点
	ECParameterSpec ecParameterSpec = new ECParameterSpec(ellipticCurve, G, n, 1);
	return ecParameterSpec;
}
 
开发者ID:bubicn,项目名称:bubichain-sdk-java,代码行数:24,代码来源:Sm2keyCFCA.java

示例9: BCECGOST3410PublicKey

import java.security.spec.ECParameterSpec; //导入依赖的package包/类
public BCECGOST3410PublicKey(
    String algorithm,
    ECPublicKeyParameters params,
    ECParameterSpec spec)
{
    ECDomainParameters      dp = params.getParameters();

    this.algorithm = algorithm;
    this.q = params.getQ();

    if (spec == null)
    {
        EllipticCurve ellipticCurve = EC5Util.convertCurve(dp.getCurve(), dp.getSeed());

        this.ecSpec = createSpec(ellipticCurve, dp);
    }
    else
    {
        this.ecSpec = spec;
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:22,代码来源:BCECGOST3410PublicKey.java

示例10: getPublicKey

import java.security.spec.ECParameterSpec; //导入依赖的package包/类
/**
 * Returns the ECPublicKey instance from its encoded raw bytes. 
 * The first byte has the fixed value 0x04 indicating the uncompressed form.
 * Therefore, the byte array must be of form: [0x04, x coord of point (32 bytes), y coord of point (32 bytes)]
 * 
 * @param publicKeyBytes The byte array representing the encoded raw bytes of the public key
 * @return The ECPublicKey instance
 */
public static ECPublicKey getPublicKey(byte[] publicKeyBytes) {
	// First we separate x and y of coordinates into separate variables
    byte[] x = new byte[32];
    byte[] y = new byte[32];
    System.arraycopy(publicKeyBytes, 1, x, 0, 32);
    System.arraycopy(publicKeyBytes, 33, y, 0, 32);
    
    try {
		KeyFactory kf = KeyFactory.getInstance("EC");
		
		AlgorithmParameters parameters = AlgorithmParameters.getInstance("EC");
		parameters.init(new ECGenParameterSpec("secp256r1"));
		ECParameterSpec ecParameterSpec = parameters.getParameterSpec(ECParameterSpec.class);
		
		ECPublicKeySpec ecPublicKeySpec = new ECPublicKeySpec(new ECPoint(new BigInteger(x), new BigInteger(y)), ecParameterSpec);
		ECPublicKey ecPublicKey = (ECPublicKey) kf.generatePublic(ecPublicKeySpec);
		return ecPublicKey;
    } catch (NoSuchAlgorithmException | InvalidParameterSpecException | InvalidKeySpecException e) {
		getLogger().error(e.getClass().getSimpleName() + " occurred when trying to get public key from raw bytes", e);
        return null;
	}
}
 
开发者ID:V2GClarity,项目名称:RISE-V2G,代码行数:31,代码来源:SecurityUtils.java

示例11: getPrivateKey

import java.security.spec.ECParameterSpec; //导入依赖的package包/类
/**
 * Returns the ECPrivateKey instance from its raw bytes. Note that you must provide the "s" value of the 
 * private key, not e.g. the byte array from reading a PKCS#8 key file.
 * 
 * @param privateKeyBytes The byte array (the "s" value) of the private key
 * @return The ECPrivateKey instance
 */
public static ECPrivateKey getPrivateKey(byte[] privateKeyBytes) {
	try {
		AlgorithmParameters parameters = AlgorithmParameters.getInstance("EC");
		parameters.init(new ECGenParameterSpec("secp256r1"));
		
		ECParameterSpec ecParameterSpec = parameters.getParameterSpec(ECParameterSpec.class);
		ECPrivateKeySpec ecPrivateKeySpec = new ECPrivateKeySpec(new BigInteger(privateKeyBytes), ecParameterSpec);
		
		ECPrivateKey privateKey = (ECPrivateKey) KeyFactory.getInstance("EC").generatePrivate(ecPrivateKeySpec);

		return privateKey;
	} catch (NoSuchAlgorithmException | InvalidKeySpecException | InvalidParameterSpecException e) {
		getLogger().error(e.getClass().getSimpleName() + " occurred when trying to get private key from raw bytes", e);
		return null;
	}
}
 
开发者ID:V2GClarity,项目名称:RISE-V2G,代码行数:24,代码来源:SecurityUtils.java

示例12: 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);
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:19,代码来源:JseCryptoHelper.java

示例13: initialize

import java.security.spec.ECParameterSpec; //导入依赖的package包/类
@Override
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof ECParameterSpec) {
        this.params = ECUtil.getECParameterSpec(null,
                                                (ECParameterSpec)params);
        if (this.params == null) {
            throw new InvalidAlgorithmParameterException(
                "Unsupported curve: " + params);
        }
    } else if (params instanceof ECGenParameterSpec) {
        String name = ((ECGenParameterSpec)params).getName();
        this.params = ECUtil.getECParameterSpec(null, name);
        if (this.params == null) {
            throw new InvalidAlgorithmParameterException(
                "Unknown curve name: " + name);
        }
    } else {
        throw new InvalidAlgorithmParameterException(
            "ECParameterSpec or ECGenParameterSpec required for EC");
    }
    this.keySize =
        ((ECParameterSpec)this.params).getCurve().getField().getFieldSize();
    this.random = random;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:ECKeyPairGenerator.java

示例14: getCurveName

import java.security.spec.ECParameterSpec; //导入依赖的package包/类
public static String getCurveName(ECParameterSpec spec)
    throws InvalidAlgorithmParameterException
{
    int curve_id;

    /* Ecc object doesn't need to be initialied before call */
    if (!(spec.getCurve().getField() instanceof ECFieldFp)) {
        throw new InvalidAlgorithmParameterException(
            "Currently only ECFieldFp fields supported");
    }
    ECFieldFp field = (ECFieldFp)spec.getCurve().getField();
    EllipticCurve curve = spec.getCurve();

    curve_id = wc_ecc_get_curve_id_from_params(
                field.getFieldSize(),
                field.getP().toByteArray(),
                curve.getA().toByteArray(),
                curve.getB().toByteArray(),
                spec.getOrder().toByteArray(),
                spec.getGenerator().getAffineX().toByteArray(),
                spec.getGenerator().getAffineY().toByteArray(),
                spec.getCofactor());

    return wc_ecc_get_curve_name_from_id(curve_id);
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:26,代码来源:Ecc.java

示例15: getEccCurveNameFromSpec

import java.security.spec.ECParameterSpec; //导入依赖的package包/类
@Test
public void getEccCurveNameFromSpec()
    throws InvalidAlgorithmParameterException, NoSuchAlgorithmException {

    /* generate key pair */
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC");
    ECGenParameterSpec genSpec = new ECGenParameterSpec("secp256r1");
    kpg.initialize(genSpec);

    KeyPair pair = kpg.genKeyPair();
    ECPrivateKey priv = (ECPrivateKey)pair.getPrivate();

    ECParameterSpec spec = priv.getParams();

    String curveName = Ecc.getCurveName(spec);

    assertEquals(curveName, "SECP256R1");
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:19,代码来源:EccTest.java


注:本文中的java.security.spec.ECParameterSpec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。