1

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 :(

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.