Package org.apache.ws.security.message

Examples of org.apache.ws.security.message.WSEncryptBody


     */
    public void testSigningEncryptionIS3DES() throws Exception {
        SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope();
        SOAPEnvelope envelope = null;
       
        WSEncryptBody encrypt = new WSEncryptBody();
        encrypt.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e");
        encrypt.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
        encrypt.setSymmetricEncAlgorithm(WSConstants.TRIPLE_DES);

        WSSignEnvelope sign = new WSSignEnvelope();
        sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
        sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);

        log.info("Before Sign/Encryption....");
        Document doc = unsignedEnvelope.getAsDocument();
        Document signedDoc = sign.build(doc, crypto);
        Document encryptedSignedDoc = encrypt.build(signedDoc, crypto);
        /*
         * convert the resulting document into a message first. The toSOAPMessage()
         * method performs the necessary c14n call to properly set up the signed
         * document and convert it into a SOAP message. After that we extract it
         * as a document again for further processing.
View Full Code Here


     * @throws Exception Thrown when there is any problem in signing or verification
     */
    public void testEncryptionDecryptionRSA15() throws Exception {
        SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope();
        SOAPEnvelope envelope = null;
        WSEncryptBody builder = new WSEncryptBody();
        builder.setUserInfo("wss4jcert");
        builder.setKeyIdentifierType(WSConstants.X509_KEY_IDENTIFIER);
        Document doc = unsignedEnvelope.getAsDocument();
        log.info("Before Encryption Triple DES....");
        Document encryptedDoc = builder.build(doc, crypto);
        log.info("After Encryption Triple DES....");

        /*
         * convert the resulting document into a message first. The toSOAPMessage()
         * method performs the necessary c14n call to properly set up the signed
         * document and convert it into a SOAP message. Check that the contents can't
          * be read (cheching if we can find a specific substring). After that we extract it
         * as a document again for further processing.
         */

        Message encryptedMsg = (Message) AxisUtil.toSOAPMessage(encryptedDoc);
        if (log.isDebugEnabled()) {
            log.debug("Encrypted message, RSA-15 keytransport, 3DES:");
            XMLUtils.PrettyElementToWriter(encryptedMsg.getSOAPEnvelope().getAsDOM(), new PrintWriter(System.out));
        }
        String encryptedString = encryptedMsg.getSOAPPartAsString();
        assertTrue(encryptedString.indexOf("LogTestService2") == -1 ? true : false);
        encryptedDoc = encryptedMsg.getSOAPEnvelope().getAsDocument();
        verify(encryptedDoc);

        /*
         * second run, same Junit set up, but change encryption method,
         * key identification, encryption mode (Element now), and data to encrypt.
         * This tests if several runs of different algorithms on same builder/cipher
         * setup are ok.
         */
        message = getSOAPMessage(); // create fresh message envrionment
        builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
        builder.setSymmetricEncAlgorithm(WSConstants.AES_128);
        Vector parts = new Vector();
        WSEncryptionPart encP =
            new WSEncryptionPart("testMethod", "uri:LogTestService2", "Element");
        parts.add(encP);
        builder.setParts(parts);
        unsignedEnvelope = message.getSOAPEnvelope();
        doc = unsignedEnvelope.getAsDocument();
        log.info("Before Encryption AES 128/RSA-15....");
        encryptedDoc = builder.build(doc, crypto);
        log.info("After Encryption AES 128/RSA-15....");
        encryptedMsg = (Message) AxisUtil.toSOAPMessage(encryptedDoc);
        if (log.isDebugEnabled()) {
            log.debug("Encrypted message, RSA-15 keytransport, AES 128:");
            XMLUtils.PrettyElementToWriter(encryptedMsg.getSOAPEnvelope().getAsDOM(), new PrintWriter(System.out));
View Full Code Here

     * @throws Exception Thrown when there is any problem in signing or verification
     */
     public void testEncryptionDecryptionOAEP() throws Exception {
        SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope();
        SOAPEnvelope envelope = null;
        WSEncryptBody builder = new WSEncryptBody();
        builder.setUserInfo("wss4jcert");
        builder.setKeyIdentifierType(WSConstants.X509_KEY_IDENTIFIER);
        builder.setKeyEnc(WSConstants.KEYTRANSPORT_RSAOEP);
        Document doc = unsignedEnvelope.getAsDocument();
        log.info("Before Encryption Triple DES/RSA-OAEP....");
        Document encryptedDoc = builder.build(doc, crypto);
        log.info("After Encryption Triple DES/RSA-OAEP....");

        Message encryptedMsg = (Message) AxisUtil.toSOAPMessage(encryptedDoc);
        if (log.isDebugEnabled()) {
            log.debug("Encrypted message, RSA-OAEP keytransport, 3DES:");
View Full Code Here

     */
    public void testEMBED_SECURITY_TOKEN_REF() throws Exception {

        SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope();
        SOAPEnvelope envelope = null;
        WSEncryptBody wsEncrypt = new WSEncryptBody();

        //Get the message as document
        log.info("Before Encryption....");
        Document doc = unsignedEnvelope.getAsDocument();

        /* Step 1 :: Add a UserNameToken.
         * Step 2 :: Add an Id to it.
         * Step 3 :: Create a Reference to the UserNameToken.
         * Step 4 :: Setting necessary parameters in WSEncryptBody.
         * Step 5 :: Encrypt using the using the password of UserNameToken.
         */

        //Step 1
        String username = "Dimthu";
        String password = "Sri Lanka Sri Lanka UOM ";
        byte[] key = password.getBytes();

        WSSAddUsernameToken builder = new WSSAddUsernameToken("", false);
        builder.setPasswordType(WSConstants.PASSWORD_TEXT);
        builder.build(doc, username, password);

        //Step 2
        // I should add wsu:Id here but I am not adding it since
        Element usrEle =
            (Element) (doc
                .getElementsByTagNameNS(WSConstants.WSSE_NS, "UsernameToken")
                .item(0));
        String idValue = "1234";
        usrEle.setAttribute("Id", idValue);

        //Step 3 ::
        Reference ref = new Reference(WSSConfig.getDefaultWSConfig(), doc);
        ref.setURI("#" + idValue);
        ref.setValueType("UsernameToken");
        SecurityTokenReference secRef =
            new SecurityTokenReference(WSSConfig.getDefaultWSConfig(), doc);
        secRef.setReference(ref);

        // adding the namespace
        WSSecurityUtil.setNamespace(
            secRef.getElement(),
            WSConstants.WSSE_NS,
            WSConstants.WSSE_PREFIX);

        //Step 4 ::
        wsEncrypt.setKeyIdentifierType(WSConstants.EMBED_SECURITY_TOKEN_REF);
        wsEncrypt.setSecurityTokenReference(secRef);
        wsEncrypt.setKey(key);

        //Step 4 :: Encrypting using the key.
        Document encDoc = wsEncrypt.build(doc, crypto);

        /*
         * convert the resulting document into a message first. The toSOAPMessage()
         * mehtod performs the necessary c14n call to properly set up the signed
         * document and convert it into a SOAP message. After that we extract it
View Full Code Here

     */
    public void testSigningEncryptionIS3DES() throws Exception {
        SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope();
        SOAPEnvelope envelope = null;
       
        WSEncryptBody encrypt = new WSEncryptBody();
        encrypt.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e");
        encrypt.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
        encrypt.setSymmetricEncAlgorithm(WSConstants.TRIPLE_DES);

        WSSignEnvelope sign = new WSSignEnvelope();
        sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
        sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);

        log.info("Before Sign/Encryption....");
        Document doc = unsignedEnvelope.getAsDocument();
        Document signedDoc = sign.build(doc, crypto);
        Document encryptedSignedDoc = encrypt.build(signedDoc, crypto);
        /*
         * convert the resulting document into a message first. The toSOAPMessage()
         * method performs the necessary c14n call to properly set up the signed
         * document and convert it into a SOAP message. After that we extract it
         * as a document again for further processing.
View Full Code Here

     * @throws Exception Thrown when there is any problem in signing or verification
     */
    public void testEncryptionDecryptionRSA15() throws Exception {
        SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope();
        SOAPEnvelope envelope = null;
        WSEncryptBody builder = new WSEncryptBody();
        builder.setUserInfo("wss4jcert");
        builder.setKeyIdentifierType(WSConstants.X509_KEY_IDENTIFIER);
        Document doc = unsignedEnvelope.getAsDocument();
        log.info("Before Encryption Triple DES....");
        Document encryptedDoc = builder.build(doc, crypto);
        log.info("After Encryption Triple DES....");

        /*
         * convert the resulting document into a message first. The toSOAPMessage()
         * method performs the necessary c14n call to properly set up the signed
         * document and convert it into a SOAP message. Check that the contents can't
          * be read (cheching if we can find a specific substring). After that we extract it
         * as a document again for further processing.
         */

        Message encryptedMsg = (Message) SOAPUtil.toSOAPMessage(encryptedDoc);
        if (log.isDebugEnabled()) {
            log.debug("Encrypted message, RSA-15 keytransport, 3DES:");
            XMLUtils.PrettyElementToWriter(encryptedMsg.getSOAPEnvelope().getAsDOM(), new PrintWriter(System.out));
        }
        String encryptedString = encryptedMsg.getSOAPPartAsString();
        assertTrue(encryptedString.indexOf("LogTestService2") == -1 ? true : false);
        encryptedDoc = encryptedMsg.getSOAPEnvelope().getAsDocument();
        verify(encryptedDoc);

        /*
         * second run, same Junit set up, but change encryption method,
         * key identification, encryption mode (Element now), and data to encrypt.
         * This tests if several runs of different algorithms on same builder/cipher
         * setup are ok.
         */
        message = getSOAPMessage(); // create fresh message envrionment
        builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
        builder.setSymmetricEncAlgorithm(WSConstants.AES_128);
        Vector parts = new Vector();
        WSEncryptionPart encP =
            new WSEncryptionPart("testMethod", "uri:LogTestService2", "Element");
        parts.add(encP);
        builder.setParts(parts);
        unsignedEnvelope = message.getSOAPEnvelope();
        doc = unsignedEnvelope.getAsDocument();
        log.info("Before Encryption AES 128/RSA-15....");
        encryptedDoc = builder.build(doc, crypto);
        log.info("After Encryption AES 128/RSA-15....");
        encryptedMsg = (Message) SOAPUtil.toSOAPMessage(encryptedDoc);
        if (log.isDebugEnabled()) {
            log.debug("Encrypted message, RSA-15 keytransport, AES 128:");
            XMLUtils.PrettyElementToWriter(encryptedMsg.getSOAPEnvelope().getAsDOM(), new PrintWriter(System.out));
View Full Code Here

     * @throws Exception Thrown when there is any problem in signing or verification
     */
     public void testEncryptionDecryptionOAEP() throws Exception {
        SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope();
        SOAPEnvelope envelope = null;
        WSEncryptBody builder = new WSEncryptBody();
        builder.setUserInfo("wss4jcert");
        builder.setKeyIdentifierType(WSConstants.X509_KEY_IDENTIFIER);
        builder.setKeyEnc(WSConstants.KEYTRANSPORT_RSAOEP);
        Document doc = unsignedEnvelope.getAsDocument();
        log.info("Before Encryption Triple DES/RSA-OAEP....");
        Document encryptedDoc = builder.build(doc, crypto);
        log.info("After Encryption Triple DES/RSA-OAEP....");

        Message encryptedMsg = (Message) SOAPUtil.toSOAPMessage(encryptedDoc);
        if (log.isDebugEnabled()) {
            log.debug("Encrypted message, RSA-OAEP keytransport, 3DES:");
View Full Code Here

     *                   decryption, or verification
     */
    public void testSigningEncryptionEmbedded() throws Exception {
        SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope();
        SOAPEnvelope envelope = null;
        WSEncryptBody encrypt = new WSEncryptBody();
        WSSignEnvelope sign = new WSSignEnvelope();
       
        encrypt.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e");
        encrypt.setKeyIdentifierType(WSConstants.EMBEDDED_KEYNAME);
        encrypt.setKey(key);

        sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
        log.info("Before Encryption....");
        Document doc = unsignedEnvelope.getAsDocument();
        Document signedDoc = sign.build(doc, crypto);
        Document encryptedSignedDoc = encrypt.build(signedDoc, crypto);
        /*
         * convert the resulting document into a message first. The toSOAPMessage()
         * mehtod performs the necessary c14n call to properly set up the signed
         * document and convert it into a SOAP message. After that we extract it
         * as a document again for further processing.
View Full Code Here

     * @throws Exception Thrown when there is any problem in encryption or verification
     */
    public void testEncryptionEncryption() throws Exception {
        SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope();
        SOAPEnvelope envelope = null;
        WSEncryptBody encrypt = new WSEncryptBody();
        encrypt.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e");
        log.info("Before Encryption....");
        Document doc = unsignedEnvelope.getAsDocument();
        Document encryptedDoc = encrypt.build(doc, crypto);
        Document encryptedEncryptedDoc = encrypt.build(encryptedDoc, crypto);

        /*
         * convert the resulting document into a message first. The toSOAPMessage()
         * mehtod performs the necessary c14n call to properly set up the signed
         * document and convert it into a SOAP message. After that we extract it
View Full Code Here

     *                   decryption, or verification
     */
    public void testEncryptionSigning() throws Exception {
        SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope();
        SOAPEnvelope envelope = null;
        WSEncryptBody encrypt = new WSEncryptBody();
        WSSignEnvelope sign = new WSSignEnvelope();
        encrypt.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e");
        sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
        log.info("Before Encryption....");
        Document doc = unsignedEnvelope.getAsDocument();
        Document encryptedDoc = encrypt.build(doc, crypto);
        Document encryptedSignedDoc = sign.build(encryptedDoc, crypto);
        /*
         * convert the resulting document into a message first. The toSOAPMessage()
         * mehtod performs the necessary c14n call to properly set up the signed
         * document and convert it into a SOAP message. After that we extract it
View Full Code Here

TOP

Related Classes of org.apache.ws.security.message.WSEncryptBody

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.