title: JAVA: 128-bit key to String problem and back
body: <p>I have created a SecretkeySpec object wich contains a 128 bit key.
  I would like to have this key in a String(this string needs to be put back in to the original key later), so i use Base64 encoding.</p>
  
  <p>This is how my key looks in raw format from the byte array into chars:</p>
  
  <pre><code>*P??? ?ukL|?~
  </code></pre>
  
  <p>So I take the bytes and encode it like this.</p>
  
  <pre><code>byte[] okay = Base64.encode(eF.getSpec().getEncoded());
  </code></pre>
  
  <p>Now when i translate it into chars i get:</p>
  
  <pre><code>S2xEa3Ara0o5blVGYTB3WkRIeUZmZz09DQo=
  </code></pre>
  
  <p>Now i want to have my key back restored to it's original format from the base64 encoded array.</p>
  
  <pre><code>String dkey = "S2xEa3Ara0o5blVGYTB3WkRIeUZmZz09DQo=";
  
  byte[] key = null;
  key = dKey.getBytes();
  key = Base64.decode(key);
  </code></pre>
  
  <p>Now when i check the result i get:</p>
  
  <pre><code>DKlDkp+kJ9nUFa0wZHyFfg==
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>*P??? ?ukL|?~ 
  </code></pre>
  
  <p>As you can see this is not the result i hoped to see.
  I surely made a novice mistake, and forgive me for that but i am relativaly new to programming.
  I would appreciate it if someone could give me a working example of transforming
  the 128 bit key to and from readable format, and perhaps an explanation where i went wrong with thinking.</p>
  
  <p>And i apologize for any spelling mistakes, English is not my native language.</p>
  
  <p>Thanks in advance</p>