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


Java JceCMSContentEncryptorBuilder类代码示例

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


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

示例1: encrypt

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
private byte[] encrypt(byte[] data) throws CertificateEncodingException,
		CMSException, IOException {
	CMSEnvelopedDataGenerator cmsEnvelopedDataGenerator = new CMSEnvelopedDataGenerator();
	for (X509Certificate destinationCertificate : this.destinationCertificates) {
		cmsEnvelopedDataGenerator
				.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(
						destinationCertificate)
						.setProvider(BouncyCastleProvider.PROVIDER_NAME));
	}
	CMSTypedData cmsTypedData = new CMSProcessableByteArray(data);
	CMSEnvelopedData cmsEnvelopedData = cmsEnvelopedDataGenerator.generate(
			cmsTypedData,
			new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC)
					.setProvider(BouncyCastleProvider.PROVIDER_NAME)
					.build());
	return cmsEnvelopedData.getEncoded();
}
 
开发者ID:e-Contract,项目名称:mycarenet,代码行数:18,代码来源:Sealer.java

示例2: testECKeyAgree

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
public void testECKeyAgree()
    throws Exception
{
    byte[] data = Hex.decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");

    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();

    edGen.addRecipientInfoGenerator(new JceKeyAgreeRecipientInfoGenerator(CMSAlgorithm.ECDH_SHA1KDF,
        _origEcKP.getPrivate(), _origEcKP.getPublic(),
         CMSAlgorithm.AES128_WRAP).addRecipient(_reciEcCert).setProvider(BC));

    CMSEnvelopedData ed = edGen.generate(
        new CMSProcessableByteArray(data),
        new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider(BC).build());

    assertEquals(ed.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.AES128_CBC);

    RecipientInformationStore recipients = ed.getRecipientInfos();

    confirmDataReceived(recipients, data, _reciEcCert, _reciEcKP.getPrivate(), BC);
    confirmNumberRecipients(recipients, 1);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:23,代码来源:NewEnvelopedDataTest.java

示例3: testECMQVKeyAgree

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
public void testECMQVKeyAgree()
    throws Exception
{
    byte[] data = Hex.decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");

    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();

    edGen.addRecipientInfoGenerator(new JceKeyAgreeRecipientInfoGenerator(CMSAlgorithm.ECMQV_SHA1KDF,
        _origEcKP.getPrivate(), _origEcKP.getPublic(),
        CMSAlgorithm.AES128_WRAP).addRecipient(_reciEcCert).setProvider(BC));

    CMSEnvelopedData ed = edGen.generate(
        new CMSProcessableByteArray(data),
        new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider(BC).build());

    assertEquals(ed.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.AES128_CBC);

    RecipientInformationStore recipients = ed.getRecipientInfos();

    confirmDataReceived(recipients, data, _reciEcCert, _reciEcKP.getPrivate(), BC);
    confirmNumberRecipients(recipients, 1);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:23,代码来源:NewEnvelopedDataTest.java

示例4: testHeaders

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
public void testHeaders()
    throws Exception
{
    MimeBodyPart    msg      = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");

    SMIMEEnvelopedGenerator  gen = new SMIMEEnvelopedGenerator();
      
    gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));
     
    //
    // generate a MimeBodyPart object which encapsulates the content
    // we want encrypted.
    //

    MimeBodyPart mp = gen.generate(msg, new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).setProvider(BC).build());

    assertEquals("application/pkcs7-mime; name=\"smime.p7m\"; smime-type=enveloped-data", mp.getHeader("Content-Type")[0]);
    assertEquals("attachment; filename=\"smime.p7m\"", mp.getHeader("Content-Disposition")[0]);
    assertEquals("S/MIME Encrypted Message", mp.getHeader("Content-Description")[0]);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:21,代码来源:NewSMIMEEnvelopedTest.java

示例5: verifyAlgorithm

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
private void verifyAlgorithm(
    String algorithmOid,
    MimeBodyPart msg) 
    throws Exception
{
    SMIMEEnvelopedGenerator  gen = new SMIMEEnvelopedGenerator();
      
    gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));
     
    //
    // generate a MimeBodyPart object which encapsulates the content
    // we want encrypted.
    //

    MimeBodyPart   mp = gen.generate(msg, new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(algorithmOid)).setProvider(BC).build());
    SMIMEEnveloped m = new SMIMEEnveloped(mp);
    RecipientId    recId = getRecipientId(_reciCert);

    RecipientInformationStore  recipients = m.getRecipientInfos();
    RecipientInformation       recipient = recipients.get(recId);

    MimeBodyPart    res = SMIMEUtil.toMimeBodyPart(recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC)));

    verifyMessageBytes(msg, res);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:26,代码来源:NewSMIMEEnvelopedTest.java

