从Base64编码在C#中的解码 [英] Decoding from Base64 in C#

查看:1131
本文介绍了从Base64编码在C#中的解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建XML文档,并保存这个文件为

I created XML Document and saved this document as

  XmlDocument xmlDoc = new XmlDocument();
  XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
  xmlDoc.AppendChild(dec);
  XmlTextWriter writer = new XmlTextWriter(fullPath,Encoding.UTF8);
  writer.Formatting = Formatting.Indented;
  xMLDoc.Save(writer);
  writer.Flush();

然后,我都设有codeD Base64编码使用恩codeR这个文件

And then I have encoded this document using Base64 Encoder

这De codeR无法解析XML文件。
我创建了德codeR自己,得到这个结果。

The Decoder could not parse XML file. I created the decoder myself and got this result

 ?<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<ClinicalDocument 
 xmlns=\"urn:hl7-org:v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
classCode=\"DOCCLIN\" moodCode=\"EVN\" schemaLocation=\"urn:hl7-org:v3
CDA.xsd\">\r\n  <typeId extension=\"POCD_HD000040\" root=\"2.16.840.1.113883.1.3
\" />\r\n

请帮我解决这个问题。
我怎么也得保存XML文件,以避免这些问题?
或者,我怎么也得带code至64基地来解决问题?
我使用Base64 EN codeR为en code xml文件。
我请求文件。它是需要使用的base64 EN $ C $铬。
我去codeD自己来检查哪里出了问题。
去codeR就是Java。他们不能解析xml文件,我相信,因为&LT?;在该文件的前面

Please help me to resolve the issue. How I have to save the XML file to avoid the issues? Or How I have to encode to Base 64 to resolve the issue? I am using base64 encoder to encode xml file. I am requesting document. it is required to use base64 encoder. I decoded myself to check where is the problem. The decoder is Java . They can not parse the xml file I believe because ?< in front of the document.

推荐答案

这取决于你是如何编码,但你应该使用UTF-8,因为该文件被宣布为。下面是用于编码和解码的例子:

It depends on how you're encoding it, but you should use UTF-8 since the document is declared as such. Here are examples for encoding and decoding:

请参阅乔恩斯基特的答案在这里:

<一href=\"http://stackoverflow.com/questions/1957987/c-base64-encoding-decoding-with-serialization-of-objects-issue\">C# base64编码/使用对象问题的系列化解码

See Jon Skeet's answer here:
C# base64 encoding/decoding with serialization of objects issue

要带code:

public string EncodeStringToBase64(string stringToEncode)
{
    return Convert.ToBase64String(Encoding.UTF8.GetBytes(stringToEncode));
}

要取消code:

public string DecodeStringFromBase64(string stringToDecode)
{       
    return Encoding.UTF8.GetString(Convert.FromBase64String(stringToDecode));
}

这篇关于从Base64编码在C#中的解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