In c# I can encode binary data by Encoding.UTF8.GetString() and later convert it back by binary = Encoding.UTF8.GetBytes().
No, because that isn't what a text encoding does.
A text encoding transforms arbitrary text to/from structured bytes (meaning: structured in the way defined by that encoding)
You have arbitrary bytes, not structured bytes. You should use base-64 (Convert.ToBase64String
/ Convert.FromBase64String
), which converts arbitrary bytes to/from a structured string - in this case, structured according to the rules of base-64.
byte[] orig = ...
string storeThis = Convert.ToBase64String(orig);
// ...
byte[] backAgain = Convert.FromBase64String(storeThis);