title: Guid to Base64 in Java
body: <p>I am converting a Guid to Base64 in C# using the following code:</p>
  
  <pre><code>var id = Guid.Parse("be9f1bb6-5c8e-407d-85a3-d5ef31f21b4d");
  var base64=Convert.ToBase64String(id.ToByteArray());
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <blockquote>
    <p>thufvo5cfUCFo9XvMfIbTQ==</p>
  </blockquote>
  
  <p>When I try to do the same in Java using the following:</p>
  
  <pre><code>java.util.Base64.Encoder encoder=Base64.getEncoder();
  UUID uuid = UUID.fromString("be9f1bb6-5c8e-407d-85a3-d5ef31f21b4d");
  ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
  bb.putLong(uuid.getMostSignificantBits());
  bb.putLong(uuid.getLeastSignificantBits());
  encoder.encodeToString(bb.array());
  </code></pre>
  
  <p><strong>Different output</strong></p>
  
  <blockquote>
    <p>vp8btlyOQH2Fo9XvMfIbTQ==</p>
  </blockquote>
  
  <p>What I am doing wrong in my Java code? How can I get the same result I am getting using C#?</p>