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


Java ECNamedCurveParameterSpec.getN方法代码示例

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


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

示例1: getPubKeyFromCurve

import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
/**
 * Decode based on X, Y 32 byte integers
 * 
 * @param pubKey
 * @param curveName
 *            - Example secp256r1
 * @return
 * @throws InvalidKeySpecException
 * @throws NoSuchAlgorithmException
 * @throws NoSuchProviderException
 */
public static PublicKey getPubKeyFromCurve(byte[] pubKey, String curveName)
		throws InvalidKeySpecException, NoSuchAlgorithmException,
		NoSuchProviderException {

	ECNamedCurveParameterSpec spec = ECNamedCurveTable
			.getParameterSpec(curveName);
	KeyFactory kf = KeyFactory.getInstance("ECDSA",
			new BouncyCastleProvider());
	ECNamedCurveSpec params = new ECNamedCurveSpec(curveName,
			spec.getCurve(), spec.getG(), spec.getN());
	ECPoint point = ECPointUtil.decodePoint(params.getCurve(), pubKey);
	ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(point, params);
	ECPublicKey pk = (ECPublicKey) kf.generatePublic(pubKeySpec);
	return pk;
}
 
开发者ID:zsavvas,项目名称:ReCRED_FIDO_UAF_OIDC,代码行数:27,代码来源:KeyCodec.java

示例2: verifySignature

import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
public static boolean verifySignature(byte[] sigR, byte sigS[], byte[] publicKey, byte[] message) {
  try {
    Security.addProvider(new BouncyCastleProvider());
    ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(SECP256K1);
    ECDomainParameters domain = new ECDomainParameters(spec.getCurve(), spec.getG(), spec.getN());
    ECPublicKeyParameters publicKeyParams =
        new ECPublicKeyParameters(spec.getCurve().decodePoint(publicKey), domain);

    ECDSASigner signer = new ECDSASigner();
    signer.init(false, publicKeyParams);
    return signer.verifySignature(message, new BigInteger(1, sigR), new BigInteger(1, sigS));
  } catch (Exception e) {
    LOGGER.error(null, e);
    return false;
  }
}
 
开发者ID:Braveno,项目名称:cosigner,代码行数:17,代码来源:Secp256k1.java

示例3: 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

示例4: 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

示例5: 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

示例6: getPrivKeyFromCurve

import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
/**
 * Decode based on d - 32 byte integer
 * 
 * @param privKey
 * @param curveName
 *            - Example secp256r1
 * @return
 * @throws InvalidKeySpecException
 * @throws NoSuchAlgorithmException
 * @throws NoSuchProviderException
 */
public static PrivateKey getPrivKeyFromCurve(byte[] privKey,
		String curveName) throws InvalidKeySpecException,
		NoSuchAlgorithmException, NoSuchProviderException {

	ECNamedCurveParameterSpec spec = ECNamedCurveTable
			.getParameterSpec(curveName);
	KeyFactory kf = KeyFactory.getInstance("ECDSA",
			new BouncyCastleProvider());
	ECNamedCurveSpec params = new ECNamedCurveSpec(curveName,
			spec.getCurve(), spec.getG(), spec.getN());
	ECPrivateKeySpec priKey = new ECPrivateKeySpec(new BigInteger(privKey), // d
			params);
	return kf.generatePrivate(priKey);
}
 
开发者ID:zsavvas,项目名称:ReCRED_FIDO_UAF_OIDC,代码行数:26,代码来源:KeyCodec.java

示例7: getPublicKeyFromBytes

import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
private PublicKey getPublicKeyFromBytes(byte[] pubKey) throws NoSuchAlgorithmException, InvalidKeySpecException {
    ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec("secp384r1");
    KeyFactory keyFactory = KeyFactory.getInstance("ECDH", new BouncyCastleProvider());

    ECNamedCurveSpec params = new ECNamedCurveSpec("secp384r1", spec.getCurve(), spec.getG(), spec.getN());
    ECPoint point =  ECPointUtil.decodePoint(params.getCurve(), pubKey);
    ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(point, params);
    ECPublicKey ecPublicKey = (ECPublicKey) keyFactory.generatePublic(pubKeySpec);
    return ecPublicKey;
}
 
开发者ID:iotauth,项目名称:iotauth,代码行数:11,代码来源:DistributionDiffieHellman.java

示例8: signTransaction

import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
/**
 * Sign data using the ECDSA algorithm.
 */
