Вопрос

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

Это было полезно?

Решение

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);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top