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


Java WSEncryptionPart类代码示例

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


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

示例1: encryptSoapBodyPayload

import org.apache.wss4j.common.WSEncryptionPart; //导入依赖的package包/类
@Nonnull
public Document encryptSoapBodyPayload (@Nonnull final ESOAPVersion eSOAPVersion,
                                        @Nonnull final Document aDoc,
                                        final boolean bMustUnderstand,
                                        @Nonnull final ECryptoAlgorithmCrypt eCryptAlgo) throws Exception
{
  ValueEnforcer.notNull (eSOAPVersion, "SOAPVersion");
  ValueEnforcer.notNull (aDoc, "XMLDoc");
  ValueEnforcer.notNull (eCryptAlgo, "CryptAlgo");

  final CryptoProperties aCryptoProps = m_aCryptoFactory.getCryptoProperties ();

  final WSSecHeader aSecHeader = new WSSecHeader (aDoc);
  aSecHeader.insertSecurityHeader ();

  final WSSecEncrypt aBuilder = new WSSecEncrypt (aSecHeader);
  aBuilder.setKeyIdentifierType (WSConstants.BST_DIRECT_REFERENCE);
  aBuilder.setSymmetricEncAlgorithm (eCryptAlgo.getAlgorithmURI ());
  aBuilder.setUserInfo (aCryptoProps.getKeyAlias (), aCryptoProps.getKeyPassword ());
  aBuilder.getParts ().add (new WSEncryptionPart ("Body", eSOAPVersion.getNamespaceURI (), "Content"));
  final Attr aMustUnderstand = aSecHeader.getSecurityHeaderElement ()
                                         .getAttributeNodeNS (eSOAPVersion.getNamespaceURI (), "mustUnderstand");
  if (aMustUnderstand != null)
    aMustUnderstand.setValue (eSOAPVersion.getMustUnderstandValue (bMustUnderstand));
  return aBuilder.build (m_aCryptoFactory.getCrypto ());
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:27,代码来源:EncryptionCreator.java

示例2: testEncryptionDecryptionAES128GCM

import org.apache.wss4j.common.WSEncryptionPart; //导入依赖的package包/类
/**
 * Test that encrypt and decrypt a WS-Security envelope. This test uses the
 * RSA_15 algorithm to transport (wrap) the symmetric key.
 * <p/>
 *
 * @throws Exception
 *         Thrown when there is any problem in signing or verification
 */
@Test
public void testEncryptionDecryptionAES128GCM () throws Exception
{
  final Document doc = _getSoapEnvelope11 ();
  final WSSecHeader secHeader = new WSSecHeader (doc);
  secHeader.insertSecurityHeader ();

  final WSSecEncrypt aBuilder = new WSSecEncrypt (secHeader);
  aBuilder.setKeyIdentifierType (WSConstants.ISSUER_SERIAL);
  aBuilder.setSymmetricEncAlgorithm (ECryptoAlgorithmCrypt.AES_128_GCM.getAlgorithmURI ());
  aBuilder.setSymmetricKey (null);
  aBuilder.setUserInfo (m_aCryptoProperties.getKeyAlias (), m_aCryptoProperties.getKeyPassword ());

  // final WSEncryptionPart encP = new WSEncryptionPart ("Messaging",
  // "http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/",
  // "Element");
  final WSEncryptionPart encP = new WSEncryptionPart ("Body", ESOAPVersion.SOAP_11.getNamespaceURI (), "Element");
  aBuilder.getParts ().add (encP);

  LOG.info ("Before Encryption AES 128/RSA-15....");
  final Document encryptedDoc = aBuilder.build (m_aCrypto);
  LOG.info ("After Encryption AES 128/RSA-15....");
  final String outputString = XMLUtils.prettyDocumentToString (encryptedDoc);

  assertFalse (outputString.contains ("counter_port_type"));
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:35,代码来源:EncryptionTest.java

示例3: getPart

import org.apache.wss4j.common.WSEncryptionPart; //导入依赖的package包/类
public WSEncryptionPart getPart() {
    WSEncryptionPart part = new WSEncryptionPart(getName(), getNamespace(), getModifier());
    part.setRequired(false); // treat as optional
    return part;
}
 
开发者ID:tilln,项目名称:jmeter-wssecurity,代码行数:6,代码来源:SecurityPart.java

示例4: createSignedMessage

import org.apache.wss4j.common.WSEncryptionPart; //导入依赖的package包/类
/**
 * This method must be used if the message does not contain attachments, that
 * should be in a additional mime message part.
 *
 * @param aPreSigningMessage
 *        SOAP Document before signing
 * @param eSOAPVersion
 *        SOAP version to use
 * @param aAttachments
 *        Optional list of attachments
 * @param aResMgr
 *        Resource manager to be used.
 * @param bMustUnderstand
 *        Must understand?
 * @param eCryptoAlgorithmSign
 *        Signing algorithm
 * @param eCryptoAlgorithmSignDigest
 *        Signing digest algorithm
 * @return The created signed SOAP document
 * @throws WSSecurityException
 *         If an error occurs during signing
 */
@Nonnull
public static Document createSignedMessage (@Nonnull final AS4CryptoFactory aCryptoFactory,
                                            @Nonnull final Document aPreSigningMessage,
                                            @Nonnull final ESOAPVersion eSOAPVersion,
                                            @Nullable final ICommonsList <WSS4JAttachment> aAttachments,
                                            @Nonnull final AS4ResourceManager aResMgr,
                                            final boolean bMustUnderstand,
                                            @Nonnull final ECryptoAlgorithmSign eCryptoAlgorithmSign,
                                            @Nonnull final ECryptoAlgorithmSignDigest eCryptoAlgorithmSignDigest) throws WSSecurityException
{
  ValueEnforcer.notNull (aCryptoFactory, "CryptoFactory");
  ValueEnforcer.notNull (aPreSigningMessage, "PreSigningMessage");
  ValueEnforcer.notNull (eSOAPVersion, "SOAPVersion");
  ValueEnforcer.notNull (aResMgr, "ResMgr");
  ValueEnforcer.notNull (eCryptoAlgorithmSign, "CryptoAlgorithmSign");
  ValueEnforcer.notNull (eCryptoAlgorithmSignDigest, "CryptoAlgorithmSignDigest");

  // Start signing the document
  final WSSecHeader aSecHeader = new WSSecHeader (aPreSigningMessage);
  aSecHeader.insertSecurityHeader ();

  final CryptoProperties aCryptoProps = aCryptoFactory.getCryptoProperties ();

  final WSSecSignature aBuilder = new WSSecSignature (aSecHeader);
  aBuilder.setUserInfo (aCryptoProps.getKeyAlias (), aCryptoProps.getKeyPassword ());
  aBuilder.setKeyIdentifierType (WSConstants.BST_DIRECT_REFERENCE);
  aBuilder.setSignatureAlgorithm (eCryptoAlgorithmSign.getAlgorithmURI ());
  // PMode indicates the DigestAlgorithm as Hash Function
  aBuilder.setDigestAlgo (eCryptoAlgorithmSignDigest.getAlgorithmURI ());

  if (CollectionHelper.isNotEmpty (aAttachments))
  {
    // Modify builder for attachments
    aBuilder.getParts ().add (new WSEncryptionPart ("Body", eSOAPVersion.getNamespaceURI (), "Content"));
    // XXX where is this ID used????
    aBuilder.getParts ().add (new WSEncryptionPart (UserMessageCreator.PREFIX_CID + "Attachments", "Content"));

    final WSS4JAttachmentCallbackHandler aAttachmentCallbackHandler = new WSS4JAttachmentCallbackHandler (aAttachments,
                                                                                                          aResMgr);
    aBuilder.setAttachmentCallbackHandler (aAttachmentCallbackHandler);
  }

  // Set the mustUnderstand header of the wsse:Security element as well
  final Attr aMustUnderstand = aSecHeader.getSecurityHeaderElement ()
                                         .getAttributeNodeNS (eSOAPVersion.getNamespaceURI (), "mustUnderstand");
  if (aMustUnderstand != null)
    aMustUnderstand.setValue (eSOAPVersion.getMustUnderstandValue (bMustUnderstand));

  return aBuilder.build (aCryptoFactory.getCrypto ());
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:73,代码来源:SignedMessageCreator.java

示例5: encryptMimeMessage

import org.apache.wss4j.common.WSEncryptionPart; //导入依赖的package包/类
@Nonnull
public MimeMessage encryptMimeMessage (@Nonnull final ESOAPVersion eSOAPVersion,
                                       @Nonnull final Document aDoc,
                                       final boolean bMustUnderstand,
                                       @Nullable final ICommonsList <WSS4JAttachment> aAttachments,
                                       @Nonnull final AS4ResourceManager aResMgr,
                                       @Nonnull final ECryptoAlgorithmCrypt eCryptAlgo) throws WSSecurityException,
                                                                                        MessagingException
{
  ValueEnforcer.notNull (eSOAPVersion, "SOAPVersion");
  ValueEnforcer.notNull (aDoc, "XMLDoc");

  final CryptoProperties aCryptoProps = m_aCryptoFactory.getCryptoProperties ();

  final WSSecHeader aSecHeader = new WSSecHeader (aDoc);
  aSecHeader.insertSecurityHeader ();

  final WSSecEncrypt aBuilder = new WSSecEncrypt (aSecHeader);
  aBuilder.setKeyIdentifierType (WSConstants.ISSUER_SERIAL);
  aBuilder.setSymmetricEncAlgorithm (eCryptAlgo.getAlgorithmURI ());
  aBuilder.setSymmetricKey (null);
  aBuilder.setUserInfo (aCryptoProps.getKeyAlias (), aCryptoProps.getKeyPassword ());
  aBuilder.getParts ().add (new WSEncryptionPart (UserMessageCreator.PREFIX_CID + "Attachments", "Content"));

  WSS4JAttachmentCallbackHandler aAttachmentCallbackHandler = null;
  if (CollectionHelper.isNotEmpty (aAttachments))
  {
    aAttachmentCallbackHandler = new WSS4JAttachmentCallbackHandler (aAttachments, aResMgr);
    aBuilder.setAttachmentCallbackHandler (aAttachmentCallbackHandler);
  }

  final Attr aMustUnderstand = aSecHeader.getSecurityHeaderElement ()
                                         .getAttributeNodeNS (eSOAPVersion.getNamespaceURI (), "mustUnderstand");
  if (aMustUnderstand != null)
    aMustUnderstand.setValue (eSOAPVersion.getMustUnderstandValue (bMustUnderstand));

  // Main sign and/or encrypt
  final Document aEncryptedDoc = aBuilder.build (m_aCryptoFactory.getCrypto ());

  // The attachment callback handler contains the encrypted attachments
  // Important: read the attachment stream only once!
  ICommonsList <WSS4JAttachment> aEncryptedAttachments = null;
  if (aAttachmentCallbackHandler != null)
  {
    aEncryptedAttachments = aAttachmentCallbackHandler.getAllResponseAttachments ();
    // MIME Type and CTE must be set for encrypted attachments!
    aEncryptedAttachments.forEach (x -> {
      x.overwriteMimeType (CMimeType.APPLICATION_OCTET_STREAM.getAsString ());
      x.setContentTransferEncoding (EContentTransferEncoding.BINARY);
    });
  }

  // Use the encrypted attachments!
  return MimeMessageCreator.generateMimeMessage (eSOAPVersion, aEncryptedDoc, aEncryptedAttachments);
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:56,代码来源:EncryptionCreator.java


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