Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8672215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:08:44+00:00 2026-06-12T19:08:44+00:00

I want to convert a SOAPMessage to a byte Array so i can encrypt

  • 0

I want to convert a SOAPMessage to a byte Array so i can encrypt it and then decrypt it in a proxy server that will make the Invoke of a Web service on my behalf.
The problem is that SOAPMessage does not implement java.io.Serializable and therefore I can’t proceed on the encryption of it.

I have used this for serializing

public static byte[] serializeSoapMessage (SOAPMessage sm){
    try {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        sm.writeTo(baos);
       byte[] bytes= baos.toByteArray();
       return bytes;
    } catch (SOAPException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

But deserialization is a problem because ObjectInputStream requires the implementation of java.io.Serializable

Thank you in regards 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:08:46+00:00Added an answer on June 12, 2026 at 7:08 pm

    I think you don’t quite understand what SOAPMessage.writeTo is doing (or how object streams work). As far as I can tell, writeTo will create the XML for the SOAPMessage and write it as bytes to the stream it’s given. To read it, you use a MessageFactory and its createMessage method. The information written to the stream isn’t an object (which is what ObjectInputStream expects), it’s data.

    To do what you want, wrap your ByteArrayOutputStream in a CipherOutputStream (see this question to see how to wrap streams with cipher streams) and call sm.writeTo(cipherOutputStream) instead. This will encrypt the bytes on the stream, and then you can send the bytes to your web service.

    Have the web service run the decryption by wrapping the bytes received in a ByteArrayInputStream and then wrapping that in a CipherInputStream. Give the resulting CipherInputStream to the MessageFactory and it will reconstruct the original SOAPMessage.

    Admittedly, I’m not an expert in web services, so I can’t give you working code for your specific solution, but this approach will definitely give you an encrypted byte[] to send that will contain the encrypted SOAPMessage.

    Note that the object streams don’t encrypt anything anyway. You may think so because its output is more or less unreadable, but it’s by no means encrypted. The only way to get encryption is to use, well, encryption.

    Some references for you:

    • Wrapping streams with cipher streams
    • MessageFactory
    • SOAPMessage.writeTo
    • CipherInputStream and CipherOutputStream
    • Lesson on cipher streams
    • Lesson on Cipher which is needed for cipher streams

    Hope that’s enough to get you started.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want convert image into byte array in php.actually i am accessing web service
I want convert a char array in C to jcharArray for the JNI-interface to
I want to convert a QGraphicsScene to a pixmap, so I can add it
I want to convert my web application prototype (PHP server side) to a C++
I want to convert a binary file to a string which could be then
I have a string array: array = ['123';'abc';'uvw']; I want convert it to a
I want convert an int into 2 bytes representing that int. Probably must use
I want to convert a number that is in PRTime format (a 64-bit integer
I want to convert string from koderesult into object, and then thie obj.result should
I have an number I want convert its format to xxx xxx xxx,xx (will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.