public static byte[][] signTransaction(byte[] data, byte[] privateKey) {
  try {
    Security.addProvider(new BouncyCastleProvider());
    ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(SECP256K1);

    ECDSASigner ecdsaSigner = new ECDSASigner();
    ECDomainParameters domain = new ECDomainParameters(spec.getCurve(), spec.getG(), spec.getN());
    ECPrivateKeyParameters privateKeyParms =
        new ECPrivateKeyParameters(new BigInteger(1, privateKey), domain);
    ParametersWithRandom params = new ParametersWithRandom(privateKeyParms);

    ecdsaSigner.init(true, params);

    BigInteger[] sig = ecdsaSigner.generateSignature(data);
    LinkedList<byte[]> sigData = new LinkedList<>();
    byte[] publicKey = getPublicKey(privateKey);
    byte recoveryId = getRecoveryId(sig[0].toByteArray(), sig[1].toByteArray(), data, publicKey);
    for (BigInteger sigChunk : sig) {
      sigData.add(sigChunk.toByteArray());
    }
    sigData.add(new byte[]{recoveryId});
    return sigData.toArray(new byte[][]{});

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

示例9: recoverPublicKey

import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
/**
 * Recover the public key that corresponds to the private key, which signed this message.
 */
public static byte[] recoverPublicKey(byte[] sigR, byte[] sigS, byte[] sigV, byte[] message) {
  ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(SECP256K1);
  BigInteger pointN = spec.getN();

  try {
    BigInteger pointX = new BigInteger(1, sigR);

    X9IntegerConverter x9 = new X9IntegerConverter();
    byte[] compEnc = x9.integerToBytes(pointX, 1 + x9.getByteLength(spec.getCurve()));
    compEnc[0] = (byte) ((sigV[0] & 1) == 1 ? 0x03 : 0x02);
    ECPoint pointR = spec.getCurve().decodePoint(compEnc);
    if (!pointR.multiply(pointN).isInfinity()) {
      return new byte[0];
    }

    BigInteger pointE = new BigInteger(1, message);
    BigInteger pointEInv = BigInteger.ZERO.subtract(pointE).mod(pointN);
    BigInteger pointRInv = new BigInteger(1, sigR).modInverse(pointN);
    BigInteger srInv = pointRInv.multiply(new BigInteger(1, sigS)).mod(pointN);
    BigInteger pointEInvRInv = pointRInv.multiply(pointEInv).mod(pointN);
    ECPoint pointQ = ECAlgorithms.sumOfTwoMultiplies(spec.getG(), pointEInvRInv, pointR, srInv);
    return pointQ.getEncoded(false);
  } catch (Exception e) {
    LOGGER.warn("Error recovering public key from message");
  }

  return new byte[0];
}
 
开发者ID:Braveno,项目名称:cosigner,代码行数:32,代码来源:Secp256k1.java

示例10: 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

示例11: getRecoveryId

import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
/**
 * Determine the recovery ID for the given signature and public key.
 *
 * <p>Any signed message can resolve to one of two public keys due to the nature ECDSA. The
 * recovery ID provides information about which one it is, allowing confirmation that the message
 * was signed by a specific key.</p>
 */
public static byte getRecoveryId(byte[] sigR, byte[] sigS, byte[] message, byte[] publicKey) {
  ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(SECP256K1);
  BigInteger pointN = spec.getN();
  for (int recoveryId = 0; recoveryId < 2; recoveryId++) {
    try {
      BigInteger pointX = new BigInteger(1, sigR);

      X9IntegerConverter x9 = new X9IntegerConverter();
      byte[] compEnc = x9.integerToBytes(pointX, 1 + x9.getByteLength(spec.getCurve()));
      compEnc[0] = (byte) ((recoveryId & 1) == 1 ? 0x03 : 0x02);
      ECPoint pointR = spec.getCurve().decodePoint(compEnc);
      if (!pointR.multiply(pointN).isInfinity()) {
        continue;
      }

      BigInteger pointE = new BigInteger(1, message);
      BigInteger pointEInv = BigInteger.ZERO.subtract(pointE).mod(pointN);
      BigInteger pointRInv = new BigInteger(1, sigR).modInverse(pointN);
      BigInteger srInv = pointRInv.multiply(new BigInteger(1, sigS)).mod(pointN);
      BigInteger pointEInvRInv = pointRInv.multiply(pointEInv).mod(pointN);
      ECPoint pointQ = ECAlgorithms.sumOfTwoMultiplies(spec.getG(), pointEInvRInv, pointR, srInv);
      byte[] pointQBytes = pointQ.getEncoded(false);
      boolean matchedKeys = true;
      for (int j = 0; j < publicKey.length; j++) {
        if (pointQBytes[j] != publicKey[j]) {
          matchedKeys = false;
          break;
        }
      }
      if (!matchedKeys) {
        continue;
      }
      return (byte) (0xFF & recoveryId);
    } catch (Exception e) {
      LOGGER.error(null, e);
    }
  }

  return (byte) 0xFF;
}
 
开发者ID:Braveno,项目名称:cosigner,代码行数:48,代码来源:Secp256k1.java

示例12: 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.getN方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。