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


Java ECNamedCurveParameterSpec.getG方法代码示例

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


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


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