org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient.setProvider()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient.setProvider()方法的一些代码示例,展示了JceKeyTransEnvelopedRecipient.setProvider()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JceKeyTransEnvelopedRecipient.setProvider()方法的具体详情如下:
包路径:org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient
类名称:JceKeyTransEnvelopedRecipient
方法名:setProvider

JceKeyTransEnvelopedRecipient.setProvider介绍

暂无

代码示例

代码示例来源:origin: itext/itext7

/**
 * Gets the content from a recipient.
 */
public static byte[] getContent(RecipientInformation recipientInfo, PrivateKey certificateKey, String certificateKeyProvider) throws CMSException {
  Recipient jceKeyTransRecipient = new JceKeyTransEnvelopedRecipient(certificateKey).setProvider(certificateKeyProvider);
  return recipientInfo.getContent(jceKeyTransRecipient);
}

代码示例来源:origin: com.itextpdf/itextpdf

/**
   * Gets the content from a recipient.
   * @param recipientInfo
   * @param certificateKey
   * @param certificateKeyProvider
   * @return
   * @throws CMSException
   */
  public static byte[] getContent(RecipientInformation recipientInfo, PrivateKey certificateKey, String certificateKeyProvider) throws CMSException {
     Recipient jceKeyTransRecipient = new JceKeyTransEnvelopedRecipient(certificateKey).setProvider(certificateKeyProvider);
    return recipientInfo.getContent(jceKeyTransRecipient);
  }
}

代码示例来源:origin: no.difi.commons/commons-asic

@Override
public void writeFile(OutputStream outputStream) throws IOException {
  if (currentFile.endsWith(".p7m")) {
    try {
      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
      asicReader.writeFile(byteArrayOutputStream);
      CMSEnvelopedDataParser cmsEnvelopedDataParser = new CMSEnvelopedDataParser(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
      // expect exactly one recipient
      Collection<?> recipients = cmsEnvelopedDataParser.getRecipientInfos().getRecipients();
      if (recipients.size() != 1)
        throw new IllegalArgumentException();
      // retrieve recipient and decode it
      RecipientInformation recipient = (RecipientInformation) recipients.iterator().next();
      byte[] decryptedData = recipient.getContent(new JceKeyTransEnvelopedRecipient(privateKey).setProvider(BC));
      ByteStreams.copy(new ByteArrayInputStream(decryptedData), outputStream);
    } catch (Exception e) {
      throw new IOException(e.getMessage(), e);
    }
  } else {
    asicReader.writeFile(outputStream);
  }
}

代码示例来源:origin: com.helger/ph-asic

public void writeFile (final OutputStream aOS) throws IOException
{
 if (m_sCurrentFile.endsWith (".p7m"))
 {
  try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ())
  {
   m_aAsicReader.writeFile (aBAOS);
   final CMSEnvelopedDataParser aCMSEnvelopedDataParser = new CMSEnvelopedDataParser (aBAOS.getAsInputStream ());
   // expect exactly one recipient
   final Collection <RecipientInformation> aRecipients = aCMSEnvelopedDataParser.getRecipientInfos ()
                                          .getRecipients ();
   if (aRecipients.size () != 1)
    throw new IllegalArgumentException ("Found not exactly one recipient but " + aRecipients.size ());
   // retrieve recipient and decode it
   final RecipientInformation aRecipientInfo = aRecipients.iterator ().next ();
   final byte [] aDecryptedData = aRecipientInfo.getContent (new JceKeyTransEnvelopedRecipient (m_aPrivateKey).setProvider (PBCProvider.getProvider ()));
   AsicUtils.copyStream (new NonBlockingByteArrayInputStream (aDecryptedData), aOS);
  }
  catch (final CMSException e)
  {
   throw new IOException (e.getMessage (), e);
  }
 }
 else
 {
  m_aAsicReader.writeFile (aOS);
 }
}

代码示例来源:origin: phax/as2-lib

if (bLargeFileOn)
 aDecryptedDataBodyPart = SMIMEUtil.toMimeBodyPart (aRecipient.getContentStream (new JceKeyTransEnvelopedRecipient (aPrivateKey).setProvider (m_sSecurityProviderName)));
 final byte [] aDecryptedData = aRecipient.getContent (new JceKeyTransEnvelopedRecipient (aPrivateKey).setProvider (m_sSecurityProviderName));
 if (s_aDumpDecryptedDirectory != null)

代码示例来源:origin: com.axway.ats.framework/ats-actionlibrary

RecipientInformation recipient = recipients.get(recId);
PrivateKey privateKey = (PrivateKey) ks.getKey(aliasOrCN, certPassword.toCharArray());
JceKeyTransRecipient jceKey = new JceKeyTransEnvelopedRecipient(privateKey).setProvider(BouncyCastleProvider.PROVIDER_NAME);

代码示例来源:origin: com.github.librepdf/openpdf

public static byte[] getEnvelopedData(PdfArray recipients, List<PdfObject> strings, Certificate certificate, Key certificateKey, String certificateKeyProvider) {
    byte[] envelopedData = null;
    for (PdfObject recipient : recipients.getElements()) {
      strings.remove(recipient);
      try {
        CMSEnvelopedData data = new CMSEnvelopedData(recipient.getBytes());

        final Collection<RecipientInformation> recipientInformations = data.getRecipientInfos().getRecipients();
        for (RecipientInformation recipientInfo : recipientInformations) {
          if (recipientInfo.getRID().match(certificate)) {
            // OJO...
            // https://www.bouncycastle.org/docs/pkixdocs1.5on/org/bouncycastle/cms/CMSEnvelopedData.html
            Recipient rec = new JceKeyTransEnvelopedRecipient(
                (PrivateKey) certificateKey)
                .setProvider(certificateKeyProvider);
            envelopedData = recipientInfo.getContent(rec);
            // ******************************************************************************
            break;
          }

        }
      } catch (Exception f) {
        throw new ExceptionConverter(f);
      }
    }
    return envelopedData;
  }
}

代码示例来源:origin: org.nhind/agent

recip.setProvider(CryptoExtensions.getJCESensitiveProviderName());
recip.setContentProvider(CryptoExtensions.getJCEProviderName());

相关文章

微信公众号

最新文章

更多