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


Java PKCS12BagAttributeCarrier类代码示例

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


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

示例3: usingBagAttributeCarrier

import org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier; //导入依赖的package包/类
public static PKCS12BagAttributeSetter usingBagAttributeCarrier(PrivateKey privateKey) {
    return new PKCS12BagAttributeSetter((PKCS12BagAttributeCarrier) privateKey);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:4,代码来源:PKCS12BagAttributeSetter.java

示例4: PKCS12BagAttributeSetter

import org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier; //导入依赖的package包/类
private PKCS12BagAttributeSetter(PKCS12BagAttributeCarrier carrier) {
    this.carrier = carrier;
}
 
开发者ID:gocd,项目名称:gocd,代码行数:4,代码来源:PKCS12BagAttributeSetter.java

示例5: testNoExtraLocalKeyID

import org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier; //导入依赖的package包/类
private void testNoExtraLocalKeyID(byte[] store1data)
    throws Exception
{
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");

    kpg.initialize(512);

    KeyPair newPair = kpg.genKeyPair();

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

    store1.load(new ByteArrayInputStream(store1data), passwd);

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

    store2.load(null, null);
    
    PrivateKey k1 = (PrivateKey)store1.getKey("privatekey", null);
    Certificate[] chain1 = store1.getCertificateChain("privatekey");

    Certificate[] chain2 = new Certificate[chain1.length + 1];

    System.arraycopy(chain1, 0, chain2, 1, chain1.length);

    chain2[0] = createCert(newPair.getPublic(), k1, "[email protected]", "[email protected]");

    if (((PKCS12BagAttributeCarrier)chain1[0]).getBagAttribute(PKCSObjectIdentifiers.pkcs_9_at_localKeyId) == null)
    {
        fail("localKeyID not found initially");
    }
    
    store2.setKeyEntry("new", newPair.getPrivate(), null, chain2);

    ByteArrayOutputStream bOut = new ByteArrayOutputStream();

    store2.store(bOut, passwd);

    store2.load(new ByteArrayInputStream(bOut.toByteArray()), passwd);

    chain2 = store2.getCertificateChain("new");

    if (((PKCS12BagAttributeCarrier)chain2[1]).getBagAttribute(PKCSObjectIdentifiers.pkcs_9_at_localKeyId) != null)
    {
        fail("localKeyID found after save");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:47,代码来源:PKCS12StoreTest.java


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