示例6: verifyParserAlgorithm

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
private void verifyParserAlgorithm(
    String algorithmOid,
    MimeBodyPart msg) 
    throws Exception
{
    SMIMEEnvelopedGenerator  gen = new SMIMEEnvelopedGenerator();

    gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));

    //
    // generate a MimeBodyPart object which encapsulates the content
    // we want encrypted.
    //

    MimeBodyPart         mp = gen.generate(msg, new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(algorithmOid)).setProvider(BC).build());
    SMIMEEnvelopedParser m = new SMIMEEnvelopedParser(mp);
    RecipientId          recId = getRecipientId(_reciCert);

    RecipientInformationStore  recipients = m.getRecipientInfos();
    RecipientInformation       recipient = recipients.get(recId);

    MimeBodyPart    res = SMIMEUtil.toMimeBodyPart(recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC)));

    verifyMessageBytes(msg, res);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:26,代码来源:NewSMIMEEnvelopedTest.java

示例7: testHeaders

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
@Test
public void testHeaders()
        throws Exception {
    InternetHeaders ih = new InternetHeaders();
    ih.addHeader("Content-Type", "application/xml");

    MimeBodyPart _msg = new MimeBodyPart(ih, "<customer name=\"bill\"/>".getBytes());


    SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
    OutputEncryptor encryptor = new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC)
            .setProvider("BC")
            .build();

    RecipientInfoGenerator generator = new JceKeyTransRecipientInfoGenerator(cert);
    gen.addRecipientInfoGenerator(generator);

    //
    // generate a MimeBodyPart object which encapsulates the content
    // we want encrypted.
    //

    MimeBodyPart mp = gen.generate(_msg, encryptor);

    output(mp);
}
 
开发者ID:gini,项目名称:jersey-smime,代码行数:27,代码来源:EnvelopedTest.java

示例8: encrypt

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
/**
   * Encrypts the encapsulated MIME body part.
   * 
   * @param cert the certificate for encryption.
   * @return an S/MIME message encapsulating the encrypted MIME body part. 
   * @throws SMimeException if unable to encrpyt the body part.
   */
  public SMimeMessage encrypt(X509Certificate cert) throws SMimeException {
      try {
          try {
              if (cert == null) {
                  throw new SMimeException("No certificate for encryption");
              }

              setDefaults();
              
              /* Create the encrypter */
              SMIMEEnvelopedGenerator encrypter = new SMIMEEnvelopedGenerator();
              encrypter.setContentTransferEncoding(getContentTransferEncoding());
              // encrypter.addKeyTransRecipient(cert); // Deprecated
encrypter.addRecipientInfoGenerator(
    // JceKeyTransRecipientInfoGenerator(X509Certificate,
    // 			    [org.bouncycastle.asn1.x509.AlgorithmIdentifier])
    new JceKeyTransRecipientInfoGenerator(cert).setProvider(SECURITY_PROVIDER));
      
              /* Encrypt the body part */
              MimeBodyPart encryptedPart =
    // encrypter.generate(bodyPart, getEncryptAlgorithm(), SECURITY_PROVIDER);  // Deprecated
    // encryptor.generate(MimeBodyPart, JceCMSContentEncryptorBuilder(
    //     org.bouncycastle.asn1.ANS1ObjectIdentifier, [int keySize])
    encrypter.generate(bodyPart,
		       new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(getEncryptAlgorithm()))
		       .setProvider(SECURITY_PROVIDER).build());
              return new SMimeMessage(encryptedPart, this);
          }
          catch (org.bouncycastle.mail.smime.SMIMEException ex) {
              throw new SMimeException(ex.getMessage(), ex.getUnderlyingException());
          }
      }
      catch (Exception e) {
          throw new SMimeException("Unable to encrypt body part", e);
      }
  }
 
开发者ID:cecid,项目名称:hermes,代码行数:44,代码来源:SMimeMessage.java

示例9: encrypt

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
private MimeBodyPart encrypt(MimeBodyPart bodyPart) throws Exception{
	 // Create Encrypter
       SMIMEEnvelopedGenerator encrypter = new SMIMEEnvelopedGenerator();
       encrypter.setContentTransferEncoding("base64");
encrypter.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(partnershipDVO.getEncryptX509Certificate())
				    .setProvider(SECURITY_PROVIDER));
	
       // Encrypt BodyPart
MimeBodyPart encryptedPart = encrypter.generate(bodyPart,
			       new JceCMSContentEncryptorBuilder(
				   new ASN1ObjectIdentifier(SMIMEEnvelopedGenerator.DES_EDE3_CBC))
			       .setProvider(SECURITY_PROVIDER).build());
       return encryptedPart;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:15,代码来源:IncomingMessageProcessorTest.java

示例10: encrypt

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
public void encrypt(X509Certificate cert, String encryptAlg) throws SFRMException {
      try {       	
          /* Create the encrypter */
          SMIMEEnvelopedGenerator encrypter = new SMIMEEnvelopedGenerator();
          encrypter.setContentTransferEncoding("binary");
   encrypter.addRecipientInfoGenerator(
new JceKeyTransRecipientInfoGenerator(cert).setProvider(SECURITY_PROVIDER));
  
          /* Encrypt the body part */
      	if (encryptAlg.equalsIgnoreCase(ALG_ENCRYPT_RC2))
    this.bodyPart = encrypter.generate(bodyPart,
		        new JceCMSContentEncryptorBuilder(
			    new ASN1ObjectIdentifier(SMIMEEnvelopedGenerator.RC2_CBC))
		        .setProvider(SECURITY_PROVIDER).build());
      	else if (encryptAlg.equalsIgnoreCase(ALG_ENCRYPT_3DES))
    this.bodyPart = encrypter.generate(bodyPart,
		        new JceCMSContentEncryptorBuilder(
			    new ASN1ObjectIdentifier(SMIMEEnvelopedGenerator.DES_EDE3_CBC))
		        .setProvider(SECURITY_PROVIDER).build());
      	else
      		throw new SFRMException("Encryption algorithm error - " + encryptAlg);
          
          this.setIsEncrypted(true);
          
      } catch (org.bouncycastle.mail.smime.SMIMEException ex) {
          throw new SFRMException("Unable to encrypt body part", ex.getUnderlyingException());
      } catch (Exception e) {
          throw new SFRMException("Unable to encrypt body part", e);
      }
  }
 
开发者ID:cecid,项目名称:hermes,代码行数:31,代码来源:SFRMMessage.java

示例11: testProofOfPossessionWithoutSender

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
public void testProofOfPossessionWithoutSender()
    throws Exception
{
    KeyPairGenerator kGen = KeyPairGenerator.getInstance("RSA", BC);

    kGen.initialize(512);

    KeyPair kp = kGen.generateKeyPair();
    X509Certificate cert = makeV1Certificate(kp, "CN=Test", kp, "CN=Test");

    JcaCertificateRequestMessageBuilder certReqBuild = new JcaCertificateRequestMessageBuilder(BigInteger.ONE);

    certReqBuild.setPublicKey(kp.getPublic())
                .setAuthInfoPKMAC(new PKMACBuilder(new JcePKMACValuesCalculator()), "fred".toCharArray())
                .setProofOfPossessionSigningKeySigner(new JcaContentSignerBuilder("SHA1withRSA").setProvider(BC).build(kp.getPrivate()));

    certReqBuild.addControl(new JcaPKIArchiveControlBuilder(kp.getPrivate(), new X500Principal("CN=test"))
                                  .addRecipientGenerator(new JceKeyTransRecipientInfoGenerator(cert).setProvider(BC))
                                  .build(new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(CMSEnvelopedDataGenerator.AES128_CBC)).setProvider(BC).build()));

    JcaCertificateRequestMessage certReqMsg = new JcaCertificateRequestMessage(certReqBuild.build().getEncoded());

    // check that internal check on popo signing is working okay
    try
    {
        certReqMsg.isValidSigningKeyPOP(new JcaContentVerifierProviderBuilder().setProvider(BC).build(kp.getPublic()));
        fail("IllegalStateException not thrown");
    }
    catch (IllegalStateException e)
    {
        // ignore
    }

    assertTrue(certReqMsg.isValidSigningKeyPOP(new JcaContentVerifierProviderBuilder().setProvider(BC).build(kp.getPublic()), new PKMACBuilder(new JcePKMACValuesCalculator().setProvider(BC)), "fred".toCharArray()));

    assertEquals(kp.getPublic(), certReqMsg.getPublicKey());
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:38,代码来源:AllTests.java

