• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ECPointUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: decodeTest

import org.bouncycastle.jce.ECPointUtil; //导入依赖的package包/类
private void decodeTest()
{
    EllipticCurve curve = new EllipticCurve(
            new ECFieldFp(new BigInteger("6277101735386680763835789423207666416083908700390324961279")), // q
            new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a
            new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16)); // b

    ECPoint p = ECPointUtil.decodePoint(curve, Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012"));

    if (!p.getAffineX().equals(new BigInteger("188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012", 16)))
    {
        fail("x uncompressed incorrectly");
    }

    if (!p.getAffineY().equals(new BigInteger("7192b95ffc8da78631011ed6b24cdd573f977a11e794811", 16)))
    {
        fail("y uncompressed incorrectly");
    }
}
 
开发者ID:tsenger,项目名称:animamea,代码行数:20,代码来源:ECDSA5Test.java


示例2: getPubKeyFromCurve

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


示例3: getPublicKeyFromBytes

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


示例4: testJDKAPI

import org.bouncycastle.jce.ECPointUtil; //导入依赖的package包/类
private void testJDKAPI()
    throws Exception
{
    KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC");

    EllipticCurve curve = new EllipticCurve(
        new ECFieldFp(new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839")), // q
        new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
        new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

    java.security.spec.ECParameterSpec ecSpec = new java.security.spec.ECParameterSpec(
        curve,
        ECPointUtil.decodePoint(curve, Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
        new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n
        1); // h


    ConfigurableProvider config = (ConfigurableProvider)Security.getProvider("BC");

    config.setParameter(ConfigurableProvider.EC_IMPLICITLY_CA, ecSpec);

    g.initialize(null, new SecureRandom());

    KeyPair p = g.generateKeyPair();

    ECPrivateKey sKey = (ECPrivateKey)p.getPrivate();
    ECPublicKey vKey = (ECPublicKey)p.getPublic();

    testECDSA(sKey, vKey);

    testBCParamsAndQ(sKey, vKey);
    testEC5Params(sKey, vKey);

    testEncoding(sKey, vKey);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:36,代码来源:ImplicitlyCaTest.java


示例5: testBasicThreadLocal

import org.bouncycastle.jce.ECPointUtil; //导入依赖的package包/类
private void testBasicThreadLocal()
    throws Exception
{
    KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC");

    EllipticCurve curve = new EllipticCurve(
        new ECFieldFp(new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839")), // q
        new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
        new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

    java.security.spec.ECParameterSpec ecSpec = new java.security.spec.ECParameterSpec(
        curve,
        ECPointUtil.decodePoint(curve, Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
        new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n
        1); // h


    ConfigurableProvider config = (ConfigurableProvider)Security.getProvider("BC");

    config.setParameter(ConfigurableProvider.THREAD_LOCAL_EC_IMPLICITLY_CA, ecSpec);

    g.initialize(null, new SecureRandom());

    KeyPair p = g.generateKeyPair();

    ECPrivateKey sKey = (ECPrivateKey)p.getPrivate();
    ECPublicKey vKey = (ECPublicKey)p.getPublic();

    testECDSA(sKey, vKey);

    testBCParamsAndQ(sKey, vKey);
    testEC5Params(sKey, vKey);

    testEncoding(sKey, vKey);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:36,代码来源:ImplicitlyCaTest.java


示例6: createPublicKeySpec

import org.bouncycastle.jce.ECPointUtil; //导入依赖的package包/类
@Override
protected ECPublicKeySpec createPublicKeySpec(byte[] encodedKey) throws InvalidKeySpecException, NoSuchAlgorithmException {
    // decompress into an EC point
    ECPoint w = ECPointUtil.decodePoint(ecParameterSpec.getCurve(), encodedKey);
    
    // make a public key from the public point w
    ECPublicKeySpec publicKeySpec = new ECPublicKeySpec(w, ecParameterSpec);
    
    return publicKeySpec;
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:11,代码来源:ECDH256_ECDSA256.java


示例7: createPublicKeySpec

import org.bouncycastle.jce.ECPointUtil; //导入依赖的package包/类
@Override
protected ECPublicKeySpec createPublicKeySpec(byte[] encodedKey) throws InvalidKeySpecException, NoSuchAlgorithmException {
    // convert the key to the format used by BouncyCastle, which adds one byte
    byte[] bouncyCompressedKey = new byte[keyLengthBytes+1];
    System.arraycopy(encodedKey, 0, bouncyCompressedKey, 1, keyLengthBytes);
    bouncyCompressedKey[0] = (byte)((bouncyCompressedKey[1] >> 1) + 2);
    bouncyCompressedKey[1] &= 1;
    // decompress into an EC point
    ECPoint w = ECPointUtil.decodePoint(ecParameterSpec.getCurve(), bouncyCompressedKey);
    
    // make a public key from the public point w
    ECPublicKeySpec publicKeySpec = new ECPublicKeySpec(w, ecParameterSpec);
    
    return publicKeySpec;
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:16,代码来源:ECDH521_ECDSA521.java


示例8: testECDSA239bitPrime

import org.bouncycastle.jce.ECPointUtil; //导入依赖的package包/类
/**
 * X9.62 - 1998,<br>
 * J.3.2, Page 155, ECDSA over the field Fp<br>
 * an example with 239 bit prime
 */
private void testECDSA239bitPrime()
    throws Exception
{
    BigInteger r = new BigInteger("308636143175167811492622547300668018854959378758531778147462058306432176");
    BigInteger s = new BigInteger("323813553209797357708078776831250505931891051755007842781978505179448783");

    byte[] kData = BigIntegers.asUnsignedByteArray(new BigInteger("700000017569056646655505781757157107570501575775705779575555657156756655"));

    SecureRandom    k = new FixedSecureRandom(kData);

    EllipticCurve curve = new EllipticCurve(
        new ECFieldFp(new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839")), // q
        new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
        new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

    ECParameterSpec spec = new ECParameterSpec(
        curve,
        ECPointUtil.decodePoint(curve, Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
        new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n
        1); // h
    

    ECPrivateKeySpec priKey = new ECPrivateKeySpec(
        new BigInteger("876300101507107567501066130761671078357010671067781776716671676178726717"), // d
        spec);

    ECPublicKeySpec pubKey = new ECPublicKeySpec(
        ECPointUtil.decodePoint(curve, Hex.decode("025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70")), // Q
        spec);

    Signature           sgr = Signature.getInstance("ECDSA", "BC");
    KeyFactory          f = KeyFactory.getInstance("ECDSA", "BC");
    PrivateKey          sKey = f.generatePrivate(priKey);
    PublicKey           vKey = f.generatePublic(pubKey);

    sgr.initSign(sKey, k);

    byte[] message = new byte[] { (byte)'a', (byte)'b', (byte)'c' };

    sgr.update(message);

    byte[]  sigBytes = sgr.sign();
    System.out.println("Signatur:\n"+HexString.bufferToHex(sigBytes)+"\n");

    sgr.initVerify(vKey);

    sgr.update(message);

    if (!sgr.verify(sigBytes))
    {
        fail("239 Bit EC verification failed");
    }

    BigInteger[]  sig = derDecode(sigBytes);

    if (!r.equals(sig[0]))
    {
        fail("r component wrong." + System.getProperty("line.separator")
            + " expecting: " + r + System.getProperty("line.separator")
            + " got      : " + sig[0]);
    }

    if (!s.equals(sig[1]))
    {
        fail("s component wrong." + System.getProperty("line.separator")
            + " expecting: " + s + System.getProperty("line.separator")
            + " got      : " + sig[1]);
    }
}
 
开发者ID:tsenger,项目名称:animamea,代码行数:75,代码来源:ECDSA5Test.java


示例9: testECDSA239bitBinary

import org.bouncycastle.jce.ECPointUtil; //导入依赖的package包/类
/**
 * X9.62 - 1998,<br>
 * J.2.1, Page 100, ECDSA over the field F2m<br>
 * an example with 191 bit binary field
 */
private void testECDSA239bitBinary()
    throws Exception
{
    BigInteger r = new BigInteger("21596333210419611985018340039034612628818151486841789642455876922391552");
    BigInteger s = new BigInteger("197030374000731686738334997654997227052849804072198819102649413465737174");

    byte[] kData = BigIntegers.asUnsignedByteArray(new BigInteger("171278725565216523967285789236956265265265235675811949404040041670216363"));

    SecureRandom    k = new FixedSecureRandom(kData);

    EllipticCurve curve = new EllipticCurve(
        new ECFieldF2m(239, // m
                       new int[] { 36 }), // k
        new BigInteger("32010857077C5431123A46B808906756F543423E8D27877578125778AC76", 16), // a
        new BigInteger("790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16", 16)); // b

    ECParameterSpec params = new ECParameterSpec(
        curve,
        ECPointUtil.decodePoint(curve, Hex.decode("0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305")), // G
        new BigInteger("220855883097298041197912187592864814557886993776713230936715041207411783"), // n
        4); // h

    ECPrivateKeySpec priKeySpec = new ECPrivateKeySpec(
        new BigInteger("145642755521911534651321230007534120304391871461646461466464667494947990"), // d
        params);
    
    ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(
        ECPointUtil.decodePoint(curve, Hex.decode("045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5")), // Q
        params);

    Signature   sgr = Signature.getInstance("ECDSA", "BC");
    KeyFactory  f = KeyFactory.getInstance("ECDSA", "BC");
    PrivateKey  sKey = f.generatePrivate(priKeySpec);
    PublicKey   vKey = f.generatePublic(pubKeySpec);
    byte[]      message = new byte[] { (byte)'a', (byte)'b', (byte)'c' };
   
    sgr.initSign(sKey, k);

    sgr.update(message);
    
    byte[]  sigBytes = sgr.sign();

    sgr.initVerify(vKey);

    sgr.update(message);

    if (!sgr.verify(sigBytes))
    {
        fail("239 Bit EC verification failed");
    }

    BigInteger[]  sig = derDecode(sigBytes);

    if (!r.equals(sig[0]))
    {
        fail("r component wrong." + System.getProperty("line.separator")
            + " expecting: " + r + System.getProperty("line.separator")
            + " got      : " + sig[0]);
    }

    if (!s.equals(sig[1]))
    {
        fail("s component wrong." + System.getProperty("line.separator")
            + " expecting: " + s + System.getProperty("line.separator")
            + " got      : " + sig[1]);
    }
}
 
开发者ID:tsenger,项目名称:animamea,代码行数:73,代码来源:ECDSA5Test.java


示例10: testGeneration

import org.bouncycastle.jce.ECPointUtil; //导入依赖的package包/类
private void testGeneration()
    throws Exception
{
    //
    // ECDSA generation test
    //
    byte[]              data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
    Signature s = Signature.getInstance("ECDSA", "BC");
    KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC");

    EllipticCurve curve = new EllipticCurve(
        new ECFieldFp(new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839")), // q
        new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
        new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

    ECParameterSpec ecSpec = new ECParameterSpec(
        curve,
        ECPointUtil.decodePoint(curve, Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
        new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n
        1); // h

    g.initialize(ecSpec, new SecureRandom());

    KeyPair p = g.generateKeyPair();

    PrivateKey sKey = p.getPrivate();
    PublicKey  vKey = p.getPublic();

    s.initSign(sKey);

    s.update(data);

    byte[] sigBytes = s.sign();

    s = Signature.getInstance("ECDSA", "BC");

    s.initVerify(vKey);

    s.update(data);

    if (!s.verify(sigBytes))
    {
        fail("ECDSA verification failed");
    }

    testKeyFactory((ECPublicKey)vKey, (ECPrivateKey)sKey);
}
 
开发者ID:tsenger,项目名称:animamea,代码行数:48,代码来源:ECDSA5Test.java


示例11: testECMQV

import org.bouncycastle.jce.ECPointUtil; //导入依赖的package包/类
private void testECMQV()
    throws Exception
{
    KeyPairGenerator g = KeyPairGenerator.getInstance("ECMQV", "BC");

    EllipticCurve curve = new EllipticCurve(
            new ECFieldFp(new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839")), // q
            new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
            new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

    ECParameterSpec ecSpec = new ECParameterSpec(
            curve,
            ECPointUtil.decodePoint(curve, Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
            new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n
            1); // h

    g.initialize(ecSpec, new SecureRandom());

    //
    // U side
    //
    KeyPair U1 = g.generateKeyPair();
    KeyPair U2 = g.generateKeyPair();

    KeyAgreement uAgree = KeyAgreement.getInstance("ECMQV", "BC");
    uAgree.init(new MQVPrivateKeySpec(U1.getPrivate(), U2.getPrivate(), U2.getPublic()));

    //
    // V side
    //
    KeyPair V1 = g.generateKeyPair();
    KeyPair V2 = g.generateKeyPair();

    KeyAgreement vAgree = KeyAgreement.getInstance("ECMQV", "BC");
    vAgree.init(new MQVPrivateKeySpec(V1.getPrivate(), V2.getPrivate(), V2.getPublic()));

    //
    // agreement
    //
    uAgree.doPhase(new MQVPublicKeySpec(V1.getPublic(), V2.getPublic()), true);
    vAgree.doPhase(new MQVPublicKeySpec(U1.getPublic(), U2.getPublic()), true);

    BigInteger ux = new BigInteger(uAgree.generateSecret());
    BigInteger vx = new BigInteger(vAgree.generateSecret());

    if (!ux.equals(vx))
    {
        fail("Agreement failed");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:51,代码来源:MQVTest.java


示例12: testECDSA239bitPrime

import org.bouncycastle.jce.ECPointUtil; //导入依赖的package包/类
/**
 * X9.62 - 1998,<br>
 * J.3.2, Page 155, ECDSA over the field Fp<br>
 * an example with 239 bit prime
 */
private void testECDSA239bitPrime()
    throws Exception
{
    BigInteger r = new BigInteger("308636143175167811492622547300668018854959378758531778147462058306432176");
    BigInteger s = new BigInteger("323813553209797357708078776831250505931891051755007842781978505179448783");

    byte[] kData = BigIntegers.asUnsignedByteArray(new BigInteger("700000017569056646655505781757157107570501575775705779575555657156756655"));

    SecureRandom    k = new FixedSecureRandom(kData);

    EllipticCurve curve = new EllipticCurve(
        new ECFieldFp(new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839")), // q
        new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
        new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

    ECParameterSpec spec = new ECParameterSpec(
        curve,
        ECPointUtil.decodePoint(curve, Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
        new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n
        1); // h
    

    ECPrivateKeySpec priKey = new ECPrivateKeySpec(
        new BigInteger("876300101507107567501066130761671078357010671067781776716671676178726717"), // d
        spec);

    ECPublicKeySpec pubKey = new ECPublicKeySpec(
        ECPointUtil.decodePoint(curve, Hex.decode("025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70")), // Q
        spec);

    Signature           sgr = Signature.getInstance("ECDSA", "BC");
    KeyFactory          f = KeyFactory.getInstance("ECDSA", "BC");
    PrivateKey          sKey = f.generatePrivate(priKey);
    PublicKey           vKey = f.generatePublic(pubKey);

    sgr.initSign(sKey, k);

    byte[] message = new byte[] { (byte)'a', (byte)'b', (byte)'c' };

    sgr.update(message);

    byte[]  sigBytes = sgr.sign();

    sgr.initVerify(vKey);

    sgr.update(message);

    if (!sgr.verify(sigBytes))
    {
        fail("239 Bit EC verification failed");
    }

    BigInteger[]  sig = derDecode(sigBytes);

    if (!r.equals(sig[0]))
    {
        fail("r component wrong." + System.getProperty("line.separator")
            + " expecting: " + r + System.getProperty("line.separator")
            + " got      : " + sig[0]);
    }

    if (!s.equals(sig[1]))
    {
        fail("s component wrong." + System.getProperty("line.separator")
            + " expecting: " + s + System.getProperty("line.separator")
            + " got      : " + sig[1]);
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:74,代码来源:ECDSA5Test.java


示例13: testGeneration

import org.bouncycastle.jce.ECPointUtil; //导入依赖的package包/类
private void testGeneration()
    throws Exception
{
    //
    // ECDSA generation test
    //
    byte[]              data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
    Signature s = Signature.getInstance("ECDSA", "BC");
    KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC");

    EllipticCurve curve = new EllipticCurve(
        new ECFieldFp(new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839")), // q
        new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
        new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

    ECParameterSpec ecSpec = new ECParameterSpec(
        curve,
        ECPointUtil.decodePoint(curve, Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
        new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n
        1); // h

    g.initialize(ecSpec, new SecureRandom());

    KeyPair p = g.generateKeyPair();

    PrivateKey sKey = p.getPrivate();
    PublicKey  vKey = p.getPublic();

    s.initSign(sKey);

    s.update(data);

    byte[] sigBytes = s.sign();

    s = Signature.getInstance("ECDSA", "BC");

    s.initVerify(vKey);

    s.update(data);

    if (!s.verify(sigBytes))
    {
        fail("ECDSA verification failed");
    }

    testKeyFactory((ECPublicKey)vKey, (ECPrivateKey)sKey);
    testSerialise((ECPublicKey)vKey, (ECPrivateKey)sKey);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:49,代码来源:ECDSA5Test.java


示例14: genCAKeyStore

import org.bouncycastle.jce.ECPointUtil; //导入依赖的package包/类
static KeyStore genCAKeyStore(String nodeName)
{
    try
    {
        KeyFactory fact = KeyFactory.getInstance("ECDSA", "BC");

        EllipticCurve curve = new EllipticCurve(
            new ECFieldFp(new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839")), // q
            new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
            new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

        ECParameterSpec spec = new ECParameterSpec(
            curve,
            ECPointUtil.decodePoint(curve, Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
            new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n
            1); // h


        ECPrivateKeySpec priKeySpec = new ECPrivateKeySpec(
            new BigInteger("876300101507107567501066130761671078357010671067781776716671676178726717"), // d
            spec);

        ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(
            ECPointUtil.decodePoint(curve, Hex.decode("025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70")), // Q
            spec);

        PrivateKey sigKey = fact.generatePrivate(priKeySpec);
        PublicKey pubKey = fact.generatePublic(pubKeySpec);

        KeyStore ks = KeyStore.getInstance("PKCS12", "BC");

        ks.load(null, null);

        X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE);

        builder.addRDN(BCStyle.C, "AU");
        builder.addRDN(BCStyle.O, "Crypto Workshop Pty Ltd");
        builder.addRDN(BCStyle.OU, "Ximix Node Test CA");
        builder.addRDN(BCStyle.L, "Melbourne");
        builder.addRDN(BCStyle.ST, "Victoria");
        builder.addRDN(BCStyle.CN, nodeName);

        Date startDate = new Date(System.currentTimeMillis() - 50000);

        ContentSigner sigGen = new JcaContentSignerBuilder("SHA256withECDSA").setProvider("BC").build(sigKey);
        X509v1CertificateBuilder certGen1 = new JcaX509v1CertificateBuilder(builder.build(), BigInteger.valueOf(1), startDate, new Date(System.currentTimeMillis() + YEAR), builder.build(), pubKey);

        X509Certificate cert = new JcaX509CertificateConverter().setProvider("BC").getCertificate(certGen1.build(sigGen));

        ks.setKeyEntry("nodeCA", sigKey, new char[0], new Certificate[]{cert});

        return ks;
    }
    catch (Exception e)
    {
        throw new IllegalStateException("unable to set up test CA", e);
    }
}
 
开发者ID:cwgit,项目名称:ximix,代码行数:59,代码来源:TestUtils.java


示例15: loadP256Dh

import org.bouncycastle.jce.ECPointUtil; //导入依赖的package包/类
/**
 * Creates a public key from the p256dh encoded using URL-safe Base64
 * @param p256dh p256dh string
 * @return Public Key
 * @throws NoSuchProviderException
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeySpecException
 */
public ECPublicKey loadP256Dh(final String p256dh)
    throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException {
  final byte[] p256dhBytes = Base64.getUrlDecoder().decode(p256dh);
  final ECPoint point = ECPointUtil.decodePoint(_ecNamedCurveSpec.getCurve(), p256dhBytes);
  ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(point, _ecNamedCurveSpec);
  return (ECPublicKey) _keyFactory.generatePublic(pubKeySpec);
}
 
开发者ID:gauntface,项目名称:web-push-java,代码行数:16,代码来源:EllipticCurveKeyUtil.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FluentCaseInsensitiveStringsMap类代码示例发布时间:2022-05-22
下一篇:
Java GraphicsUtilities类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap