Realibly检查,如果一个字符串的base64 EN codeD上的.Net [英] Realibly checking if a string is base64 encoded in .Net

查看:177
本文介绍了Realibly检查,如果一个字符串的base64 EN codeD上的.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我开始:是的,我检查了其他的问题和答案对这个话题都在这里和其他地方。

Before I start: Yes, I have checked the other questions and answers on this topic both here and elsewhere.

我已经找到了一个例子串了.NET将Base64的德,即使它实际上不是Base64的EN codeD code。下面是例子:

I have found an example string that the .Net will base64 decode even though it isn't actually base64 encoded. Here is the example:

雷诺考特水64mcg /剂喷鼻剂

在.NET方法,当解码这个字符串,所以我IsBase64En codeD方法愉快地为这个字符串返回true Convert.FromBase64String不会抛出异常。

The .Net method Convert.FromBase64String does not throw an exception when decoding this string so my IsBase64Encoded method happily returns true for this string.

有趣的是,如果我用用这个字符串作为输入的cygwin的base64 -d命令时,出现该消息的输入无效的。

Interestingly, if I use the cygwin base64 -d command using this string as input, it fails with the message invalid input.

更有趣的是,我认为源属于这个可执行文件( http://libb64.sourceforge.net/ )德codeS这一相同的字符串具有相同的结果,因为我从.NET Convert.FromBase64String得到。我将继续寻找,希望找到线索,但在其他地方,现在我很为难。

Even more interestingly, the source that I thought that belongs to this executable (http://libb64.sourceforge.net/) "decodes" this same string with the same result as I am getting from the .Net Convert.FromBase64String. I will keep looking hoping to find a clue elsewhere but right now I'm stumped.

任何想法?

推荐答案

有豆蔻更好的解决方案,这也检查输入字符串lenght。
我建议你​​做检查的beggining当输入为null或空则返回false

http://www.$c$cproject.com/Questions/177808/How-to-determine-if-a-string-is-Base-de$c$cd-or

There is litte better solution, which check also input string lenght.
I recommend you do check at beggining if input is null or empty then return false

http://www.codeproject.com/Questions/177808/How-to-determine-if-a-string-is-Base-decoded-or

这篇关于Realibly检查,如果一个字符串的base64 EN codeD上的.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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