title: Encrypt Base64+XOR+UTF8 in JAVA, decrypt in C#
body: <p>I have simple encrypt function which takes string, convert it to bytes, xor it and apply base64.</p>
  
  <p>JAVA:</p>
  
  <pre><code>String key = "1234";
  public String encrypt(String plainText) throws Exception {
  
      byte [] input = plainText.getBytes("UTF8");
      byte [] output = new byte[input.length];
      for(int i=0; i&lt;input.length; i++)
          output[i] = ((byte)(input[i] ^ key.charAt(i % key.length())));
  
      String utf8 = new String(output);
      return Utils.encode(utf8); 
  }
  </code></pre>
  
  <p>Then I save it to a file and open it in another application in C# using this decrypting method:</p>
  
  <p>C#:</p>
  
  <pre><code>string key="1234";
  public string Decrypt(string CipherText)
  {
      var decoded = System.Convert.FromBase64String(CipherText);
      var dexored = xor(decoded, key);
      return Encoding.UTF8.GetString(dexored);
  }
  
  byte[] xor(byte[] text, string key)
  {
      byte[] res = new byte[text.Length];
  
      for (int c = 0; c &lt; text.Length; c++)
      {
          res[c] = (byte)((uint)text[c] ^ (uint)key[c % key.Length]);
      }
  
      return res;
  }
  </code></pre>
  
  <p>Problem is that accented characters like ěščřžýáí fail to decode.</p>
  
  <p>Do you have any idea how to determine from which part the problem comes from or how to find it out? Looks to me  that it has something to do with UTF-8.</p>
  
  <p>I don't need suggestions for a better encryption. I have already working AES but I want to switch to xored base64 due to performance issues.</p>
  
  <p>Thank you.</p>