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


Java PKCS12BagAttributeCarrier.setBagAttribute方法代码示例

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


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

示例1: createMasterCert

import org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier; //导入方法依赖的package包/类
/**
 * we generate the CA's certificate
 */
public static Certificate createMasterCert(
    PublicKey       pubKey,
    PrivateKey      privKey)
    throws Exception
{
    //
    // signers name 
    //
    String  issuer = "C=AU, O=The Legion of the Bouncy Castle, OU=Bouncy Primary Certificate";

    //
    // subjects name - the same as we are self signed.
    //
    String  subject = "C=AU, O=The Legion of the Bouncy Castle, OU=Bouncy Primary Certificate";

    //
    // create the certificate - version 1
    //

    v1CertGen.setSerialNumber(BigInteger.valueOf(1));
    v1CertGen.setIssuerDN(new X509Principal(issuer));
    v1CertGen.setNotBefore(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30));
    v1CertGen.setNotAfter(new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 30)));
    v1CertGen.setSubjectDN(new X509Principal(subject));
    v1CertGen.setPublicKey(pubKey);
    v1CertGen.setSignatureAlgorithm("SHA1WithRSAEncryption");

    X509Certificate cert = v1CertGen.generate(privKey);

    cert.checkValidity(new Date());

    cert.verify(pubKey);

    PKCS12BagAttributeCarrier   bagAttr = (PKCS12BagAttributeCarrier)cert;

    //
    // this is actually optional - but if you want to have control
    // over setting the friendly name this is the way to do it...
    //
    bagAttr.setBagAttribute(
        PKCSObjectIdentifiers.pkcs_9_at_friendlyName,
        new DERBMPString("Bouncy Primary Certificate"));

    return cert;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:49,代码来源:PKCS12Example.java

示例2: createIntermediateCert

import org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier; //导入方法依赖的package包/类
/**
 * we generate an intermediate certificate signed by our CA
 */
public static Certificate createIntermediateCert(
    PublicKey       pubKey,
    PrivateKey      caPrivKey,
    X509Certificate caCert)
    throws Exception
{
    //
    // subject name table.
    //
    Hashtable                   attrs = new Hashtable();
    Vector                      order = new Vector();

    attrs.put(X509Principal.C, "AU");
    attrs.put(X509Principal.O, "The Legion of the Bouncy Castle");
    attrs.put(X509Principal.OU, "Bouncy Intermediate Certificate");
    attrs.put(X509Principal.EmailAddress, "[email protected]");

    order.addElement(X509Principal.C);
    order.addElement(X509Principal.O);
    order.addElement(X509Principal.OU);
    order.addElement(X509Principal.EmailAddress);

    //
    // create the certificate - version 3
    //
    v3CertGen.reset();

    v3CertGen.setSerialNumber(BigInteger.valueOf(2));
    v3CertGen.setIssuerDN(PrincipalUtil.getSubjectX509Principal(caCert));
    v3CertGen.setNotBefore(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30));
    v3CertGen.setNotAfter(new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 30)));
    v3CertGen.setSubjectDN(new X509Principal(order, attrs));
    v3CertGen.setPublicKey(pubKey);
    v3CertGen.setSignatureAlgorithm("SHA1WithRSAEncryption");

    //
    // extensions
    //
    v3CertGen.addExtension(
        X509Extensions.SubjectKeyIdentifier,
        false,
        new SubjectKeyIdentifierStructure(pubKey));

    v3CertGen.addExtension(
        X509Extensions.AuthorityKeyIdentifier,
        false,
        new AuthorityKeyIdentifierStructure(caCert));

    v3CertGen.addExtension(
        X509Extensions.BasicConstraints,
        true,
        new BasicConstraints(0));

    X509Certificate cert = v3CertGen.generate(caPrivKey);

    cert.checkValidity(new Date());

    cert.verify(caCert.getPublicKey());

    PKCS12BagAttributeCarrier   bagAttr = (PKCS12BagAttributeCarrier)cert;

    //
    // this is actually optional - but if you want to have control
    // over setting the friendly name this is the way to do it...
    //
    bagAttr.setBagAttribute(
        PKCSObjectIdentifiers.pkcs_9_at_friendlyName,
        new DERBMPString("Bouncy Intermediate Certificate"));

    return cert;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:75,代码来源:PKCS12Example.java


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