Skip to content

Instantly share code, notes, and snippets.

@dmorrison
Created April 25, 2011 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmorrison/940532 to your computer and use it in GitHub Desktop.
Save dmorrison/940532 to your computer and use it in GitHub Desktop.
C# string to byte[] to base 64 string back to original string
var text = "foobar";
var bytes = Encoding.Unicode.GetBytes(text);
var base64String = Convert.ToBase64String(bytes);
var sameBytes = Convert.FromBase64String(base64String);
var sameText = Encoding.Unicode.GetString(bytes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment