Hello,

How can I encrypt message using RSA algorithm, I try do encrypt in that way:

public void encryptMessage(Document doc) throws WSSecurityException {

 WSSecEncrypt builder = new WSSecEncrypt();
builder.setUserInfo("myalias", "mykeypass");
builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
builder.setSymmetricEncAlgorithm(WSConstants.RSA);
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
/*
* Prepare the Encrypt object with the token, setup data structure
*/
builder.prepare(doc, crypto);
/*
 * Set up the parts structure to encrypt the body
 */
 SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc
                .getDocumentElement());
        Vector parts = new Vector();
        WSEncryptionPart encP = new WSEncryptionPart(soapConstants
                .getBodyQName().getLocalPart(), soapConstants.getEnvelopeURI
(),
                "Content");
        parts.add(encP);

        /*
         * Encrypt the parts (Body), create EncrypedData elements that
reference
         * the EncryptedKey, and get a ReferenceList that can be put into
the
         * Security header. Be sure that the ReferenceList is after the
         * EncryptedKey element in the Security header (strict layout)
         */
        Element refs = builder.encryptForExternalRef(null, parts);
        builder.addExternalRefElement(refs, secHeader);

        /*
         * now add (prepend) the EncryptedKey element, then a
         * BinarySecurityToken if one was setup during prepare
         */
        builder.prependToHeader(secHeader);

        builder.prependBSTElementToHeader(secHeader);
}

I catch following exception:
org.apache.ws.security.WSSecurityException: An unsupported signature or
encryption algorithm was used (unsupported key transport encryption
algorithm: No such algorithm: http://www.w3.org/2001/04/xmlenc#rsa-1_5)
    at org.apache.ws.security.util.WSSecurityUtil.getCipherInstance(
WSSecurityUtil.java:703)
    at org.apache.ws.security.message.WSSecEncryptedKey.prepareInternal(
WSSecEncryptedKey.java:189)
    at org.apache.ws.security.message.WSSecEncrypt.prepare(WSSecEncrypt.java
:216)
    at com.sabre.ssg.common.xml.wse.WSSecuritySample.encryptMessage(
WSSecuritySample.java:182)
    at com.sabre.ssg.common.xml.wse.WSSecuritySample.main(
WSSecuritySample.java:104)


My question is if there is no way to encrypt message with RSA using WSS4J?
What is more, if DES is supported by WSS4J?

Any help will be appreciated.

Regards,
Maciej

Reply via email to