[已解决] XML文件中的Base64值 [英] [Solved] Base64 Values in an XML File

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

问题描述

我正在解析XML文件,其值可能会或可能不会经过Base64编码.

我正在使用XmlReader读取XML文件,然后将其写回到输出文件中(在弄弄了某些元素的值之后).
如果输入文件是Base64编码的,则输出文件也需要同样.



a)首先要知道这些值是否是Base64编码的吗?

如果是的话...



b)在使用XmlReader类进行解析的过程中,读取编码后的值并将其更改为纯文本值吗?

c)根据输入文件是否相同,使用Base64编码或纯文本将值写回到输出中.

如果您可以将我引向有帮助的类或方法,那将是很好的.

解决方案

^ ]

确定字符串是否以64为基数编码 [ ^ ] 元数据.

对于base64转换,请使用System.Convert类,请参见 http://msdn.microsoft.com/en -us/library/system.convert.aspx [ ^ ].您可以使用其方法:<code> FromBase64CharArray,FromBase64StringToBase64CharArrayToBase64String.

—SA


I''m parsing an XML file and its values may or may not be Base64-encoded.

I''m reading an XML file with XmlReader and then writing it back out to an output file (after I''ve fiddled with the values of some of the elements).
If the input file was Base64-encoded, the output file needs to be as well.

How do I

a) tell if the values are Base64 encoded or not in the first place?

And if so...

How do I

b) Read the encoded value and change it into a plaintext value during parsing using an XmlReader class?

c) Write the value back out to the output either with Base64 encoding or plaintext, depending on whether the input file was the same.

If you could point me to a class or method that would help out that would be great.

Thanks.

解决方案

Converting Base64[^]

Determine If A String Is Base 64 Encoded[^]


It is theoretically impossible to tell if the data is Base64 or not. This format does not have any indicator of the format, and for a good reason. The whole idea of format detection is wrong and cannot be strictly implemented. In all cases, you need some meta-data.

For base64 conversions use the class System.Convert, see http://msdn.microsoft.com/en-us/library/system.convert.aspx[^]. You can use its methods: <code>FromBase64CharArray, FromBase64String, ToBase64CharArray, ToBase64String.

—SA


这篇关于[已解决] XML文件中的Base64值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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