正在解码windows phone中的base64字符串

本文关键字:中的 base64 字符串 phone windows 解码 | 更新日期: 2023-09-27 17:57:34

我得到一个包含base64字符串的Soap响应。我使用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);
  }

这是读取UTF函数

   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);
        }

和我的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;
        }

但是得到的值与在线解码器给出的结果略有不同。

我在这里错过了什么?

正在解码windows phone中的base64字符串

我不确定你想用BinaryReader做什么,但我要做的是来自base64数据的this is a dummy encoded base64 string

string data64 = "dGhpcyBpcyBhIGR1bW15IGVuY29kZWQgYmFzZTY0IHN0cmluZy4=";
var buf = Convert.FromBase64String(data64);
var str = Encoding.UTF8.GetString(buf);