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


Java ECNamedCurveParameterSpec.getH方法代码示例

本文整理汇总了Java中org.bouncycastle.jce.spec.ECNamedCurveParameterSpec.getH方法的典型用法代码示例。如果您正苦于以下问题:Java ECNamedCurveParameterSpec.getH方法的具体用法?Java ECNamedCurveParameterSpec.getH怎么用?Java ECNamedCurveParameterSpec.getH使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.jce.spec.ECNamedCurveParameterSpec的用法示例。


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

示例1: generateSharedSecret

import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
/**
 * Generate a shared AES key using ECDH.
 */
public static byte[] generateSharedSecret(byte[] privateKey, byte[] publicKey) {
  try {
    ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(SECP256K1);
    ECDomainParameters domain =
        new ECDomainParameters(spec.getCurve(), spec.getG(), spec.getN(), spec.getH());
    ECPublicKeyParameters pubKey =
        new ECPublicKeyParameters(spec.getCurve().decodePoint(publicKey), domain);
    ECPrivateKeyParameters prvkey =
        new ECPrivateKeyParameters(new BigInteger(1, privateKey), domain);

    ECDHBasicAgreement agreement = new ECDHBasicAgreement();
    agreement.init(prvkey);
    byte[] password = agreement.calculateAgreement(pubKey).toByteArray();

    return Aes.generateKey(ByteUtilities.toHexString(password), password);

  } catch (Exception e) {
    LOGGER.error(null, e);
    return new byte[0];
  }
}
 
开发者ID:Braveno,项目名称:cosigner,代码行数:25,代码来源:Secp256k1.java

示例2: toJcaPrivateKey

import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
private static ECPrivateKey toJcaPrivateKey(org.bouncycastle.asn1.sec.ECPrivateKey ecPrivateKey)
        throws GeneralSecurityException {
    String curveName = null;
    ASN1ObjectIdentifier curveId = (ASN1ObjectIdentifier) ecPrivateKey.getParameters();
    if (curveId.equals(secp224r1_OID)) {
        curveName = "secp224r1";
    } else if (curveId.equals(prime256v1_OID)) {
        curveName = "prime256v1";
    } else if (curveId.equals(secp384r1_OID)) {
        curveName = "secp384r1";
    } else if (curveId.equals(secp521r1_OID)) {
        curveName = "secp521r1";
    } else {
        throw new IllegalStateException("Unknown curve OID: " + curveId);
    }

    ECNamedCurveParameterSpec sp = ECNamedCurveTable.getParameterSpec(curveName);
    ECParameterSpec params = new ECNamedCurveSpec(sp.getName(), sp.getCurve(), sp.getG(),
            sp.getN(), sp.getH());

    ECPrivateKeySpec pkSpec = new ECPrivateKeySpec(ecPrivateKey.getKey(), params);
    KeyFactory kf = KeyFactory.getInstance("EC");
    ECPrivateKey privateKey = (ECPrivateKey) kf.generatePrivate(pkSpec);

    return privateKey;
}
 
开发者ID:nelenkov,项目名称:keystore-decryptor,代码行数:27,代码来源:SoftKeymasterBlob.java

示例3: getECPublicKey

import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
public static PublicKey getECPublicKey(java.security.spec.ECPoint w, String stdCurveName) throws NoSuchAlgorithmException, InvalidKeySpecException {
  ECNamedCurveParameterSpec parameterSpec = ECNamedCurveTable.getParameterSpec(stdCurveName);
  java.security.spec.ECParameterSpec params = new ECNamedCurveSpec(parameterSpec.getName(), parameterSpec.getCurve(),
          parameterSpec.getG(), parameterSpec.getN(), parameterSpec.getH(), parameterSpec.getSeed());
  KeySpec keySpec = new java.security.spec.ECPublicKeySpec(w, params);
  KeyFactory keyFactory = KeyFactory.getInstance("EC");
  return keyFactory.generatePublic(keySpec);
}
 
开发者ID:google,项目名称:webauthndemo,代码行数:9,代码来源:Crypto.java

示例4: populateFromPubKeyInfo

import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
private void populateFromPubKeyInfo(SubjectPublicKeyInfo info)
{
    DERBitString bits = info.getPublicKeyData();
    ASN1OctetString key;
    this.algorithm = "ECGOST3410";

    try
    {
        key = (ASN1OctetString)ASN1Primitive.fromByteArray(bits.getBytes());
    }
    catch (IOException ex)
    {
        throw new IllegalArgumentException("error recovering public key");
    }

    byte[] keyEnc = key.getOctets();
    byte[] x = new byte[32];
    byte[] y = new byte[32];

    for (int i = 0; i != x.length; i++)
    {
        x[i] = keyEnc[32 - 1 - i];
    }

    for (int i = 0; i != y.length; i++)
    {
        y[i] = keyEnc[64 - 1 - i];
    }

    gostParams = GOST3410PublicKeyAlgParameters.getInstance(info.getAlgorithm().getParameters());

    ECNamedCurveParameterSpec spec = ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()));

    ECCurve curve = spec.getCurve();
    EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getSeed());

    this.q = curve.createPoint(new BigInteger(1, x), new BigInteger(1, y));

    ecSpec = new ECNamedCurveSpec(
        ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()),
        ellipticCurve,
        new ECPoint(
            spec.getG().getAffineXCoord().toBigInteger(),
            spec.getG().getAffineYCoord().toBigInteger()),
        spec.getN(), spec.getH());
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:47,代码来源:BCECGOST3410PublicKey.java

示例5: populateFromPubKeyInfo

import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
private void populateFromPubKeyInfo(SubjectPublicKeyInfo info)
{
    DERBitString bits = info.getPublicKeyData();
    ASN1OctetString key;
    this.algorithm = "ECGOST3410";

    try
    {
        key = (ASN1OctetString)ASN1Primitive.fromByteArray(bits.getBytes());
    }
    catch (IOException ex)
    {
        throw new IllegalArgumentException("error recovering public key");
    }

    byte[] keyEnc = key.getOctets();
    byte[] x = new byte[32];
    byte[] y = new byte[32];

    for (int i = 0; i != x.length; i++)
    {
        x[i] = keyEnc[32 - 1 - i];
    }

    for (int i = 0; i != y.length; i++)
    {
        y[i] = keyEnc[64 - 1 - i];
    }

    gostParams = GOST3410PublicKeyAlgParameters.getInstance(info.getAlgorithm().getParameters());

    ECNamedCurveParameterSpec spec = ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()));

    ECCurve curve = spec.getCurve();
    EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getSeed());

    this.q = curve.createPoint(new BigInteger(1, x), new BigInteger(1, y));

    ecSpec = new ECNamedCurveSpec(
        ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()),
        ellipticCurve,
        new ECPoint(
            spec.getG().getX().toBigInteger(),
            spec.getG().getY().toBigInteger()),
        spec.getN(), spec.getH());
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:47,代码来源:BCECGOST3410PublicKey.java


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