• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ECNamedCurveGenParameterSpec类的典型用法和代码示例

java 1次浏览

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

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

示例1: initialize

点赞 2

import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec; //导入依赖的package包/类
public void initialize(
    AlgorithmParameterSpec  params,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    if (params == null)
    {
        ECParameterSpec implicitCA = configuration.getEcImplicitlyCa();
        if (implicitCA == null)
        {
            throw new InvalidAlgorithmParameterException("null parameter passed but no implicitCA set");
        }

        this.ecParams = null;
        this.param = createKeyGenParamsBC(implicitCA, random);
    }
    else if (params instanceof ECParameterSpec)
    {
        this.ecParams = params;
        this.param = createKeyGenParamsBC((ECParameterSpec)params, random);
    }
    else if (params instanceof java.security.spec.ECParameterSpec)
    {
        this.ecParams = params;
        this.param = createKeyGenParamsJCE((java.security.spec.ECParameterSpec)params, random);
    }
    else if (params instanceof ECGenParameterSpec)
    {
        initializeNamedCurve(((ECGenParameterSpec)params).getName(), random);
    }
    else if (params instanceof ECNamedCurveGenParameterSpec)
    {
        initializeNamedCurve(((ECNamedCurveGenParameterSpec)params).getName(), random);
    }
    else
    {
        throw new InvalidAlgorithmParameterException("parameter object not a ECParameterSpec");
    }

    engine.init(param);
    initialised = true;
}
 

开发者ID:thedrummeraki,
项目名称:Aki-SSL,
代码行数:43,
代码来源:KeyPairGeneratorSpi.java

示例2: main

点赞 2

import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec; //导入依赖的package包/类
public static void main(String[] args)
    throws Exception
{
    if (args.length != 5)
    {
        System.err.println("Usage: GenNodeKeyStore nodeName trustAnchorKeyStore trustAnchorPassword keyStoreName keyStorePassword");
        System.exit(1);
    }

    Security.addProvider(new BouncyCastleProvider());

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

    kpGen.initialize(new ECNamedCurveGenParameterSpec("secp256r1"));

    KeyPair kp = kpGen.generateKeyPair();

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

    trustStore.load(new FileInputStream(args[1] + ".p12"), args[2].toCharArray());

    X509Certificate trustCert = (X509Certificate)trustStore.getCertificate("trust");
    PrivateKey      privKey = (PrivateKey)trustStore.getKey("trust", 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, args[0]);

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

    ContentSigner sigGen = new JcaContentSignerBuilder("SHA256withECDSA").setProvider("BC").build(privKey);

    JcaX509ExtensionUtils extensionUtils = new JcaX509ExtensionUtils(new SHA1DigestCalculator());
    X509v3CertificateBuilder certGen = new JcaX509v3CertificateBuilder(
        X500Name.getInstance(trustCert.getSubjectX500Principal().getEncoded()),
        BigInteger.valueOf(System.currentTimeMillis()),
        startDate, trustCert.getNotAfter(),
        builder.build(), kp.getPublic());

    certGen.addExtension(Extension.subjectKeyIdentifier, false, extensionUtils.createSubjectKeyIdentifier(kp.getPublic()));
    certGen.addExtension(Extension.authorityKeyIdentifier, false, extensionUtils.createAuthorityKeyIdentifier(trustCert));

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

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

    keyStore.load(null, null);

    keyStore.setKeyEntry("nodeCA", kp.getPrivate(), null, new Certificate[] { cert });

    keyStore.store(new FileOutputStream(args[3] + ".p12"), args[4].toCharArray());
}
 

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

示例3: main

点赞 1

import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec; //导入依赖的package包/类
public static void main(String[] args)
    throws Exception
{
    if (args.length != 2)
    {
        System.err.println("Usage: GenTrustAnchorKeyStore keyStoreName keyStorePassword");
        System.exit(1);
    }

    Security.addProvider(new BouncyCastleProvider());

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

    kpGen.initialize(new ECNamedCurveGenParameterSpec("secp256r1"));

    KeyPair kp = kpGen.generateKeyPair();

    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, "Trust Anchor");

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

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

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

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

    keyStore.load(null, null);

    keyStore.setKeyEntry("trust", kp.getPrivate(), null, new Certificate[] { cert });

    keyStore.store(new FileOutputStream(args[0] + ".p12"), args[1].toCharArray());

    PEMWriter pWrt = new PEMWriter(new FileWriter(args[0] + ".pem"));

    pWrt.writeObject(cert);

    pWrt.close();
}
 

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


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)