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


Java ECNamedCurveTable类代码示例

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


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

示例1: verifySignature

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的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

示例2: generateECKeypair

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的package包/类
public static KeyPair generateECKeypair(ASN1ObjectIdentifier curveId, SecureRandom random)
        throws NoSuchAlgorithmException, NoSuchProviderException,
            InvalidAlgorithmParameterException {
    ParamUtil.requireNonNull("curveId", curveId);

    ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(curveId.getId());
    KeyPairGenerator kpGen = getKeyPairGenerator("EC");
    synchronized (kpGen) {
        if (random == null) {
            kpGen.initialize(spec);
        } else {
            kpGen.initialize(spec, random);
        }
        return kpGen.generateKeyPair();
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:17,代码来源:KeyUtil.java

示例3: register

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的package包/类
public RawRegisterResponse register(RegisterRequest registerRequest) throws Exception {

        byte[] applicationSha256 = registerRequest.getApplicationSha256();
        byte[] challengeSha256 = registerRequest.getChallengeSha256();

        // generate ECC key
        SecureRandom random = new SecureRandom();
        ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("secp256r1");
        KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA");
        g.initialize(ecSpec, random);
        KeyPair keyPair = g.generateKeyPair();

        byte[] keyHandle = new byte[64];
        random.nextBytes(keyHandle);
        dataStore.put(new String(keyHandle), keyPair);

        byte[] userPublicKey = stripMetaData(keyPair.getPublic().getEncoded());

        byte[] signedData = RawRegisterResponse.packBytesToSign(applicationSha256, challengeSha256,
                keyHandle, userPublicKey);

        byte[] signature = sign(signedData, certificatePrivateKey);

        return new RawRegisterResponse(userPublicKey, keyHandle, attestationCertificate, signature);
    }
 
开发者ID:Yubico,项目名称:java-u2flib-server,代码行数:26,代码来源:SoftKey.java

示例4: getPubKeyFromCurve

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的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

示例5: loadPrivateKey

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的package包/类
/**
 * Load the private key from a URL-safe base64 encoded string
 *
 * @param encodedPrivateKey
 * @return
 * @throws NoSuchProviderException
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeySpecException
 */
public static PrivateKey loadPrivateKey(String encodedPrivateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException {
    byte[] decodedPrivateKey = base64Decode(encodedPrivateKey);

    // prime256v1 is NIST P-256
    ECParameterSpec params = ECNamedCurveTable.getParameterSpec("prime256v1");
    ECPrivateKeySpec prvkey = new ECPrivateKeySpec(new BigInteger(decodedPrivateKey), params);
    KeyFactory kf = KeyFactory.getInstance("ECDH", BouncyCastleProvider.PROVIDER_NAME);

    return kf.generatePrivate(prvkey);
}
 
开发者ID:web-push-libs,项目名称:webpush-java,代码行数:20,代码来源:Utils.java

示例6: generateSharedSecret

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的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

示例7: toJcaPrivateKey

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的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

示例8: setUpClass

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws Exception {
    
    //RSA key generation
    KeyPairGenerator rsaGen = KeyPairGenerator.getInstance("RSA");
    rsaGen.initialize(2048, Utils.getRng());
    KeyPair sigPair = rsaGen.generateKeyPair();
    pubKeyRsa = sigPair.getPublic();
    privKeyRsa = sigPair.getPrivate();
    
    KeyGenerator macGen = KeyGenerator.getInstance("HmacSHA256");
    macGen.init(256, Utils.getRng());
    macKey = macGen.generateKey();
    
    Security.addProvider(new BouncyCastleProvider());
    ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("secp384r1");
    KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC");
    g.initialize(ecSpec, Utils.getRng());
    KeyPair keypair = g.generateKeyPair();
    pubKeyEcdsa = keypair.getPublic();
    privKeyEcdsa = keypair.getPrivate();
    
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-encryption-java,代码行数:24,代码来源:DynamoDBSignerTest.java

示例9: generateECKeys

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的package包/类
private static KeyPair generateECKeys() {
	try {
		ECNamedCurveParameterSpec parameterSpec = ECNamedCurveTable
				.getParameterSpec("secp256k1");
		KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(
				"ECDH", BouncyCastleProvider.PROVIDER_NAME);

		keyPairGenerator.initialize(parameterSpec);

		KeyPair keyPair = keyPairGenerator.generateKeyPair();
		System.out.println("Private key length: "
				+ keyPair.getPrivate().getEncoded().length);
		System.out.println("Public key length: "
				+ keyPair.getPublic().getEncoded().length);
		return keyPair;
	} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException
			| NoSuchProviderException e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:y12studio,项目名称:bkbc-tools,代码行数:22,代码来源:HelloECDH2.java

示例10: createPublicEncryptionKey

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的package包/类
/**
 * Creates a ECPublicKey with the given coordinates. The key will have valid
 * parameters.
 * 
 * @param x
 *            The x coordinate on the curve.
 * @param y
 *            The y coordinate on the curve.
 * @return A ECPublicKey with the given coordinates.
 */
public ECPublicKey createPublicEncryptionKey(BigInteger x, BigInteger y) {
	try {
		java.security.spec.ECPoint w = new java.security.spec.ECPoint(x, y);
		ECNamedCurveParameterSpec params = ECNamedCurveTable.getParameterSpec("secp256k1");
		KeyFactory fact = KeyFactory.getInstance("ECDSA", "BC");
		ECCurve curve = params.getCurve();
		java.security.spec.EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, params.getSeed());
		java.security.spec.ECParameterSpec params2 = EC5Util.convertSpec(ellipticCurve, params);
		java.security.spec.ECPublicKeySpec keySpec = new java.security.spec.ECPublicKeySpec(w, params2);
		return (ECPublicKey) fact.generatePublic(keySpec);
	} catch (InvalidKeySpecException | NoSuchAlgorithmException | NoSuchProviderException e) {
		LOG.log(Level.SEVERE, "Could not create public key.", e);
		return null;
	}
}
 
开发者ID:ISibboI,项目名称:JBitmessage,代码行数:26,代码来源:CryptManager.java

示例11: initialize

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的package包/类
public boolean initialize() {
	Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

	try {
		kpg = KeyPairGenerator.getInstance("ECIES", "BC");
		kpg.initialize(ECNamedCurveTable.getParameterSpec("secp256k1"), new SecureRandom());

		skpg = KeyPairGenerator.getInstance("ECDSA", "BC");
		skpg.initialize(ECNamedCurveTable.getParameterSpec("secp256k1"), new SecureRandom());
	} catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidAlgorithmParameterException e) {
		LOG.log(Level.SEVERE, "No ECIES cryptography available!", e);
		return false;
	}

	return true;
}
 
开发者ID:ISibboI,项目名称:JBitmessage,代码行数:17,代码来源:CryptManager.java

示例12: initialize

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的package包/类
@Override
public void initialize(int keysize)
{
   ECParameterSpec generationParam = ECNamedCurveTable.getParameterSpec("P-256");
  // Enable this code when we will have separate codec parameters for data and keys
 // ECGenParameterSpec generationParam = (ECGenParameterSpec)ecParameters.get(Integers.valueOf(keysize));
  //System.err.print("got params name " + generationParam.getName());
  try {
    initialize(generationParam);
  } catch (InvalidAlgorithmParameterException e)
  {
    e.printStackTrace();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:15,代码来源:BBS98BCReEncryptionKeyGenerator.java

示例13: initialize

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的package包/类
@Override
public void initialize(int keysize, SecureRandom random)
{

   ECParameterSpec generationParam = ECNamedCurveTable.getParameterSpec("P-256");
  // Enable this code when we will have separate codec parameters for data and keys
 // ECGenParameterSpec generationParam = (ECGenParameterSpec)ecParameters.get(Integers.valueOf(keysize));
  //System.err.print("got params name " + generationParam.getName());
  try {
    initialize(generationParam, random);
  } catch (InvalidAlgorithmParameterException e)
  {
    e.printStackTrace();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:16,代码来源:BBS98BCKeyPairGenerator.java

示例14: WrapperBBS98

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的package包/类
public WrapperBBS98(AlgorithmParameterSpec params, SecureRandom random)
		throws InvalidAlgorithmParameterException
{
	if (params instanceof ECGenParameterSpec)
		this.params = ECNamedCurveTable.getParameterSpec(((ECGenParameterSpec)params).getName());
	else if (params instanceof ECParameterSpec)
		this.params = (ECParameterSpec)params;
	else
		throw new InvalidAlgorithmParameterException();
	// TODO: check arguments
	this.random = random;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:13,代码来源:WrapperBBS98.java

示例15: main

import org.bouncycastle.jce.ECNamedCurveTable; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		SecureRandom sr = new SecureRandom(); // SecureRandom is thread-safe

		Security.addProvider(new BouncyCastleProvider());

		ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("P-256");

		for (int i = 0; i < 1000; i++) {
			byte[] message = new byte[16];
			sr.nextBytes(message);

			// ECPoint point = encodeToECPoint(ecSpec, message, sr);
			// System.out.println(point);
			// byte[] res = decodeFromECPoint(ecSpec, point);

			BigInteger n = ecSpec.getN();

			KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECDSA", "BC");

			kpg.initialize(ecSpec, new SecureRandom());
			KeyPair pair = kpg.generateKeyPair();

			PublicKey pki = pair.getPublic();
			PrivateKey xi = pair.getPrivate();

			WrapperBBS98 pre = new WrapperBBS98(ecSpec, sr);

			byte[] c = pre.encrypt(pki, message);

			byte[] m2 = pre.decrypt(xi, c);
//			System.out.println("m2 = " + BBS98BouncyCastle.bytesToHex(m2));

			if (!Arrays.areEqual(m2, message)) {
				System.out.println("Error 1!");
			}

			pair = kpg.generateKeyPair();
			PublicKey pkj = pair.getPublic();
			PrivateKey xj = pair.getPrivate();

			//
			// // RKG & REENC
			//
			BigInteger rk = pre.rekeygen(xi, xj);
			
			byte[] c_j = pre.reencrypt(rk, c);

			byte[] m3 = pre.decrypt(xj, c_j);
//			System.out.println("m3 = " + BBS98BouncyCastle.bytesToHex(m2));

			if (!Arrays.areEqual(m3, message)) {
				System.out.println("Error 2!");
			}
			
		}
		System.out.println("End");
	}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:59,代码来源:WrapperBBS98.java


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