title: Base64 encode gives different result on linux CentOS terminal and in Java
body: <p>I am trying to generate some random password on Linux CentOS and store it in database as base64. Password is 'KQ3h3dEN' and when I convert it with 'echo KQ3h3dEN | base64' as a result I will get 'S1EzaDNkRU4<strong>K</strong>'. 
  I have function in java: </p>
  
  <pre><code>public static String encode64Base(String stringToEncode)
  {
      byte[] encodedBytes = Base64.getEncoder().encode(stringToEncode.getBytes());
      String encodedString = new String(encodedBytes, "UTF-8");
  
      return encodedString;
  }
  </code></pre>
  
  <p>And result of encode64Base("KQ3h3dEN") is 'S1EzaDNkRU4='.</p>
  
  <p>So, it is adding "K" instead of "=" in this example. How to ensure that I will always get same result when using base64 on linux and base64 encoding in java? </p>
  
  <p>UPDATE: Updated question as I didn't noticed "K" at the end of linux encoded string. Also, here are few more examples:</p>
  
  <ul>
  <li>'echo KQ3h3dENa | base64' => result='S1EzaDNkRU5hCg==', but it should be 'S1EzaDNkRU5h'</li>
  <li>echo KQ3h3dENaa | base64' => result='S1EzaDNkRU5hYQo=', but it should be 'S1EzaDNkRU5hYQ=='</li>
  </ul>