Skip to content

Instantly share code, notes, and snippets.

@thisisone
Created August 4, 2014 12:03
Show Gist options
  • Save thisisone/030535f1b740d4ece7ab to your computer and use it in GitHub Desktop.
Save thisisone/030535f1b740d4ece7ab to your computer and use it in GitHub Desktop.
try
{
// JAVA : string -> base64
{
String text = "한글";
byte[] data = text.getBytes("UTF-8");
String base64 = Base64.encodeToString(data, Base64.DEFAULT);
Log.d("Unity", "base64="+base64);
}
// JAVA : base64 -> string
{
String base64 = "YWJjZGVmZw==";
byte[] data = base64.getBytes("UTF-8");
data = Base64.decode(data, Base64.DEFAULT);
String text = new String(data, "UTF-8");
Log.d("Unity", "text="+text);
}
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
{
// C# : base64 -> string
string text = "7ZWc6riA";
byte[] data = System.Convert.FromBase64String(text);
string decode_base64 = System.Text.Encoding.UTF8.GetString(data);
Debug.LogError("decode_base64="+decode_base64);
// C# : base64 -> string
text = decode_base64;
data = System.Text.Encoding.UTF8.GetBytes(text);
string encode_base64 = System.Convert.ToBase64String(data);
Debug.LogError("encode_base64="+encode_base64);
}
@maryfrancislopez
Copy link

maryfrancislopez commented Jun 21, 2018

which Jar are you referring to in java when you say Base64.encodeToString
since i see syntax change when i use Apache Library.
or are you using the util one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment