title: How to encode a Map<String,String> as Base64 string?
body: <p>i like to encode a java map of strings as a single base 64 encoded string. The encoded string will be transmitted to a remote endpoint and maybe manipulated by a not nice person. So the worst thing that should happen are invaild key,value-tuples, but should not bring any other security risks aside. </p>
  
  <p>Example:</p>
  
  <pre><code>Map&lt;String,String&gt; map = ...
  String encoded = Base64.encode(map);
  
  // somewhere else
  Map&lt;String,String&gt; map = Base64.decode(encoded);
  </code></pre>
  
  <p>Yes, must be Base64. <a href="http://xstream.codehaus.org/" rel="noreferrer">Not like that</a> <a href="http://java.sun.com/developer/technicalArticles/WebServices/jaxb/" rel="noreferrer">or that</a> <a href="http://www.google.com/search?q=java+binding+frameworks" rel="noreferrer">or any other of these</a>. Is there an existing lightweight solution (Single Utils-Class prefered) out there? Or do i have to create my own?</p>
  
  <p>Anything better than this?</p>
  
  <pre><code>// marshalling
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  ObjectOutputStream oos = new ObjectOutputStream(baos);
  oos.writeObject(map);
  oos.close();
  String encoded = new String(Base64.encodeBase64(baos.toByteArray()));
  
  // unmarshalling 
  byte[] decoded = Base64.decodeBase64(encoded.getBytes());
  ByteArrayInputStream bais = new ByteArrayInputStream(decoded);
  ObjectInputStream ois = new ObjectInputStream(bais);
  map = (Map&lt;String,String&gt;) ois.readObject();
  ois.close();
  </code></pre>
  
  <p>Thanks,</p>