[英]Decoding a base64 string from windows phone
i am getting a Soap response which contains a base64 string. 我收到一个包含base64字符串的Soap响应。 I am using XDocument to get the value of the element and a function like this to read it
我正在使用XDocument获取元素的值和类似这样的函数来读取它
public void main()
{
//****UPDATE
string data64 = "";
data64 = removeNewLinesFromString(data64);
content = data64.ToCharArray();
byte[] binaryData = Convert.FromBase64CharArray(content, 0, content.Length);
Stream stream = new MemoryStream(binaryData);
BinaryReader reader = new BinaryReader(stream,Encoding.UTF8);
string object64 = SoapSerializable.ReadUTF(reader);
}
this is the readUTF function 这是readUTF函数
public static String ReadUTF(BinaryReader reader)
{
// read the following string's length in bytes
int length = Helpers.FlipInt32(reader.ReadInt32());
// read the string's data bytes
byte[] utfString = reader.ReadBytes(length);
// get the string by interpreting the read data as UTF-8
return System.Text.Encoding.UTF8.GetString(utfString, 0, utfString.Length);
}
and my FlipInt32 function 和我的FlipInt32函数
public static Int32 FlipInt32(Int32 value)
{
Int32 a = (value >> 24) & 0xFF;
Int32 b = (value >> 16) & 0xFF;
Int32 c = (value >> 8) & 0xFF;
Int32 d = (value >> 0) & 0xFF;
return (((((d << 8) | c) << 8) | b) << 8) | a;
}
but the resulting values are slightly different from the results an online decoder gives. 但是结果值与在线解码器给出的结果略有不同。
I am missing something here? 我在这里想念什么吗?
I am not sure what you are trying to do with BinaryReader
But here is what I do to get this is a dummy encoded base64 string
from your base64 data 我不确定您要使用
BinaryReader
做什么,但是我要做的this is a dummy encoded base64 string
从您的base64数据中得到this is a dummy encoded base64 string
string data64 = "dGhpcyBpcyBhIGR1bW15IGVuY29kZWQgYmFzZTY0IHN0cmluZy4=";
var buf = Convert.FromBase64String(data64);
var str = Encoding.UTF8.GetString(buf);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.