示例12: testProofOfPossessionWithSender

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
public void testProofOfPossessionWithSender()
    throws Exception
{
    KeyPairGenerator kGen = KeyPairGenerator.getInstance("RSA", BC);

    kGen.initialize(512);

    KeyPair kp = kGen.generateKeyPair();
    X509Certificate cert = makeV1Certificate(kp, "CN=Test", kp, "CN=Test");

    JcaCertificateRequestMessageBuilder certReqBuild = new JcaCertificateRequestMessageBuilder(BigInteger.ONE);

    certReqBuild.setPublicKey(kp.getPublic())
                .setAuthInfoSender(new X500Principal("CN=Test"))
                .setProofOfPossessionSigningKeySigner(new JcaContentSignerBuilder("SHA1withRSA").setProvider(BC).build(kp.getPrivate()));

    certReqBuild.addControl(new JcaPKIArchiveControlBuilder(kp.getPrivate(), new X500Principal("CN=test"))
                                  .addRecipientGenerator(new JceKeyTransRecipientInfoGenerator(cert).setProvider(BC))
                                  .build(new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(CMSEnvelopedDataGenerator.AES128_CBC)).setProvider(BC).build()));

    JcaCertificateRequestMessage certReqMsg = new JcaCertificateRequestMessage(certReqBuild.build().getEncoded());

    // check that internal check on popo signing is working okay
    try
    {
        certReqMsg.isValidSigningKeyPOP(new JcaContentVerifierProviderBuilder().setProvider(BC).build(kp.getPublic()), new PKMACBuilder(new JcePKMACValuesCalculator().setProvider(BC)), "fred".toCharArray());

        fail("IllegalStateException not thrown");
    }
    catch (IllegalStateException e)
    {
        // ignore
    }


    assertTrue(certReqMsg.isValidSigningKeyPOP(new JcaContentVerifierProviderBuilder().setProvider(BC).build(kp.getPublic())));

    assertEquals(kp.getPublic(), certReqMsg.getPublicKey());
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:40,代码来源:AllTests.java

示例13: testProofOfPossessionWithTemplate

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
public void testProofOfPossessionWithTemplate()
    throws Exception
{
    KeyPairGenerator kGen = KeyPairGenerator.getInstance("RSA", BC);

    kGen.initialize(512);

    KeyPair kp = kGen.generateKeyPair();
    X509Certificate cert = makeV1Certificate(kp, "CN=Test", kp, "CN=Test");

    JcaCertificateRequestMessageBuilder certReqBuild = new JcaCertificateRequestMessageBuilder(BigInteger.ONE);

    certReqBuild.setPublicKey(kp.getPublic())
                .setSubject(new X500Principal("CN=Test"))
                .setAuthInfoSender(new X500Principal("CN=Test"))
                .setProofOfPossessionSigningKeySigner(new JcaContentSignerBuilder("SHA1withRSA").setProvider(BC).build(kp.getPrivate()));

    certReqBuild.addControl(new JcaPKIArchiveControlBuilder(kp.getPrivate(), new X500Principal("CN=test"))
                                  .addRecipientGenerator(new JceKeyTransRecipientInfoGenerator(cert).setProvider(BC))
                                  .build(new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(CMSEnvelopedDataGenerator.AES128_CBC)).setProvider(BC).build()));

    JcaCertificateRequestMessage certReqMsg = new JcaCertificateRequestMessage(certReqBuild.build().getEncoded());

    assertTrue(certReqMsg.isValidSigningKeyPOP(new JcaContentVerifierProviderBuilder().setProvider(BC).build(kp.getPublic())));

    assertEquals(kp.getPublic(), certReqMsg.getPublicKey());
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:28,代码来源:AllTests.java

示例14: testKeyTrans128RC4

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
public void testKeyTrans128RC4()
    throws Exception
{
    byte[]          data     = "WallaWallaBouncyCastle".getBytes();

    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();

    edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));

    CMSEnvelopedData ed = edGen.generate(
                            new CMSProcessableByteArray(data),
                            new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier("1.2.840.113549.3.4"), 128).setProvider(BC).build());

    RecipientInformationStore  recipients = ed.getRecipientInfos();

    assertEquals(ed.getEncryptionAlgOID(), "1.2.840.113549.3.4");

    Collection  c = recipients.getRecipients();
    Iterator    it = c.iterator();

    if (it.hasNext())
    {
        RecipientInformation   recipient = (RecipientInformation)it.next();

        byte[] recData = recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC));

        assertEquals(true, Arrays.equals(data, recData));
    }
    else
    {
        fail("no recipient found");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:34,代码来源:NewEnvelopedDataTest.java

示例15: testKeyTransLight128RC4

import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; //导入依赖的package包/类
public void testKeyTransLight128RC4()
    throws Exception
{
    byte[]          data     = "WallaWallaBouncyCastle".getBytes();

    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();

    edGen.addRecipientInfoGenerator(new BcRSAKeyTransRecipientInfoGenerator(new JcaX509CertificateHolder(_reciCert)));

    CMSEnvelopedData ed = edGen.generate(
                            new CMSProcessableByteArray(data),
                            new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier("1.2.840.113549.3.4"), 128).setProvider(BC).build());

    RecipientInformationStore  recipients = ed.getRecipientInfos();

    assertEquals(ed.getEncryptionAlgOID(), "1.2.840.113549.3.4");

    Collection  c = recipients.getRecipients();
    Iterator    it = c.iterator();

    if (it.hasNext())
    {
        RecipientInformation   recipient = (RecipientInformation)it.next();

        byte[] recData = recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC));

        assertEquals(true, Arrays.equals(data, recData));
    }
    else
    {
        fail("no recipient found");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:34,代码来源:NewEnvelopedDataTest.java


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