title: Base64 Java encode and decode a string
body: <p>I want to encode a string into <code>base64</code> and transfer it through a socket and decode it back. </p>
  
  <p>But after decoding it gives different answer. </p>
  
  <p>Following is my code and result is "77+9x6s="</p>
  
  <pre><code>import javax.xml.bind.DatatypeConverter;
  
      public class f{
  
         public static void main(String a[]){
  
            String str = new String(DatatypeConverter.parseBase64Binary("user:123"));
            String res = DatatypeConverter.printBase64Binary(str.getBytes());
            System.out.println(res);
         }
      }
  </code></pre>
  
  <p>Any idea about how to implement this?</p>