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


Java CustomNamedCurves.getByName方法代码示例

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


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

示例1: testExportImport

import org.bouncycastle.crypto.ec.CustomNamedCurves; //导入方法依赖的package包/类
@Test
public void testExportImport() throws GeneralSecurityException {

	// Create a curve25519 parameter spec
	X9ECParameters params = CustomNamedCurves.getByName("curve25519");
	ECParameterSpec ecParameterSpec = new ECParameterSpec(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed());

	// Create public key
	KeyAgreementPeer peer = new ECDHPeer(ecParameterSpec, null, "BC");
	ECPublicKey ecPublicKey = (ECPublicKey) peer.getPublicKey();

	// Export public key
	byte[] encoded = ecPublicKey.getQ().getEncoded(true);

	System.out.println(Arrays.toString(encoded));
	System.out.println("Encoded length: " + encoded.length);

	// Import public key
	ECPublicKey importedECPublicKey = loadPublicKey(encoded);

	Assert.assertArrayEquals(ecPublicKey.getEncoded(), importedECPublicKey.getEncoded());
}
 
开发者ID:martinwithaar,项目名称:Encryptor4j,代码行数:23,代码来源:ECDHExportTest.java

示例2: getParametersForNamedCurve

import org.bouncycastle.crypto.ec.CustomNamedCurves; //导入方法依赖的package包/类
public static ECDomainParameters getParametersForNamedCurve(int namedCurve)
{
    String curveName = getNameOfNamedCurve(namedCurve);
    if (curveName == null)
    {
        return null;
    }

    // Parameters are lazily created the first time a particular curve is accessed

    X9ECParameters ecP = CustomNamedCurves.getByName(curveName);
    if (ecP == null)
    {
        ecP = ECNamedCurveTable.getByName(curveName);
        if (ecP == null)
        {
            return null;
        }
    }

    // It's a bit inefficient to do this conversion every time
    return new ECDomainParameters(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed());
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:24,代码来源:TlsECCUtils.java

示例3: main

import org.bouncycastle.crypto.ec.CustomNamedCurves; //导入方法依赖的package包/类
public static void main(String[] args)
{
    SortedSet names = new TreeSet(enumToList(ECNamedCurveTable.getNames()));
    names.addAll(enumToList(CustomNamedCurves.getNames()));

    Iterator it = names.iterator();
    while (it.hasNext())
    {
        String name = (String)it.next();
        X9ECParameters x9 = CustomNamedCurves.getByName(name);
        if (x9 == null)
        {
            x9 = ECNamedCurveTable.getByName(name);
        }
        if (x9 != null && ECAlgorithms.isF2mCurve(x9.getCurve()))
        {
            System.out.print(name + ":");
            implPrintNonZeroTraceBits(x9);
        }
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:22,代码来源:TraceOptimizer.java

示例4: main

import org.bouncycastle.crypto.ec.CustomNamedCurves; //导入方法依赖的package包/类
public static void main(String[] args)
{
    SortedSet names = new TreeSet(enumToList(ECNamedCurveTable.getNames()));
    names.addAll(enumToList(CustomNamedCurves.getNames()));

    Iterator it = names.iterator();
    while (it.hasNext())
    {
        String name = (String)it.next();
        X9ECParameters x9 = CustomNamedCurves.getByName(name);
        if (x9 == null)
        {
            x9 = ECNamedCurveTable.getByName(name);
        }
        if (x9 != null && ECAlgorithms.isF2mCurve(x9.getCurve()))
        {
            System.out.print(name + ":");
            implPrintRootZ(x9);
        }
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:22,代码来源:F2mSqrtOptimizer.java

示例5: getNamedCurveByName

import org.bouncycastle.crypto.ec.CustomNamedCurves; //导入方法依赖的package包/类
public static X9ECParameters getNamedCurveByName(
    String curveName)
{
    X9ECParameters params = CustomNamedCurves.getByName(curveName);

    if (params == null)
    {
        params = X962NamedCurves.getByName(curveName);
        if (params == null)
        {
            params = SECNamedCurves.getByName(curveName);
        }
        if (params == null)
        {
            params = NISTNamedCurves.getByName(curveName);
        }
        if (params == null)
        {
            params = TeleTrusTNamedCurves.getByName(curveName);
        }
    }

    return params;
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:25,代码来源:ECUtil.java

示例6: testDuplicateKey

import org.bouncycastle.crypto.ec.CustomNamedCurves; //导入方法依赖的package包/类
@Test
public void testDuplicateKey()
{
    ECKeyManager keyManager = new ECKeyManager(new TestUtils.BasicNodeContext("Test"));
    X9ECParameters ecParameters = CustomNamedCurves.getByName("secp256r1");
    ECDomainParameters domainParameters = new ECDomainParameters(ecParameters.getCurve(), ecParameters.getG(), ecParameters.getN(), ecParameters.getH());
    ECPoint h = domainParameters.getG().multiply(BigInteger.valueOf(1000001));

    keyManager.generateKeyPair("Test1", Algorithm.EC_ELGAMAL, 1, domainParameters, h);

    try
    {
        keyManager.generateKeyPair("Test1", Algorithm.EC_ELGAMAL, 1, domainParameters, h);

        Assert.fail("duplicate key not detected");
    }
    catch (IllegalStateException e)
    {
        Assert.assertEquals("Key Test1 already exists.", e.getMessage());
    }
}
 
开发者ID:cwgit,项目名称:ximix,代码行数:22,代码来源:ECKeyManagerTest.java

示例7: testFailedCommitment

import org.bouncycastle.crypto.ec.CustomNamedCurves; //导入方法依赖的package包/类
@Test
public void testFailedCommitment()
    throws Exception
{
    ECKeyManager keyManager = new ECKeyManager(new TestUtils.BasicNodeContext("Test"));
    X9ECParameters ecParameters = CustomNamedCurves.getByName("secp256r1");
    ECDomainParameters domainParameters = new ECDomainParameters(ecParameters.getCurve(), ecParameters.getG(), ecParameters.getN(), ecParameters.getH());
    ECPoint h = domainParameters.getG().multiply(BigInteger.valueOf(1000001));

    AsymmetricCipherKeyPair kp = keyManager.generateKeyPair("Test1", Algorithm.EC_ELGAMAL, 1, domainParameters, h);
    ECPrivateKeyParameters privKey = (ECPrivateKeyParameters)kp.getPrivate();
    ECPublicKeyParameters pubKey = (ECPublicKeyParameters)kp.getPublic();
    ECPoint commitment = pubKey.getParameters().getG().multiply(privKey.getD()).add(h);

    try
    {
        keyManager.buildSharedKey("Test1", new ECCommittedSecretShareMessage(0, privKey.getD(), BigInteger.TEN, new ECPoint[]{commitment}, pubKey.getQ(), new ECPoint[]{pubKey.getQ()}));

        Assert.fail("bad commitment not detected");
    }
    catch (IllegalStateException e)
    {
        Assert.assertEquals("Commitment for Test1 failed!", e.getMessage());
    }
}
 
开发者ID:cwgit,项目名称:ximix,代码行数:26,代码来源:ECKeyManagerTest.java

示例8: testBasicGenerationNoPeers

import org.bouncycastle.crypto.ec.CustomNamedCurves; //导入方法依赖的package包/类
@Test
public void testBasicGenerationNoPeers()
    throws Exception
{
    XimixNodeContext context = new XimixNodeContext(new HashMap<String, ServicesConnection>(), new Config(createConfig("A")), new TestNotifier());

    try
    {
        List<String> peers = Arrays.asList("A", "B", "C");
        NamedKeyGenParams kGenParams = new NamedKeyGenParams("EC_KEY", Algorithm.EC_ELGAMAL, "secp256r1", 4, peers);
        X9ECParameters ecParameters = CustomNamedCurves.getByName("secp256r1");
        ECDomainParameters domainParameters = new ECDomainParameters(ecParameters.getCurve(), ecParameters.getG(), ecParameters.getN(), ecParameters.getH());
        ECPoint h = domainParameters.getG().multiply(BigInteger.valueOf(1000001));
        ECCommittedSecretShareMessage[] messages = ((ECNewDKGGenerator)context.getKeyPairGenerator(Algorithm.EC_ELGAMAL))
            .generateThresholdKey("EC_KEY", domainParameters, kGenParams.getNodesToUse().size(), kGenParams.getThreshold(), h);

        Assert.fail("no exception!");
    }
    catch (IllegalArgumentException e)
    {
        if (!"numberOfPeers must at least be as big as the threshold value.".equals(e.getMessage()))
        {
            Assert.fail("exception but wrong message");
        }
    }
}
 
开发者ID:cwgit,项目名称:ximix,代码行数:27,代码来源:CryptoServicesTest.java

示例9: loadPublicKey

import org.bouncycastle.crypto.ec.CustomNamedCurves; //导入方法依赖的package包/类
/**
 * Loads and returns the elliptic-curve public key from the data byte array.
 * @param data
 * @return
 * @throws NoSuchAlgorithmException
 * @throws NoSuchProviderException
 * @throws InvalidKeySpecException
 */
public static ECPublicKey loadPublicKey(byte[] data) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException
{
	X9ECParameters params = CustomNamedCurves.getByName("curve25519");
	ECParameterSpec ecParameterSpec = new ECParameterSpec(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed());

	ECPublicKeySpec publicKey = new ECPublicKeySpec(ecParameterSpec.getCurve().decodePoint(data), ecParameterSpec);
	KeyFactory kf = KeyFactory.getInstance("ECDH", "BC");
	return (ECPublicKey) kf.generatePublic(publicKey);
}
 
开发者ID:martinwithaar,项目名称:Encryptor4j,代码行数:18,代码来源:ECDHExportTest.java

示例10: testBasicGeneration

import org.bouncycastle.crypto.ec.CustomNamedCurves; //导入方法依赖的package包/类
@Test
public void testBasicGeneration()
    throws Exception
{
    Map<String, XimixNodeContext>  contextMap = createContextMap(5);

    XimixNodeContext context = contextMap.get("A");

    List<String> peers = Arrays.asList("A", "B", "C", "D", "E");
    NamedKeyGenParams kGenParams = new NamedKeyGenParams("EC_KEY", Algorithm.EC_ELGAMAL, "secp256r1", 4, peers);
    X9ECParameters ecParameters = CustomNamedCurves.getByName("secp256r1");
    ECDomainParameters domainParameters = new ECDomainParameters(ecParameters.getCurve(), ecParameters.getG(), ecParameters.getN(), ecParameters.getH());
    ECPoint h = domainParameters.getG().multiply(BigInteger.valueOf(1000001));
    ECCommittedSecretShareMessage[] messages = ((ECNewDKGGenerator)context.getKeyPairGenerator(Algorithm.EC_ELGAMAL))
        .generateThresholdKey("EC_KEY", domainParameters, kGenParams.getNodesToUse().size(), kGenParams.getThreshold(), h);
    Assert.assertEquals(5, messages.length);

    X9ECParameters params = CustomNamedCurves.getByName("secp256r1");
    ECDomainParameters domainParams = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed());

    for (int i = 0; i != messages.length; i++)
    {
        ECCommittedSecretShareMessage message = ECCommittedSecretShareMessage.getInstance(params.getCurve(), messages[i].getEncoded());
        ECCommittedSecretShare share = new ECCommittedSecretShare(message.getValue(), message.getWitness(), message.getCommitmentFactors());

        Assert.assertTrue(share.isRevealed(i, domainParams, h));
    }
}
 
开发者ID:cwgit,项目名称:ximix,代码行数:29,代码来源:CryptoServicesTest.java

示例11: handle

import org.bouncycastle.crypto.ec.CustomNamedCurves; //导入方法依赖的package包/类
public MessageReply handle(final KeyPairGenerateMessage message)
{
    // TODO: sort out the reply messages
    try
    {
        switch (((Type)message.getType()))
        {
        case GENERATE:
            final NamedKeyGenParams ecKeyGenParams = (NamedKeyGenParams)NamedKeyGenParams.getInstance(message.getPayload());
            final List<String> involvedPeers = ecKeyGenParams.getNodesToUse();

            X9ECParameters params = CustomNamedCurves.getByName(ecKeyGenParams.getDomainParameters());

            if (params == null)
            {
                params = ECNamedCurveTable.getByName(ecKeyGenParams.getDomainParameters());
            }

            paramsMap.put(ecKeyGenParams.getKeyID(), new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed()));

            sharedHMap.init(ecKeyGenParams.getKeyID(), involvedPeers.size());

            BigInteger h = generateH(params.getN(), new SecureRandom());  // TODO: provide randomness?
            ECPoint[]    messages = new ECPoint[involvedPeers.size()];

            for (int i = 0; i != messages.length; i++)
            {
                messages[i] = params.getG().multiply(h);
            }

            nodeContext.execute(new SendHTask(message.getAlgorithm(), ecKeyGenParams.getKeyID(), involvedPeers, messages));

            final List<String> peerList = ecKeyGenParams.getNodesToUse();

            ECNewDKGGenerator generator = (ECNewDKGGenerator)nodeContext.getKeyPairGenerator(ecKeyGenParams.getAlgorithm());

            ECCommittedSecretShareMessage[] comMessages = generator.generateThresholdKey(
                                                                      ecKeyGenParams.getKeyID(), paramsMap.get(ecKeyGenParams.getKeyID()), peerList.size(),
                                                                      ecKeyGenParams.getThreshold(), sharedHMap.getShare(ecKeyGenParams.getKeyID()).getValue().normalize());

            nodeContext.execute(new SendShareTask(generator, message.getAlgorithm(), ecKeyGenParams.getKeyID(), peerList, comMessages));

            return new MessageReply(MessageReply.Type.OKAY);
        case STORE_H:
            StoreMessage storeMessage = StoreMessage.getInstance(message.getPayload());
            ShareMessage shareMessage = ShareMessage.getInstance(storeMessage.getSecretShareMessage());

            nodeContext.execute(new StoreHTask(storeMessage.getID(), shareMessage));

            return new MessageReply(MessageReply.Type.OKAY);
        case STORE:
            StoreMessage sssMessage = StoreMessage.getInstance(message.getPayload());

            // we may not have been asked to generate our share yet, if this is the case we need to queue up our share requests
            // till we can validate them.
            generator = (ECNewDKGGenerator)nodeContext.getKeyPairGenerator(message.getAlgorithm());

            nodeContext.execute(new StoreShareTask(generator, sssMessage.getID(), sssMessage.getSecretShareMessage()));

            return new MessageReply(MessageReply.Type.OKAY);
        default:
            return new MessageReply(MessageReply.Type.ERROR, new DERUTF8String("Unknown command in NodeKeyGenerationService."));
        }
    }
    catch (Exception e)
    {
        nodeContext.getEventNotifier().notify(EventNotifier.Level.ERROR, "NodeKeyGenerationService failure: " + e.getMessage(), e);

        return new MessageReply(MessageReply.Type.ERROR, new DERUTF8String("NodeKeyGenerationService failure: " + e.getMessage()));
    }

}
 
开发者ID:cwgit,项目名称:ximix,代码行数:73,代码来源:ECKeyPairGenerator.java

示例12: testSingleKeyStoreAndLoad

import org.bouncycastle.crypto.ec.CustomNamedCurves; //导入方法依赖的package包/类
@Test
public void testSingleKeyStoreAndLoad()
    throws Exception
{
    ECKeyManager keyManager = new ECKeyManager(new TestUtils.BasicNodeContext("Test"));

    X9ECParameters ecParameters = CustomNamedCurves.getByName("secp256r1");
    ECDomainParameters domainParameters = new ECDomainParameters(ecParameters.getCurve(), ecParameters.getG(), ecParameters.getN(), ecParameters.getH());
    ECPoint h = domainParameters.getG().multiply(BigInteger.valueOf(1000001));

    AsymmetricCipherKeyPair kp = keyManager.generateKeyPair("Test1", Algorithm.EC_ELGAMAL, 1, domainParameters, h);
    ECPrivateKeyParameters privKey = (ECPrivateKeyParameters)kp.getPrivate();
    ECPublicKeyParameters pubKey = (ECPublicKeyParameters)kp.getPublic();

    ECPoint commitment = pubKey.getParameters().getG().multiply(privKey.getD()).add(h);

    keyManager.buildSharedKey("Test1", new ECCommittedSecretShareMessage(0, privKey.getD(), BigInteger.ONE, new ECPoint[]{commitment}, pubKey.getQ(), new ECPoint[]{pubKey.getQ()}));

    keyManager.fetchPublicKey("Test1"); // make sure we've synced up

    byte[] p12enc = keyManager.getEncoded(passwd);

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

    keyStore.load(new ByteArrayInputStream(p12enc), passwd);

    Assert.assertEquals(1, keyStore.size());

    Assert.assertTrue(keyStore.containsAlias("Test1"));

    ECKeyManager rebuiltKeyManager = new ECKeyManager(new TestUtils.BasicNodeContext("Test"));

    rebuiltKeyManager.load(passwd, p12enc);

    Assert.assertFalse(keyManager.isSigningKey("Test1"));
    Assert.assertFalse(rebuiltKeyManager.isSigningKey("Test1"));
    Assert.assertEquals(SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(kp.getPublic()), keyManager.fetchPublicKey("Test1"));
    Assert.assertEquals(((ECPrivateKeyParameters)kp.getPrivate()).getD(), keyManager.getPartialPrivateKey("Test1"));
    Assert.assertEquals(keyManager.fetchPublicKey("Test1"), rebuiltKeyManager.fetchPublicKey("Test1"));
    Assert.assertEquals(keyManager.getPartialPrivateKey("Test1"), rebuiltKeyManager.getPartialPrivateKey("Test1"));
}
 
开发者ID:cwgit,项目名称:ximix,代码行数:42,代码来源:ECKeyManagerTest.java


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