Reputation: 15
I am try to write this stuff in c# asp.net 4 framework. I have a String variable called u. it is base64 encode of another string. now I need to decode it and get the original string, the problem is that decoding convert it to byte array.how can I convert it to string?
I tried Convert.FromBase64String(u).toString() but it didn't help :(
Upvotes: 1
Views: 8509
Reputation: 35881
Base-64 could be an encoding of anything. If you know it's an encoding of an ASCII string, you could do this:
var bytes = Convert.FromBase64String(u);
var text = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
If it's an encoding of a Unicode string (you weren't specific), you could do this:
var bytes = Convert.FromBase64String(u);
var text = System.Text.Encoding.Unicode.GetString(bytes, 0, bytes.Length);
Upvotes: 2