title: How can I make a String Base64 Url Safe Java/Android?
body: <p>I've been trying for a while but I can't seem to get my string to be Url Safe no matter what I do:</p>
  
  <pre><code>Input: XwPp9xazJ0ku5CZnlmgAx2Dld8SHkAeT+d7yvxw=
  Desired Output: XwPp9xazJ0ku5CZnlmgAx2Dld8SHkAeT-d7yvxw
  </code></pre>
  
  <p>Essentially I want to apply some flags on my input string from <a href="https://developer.android.com/reference/android/util/Base64.html" rel="noreferrer">https://developer.android.com/reference/android/util/Base64.html</a>, namely <code>Base64.URL_SAFE</code>,<code>Base64.NO_PADDING</code> and <code>Base64.NO_WRAP</code>. However when I do:</p>
  
  <pre><code>String str = "XzbeW3jg9NYp6J0w2mTP4NLrTK06p1EDTnNG+KYhvyw=";
  
  byte[] encoded = Base64.encode(
          str.getBytes(), Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP);
  
  byte[] strBytes = Base64.decode(encoded, Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP);
  String decoded = new String(strBytes);
  
  //outputs original str "XzbeW3jg9NYp6J0w2mTP4NLrTK06p1EDTnNG+KYhvyw="
  System.out.println(decoded);
  </code></pre>
  
  <p>I am not sure why the url safe encoding isn't working here, is there something I"m doing wrong? Is there a way I can get my desired output (besides manually doing <code>String.replace()</code> and other string modifications?</p>