Detect weather a string is Base64 encoded or not?

polaris · · 249 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>So i am trying to figure out some why to detect if data downloaded from a website using Get is base64 encoded or not. How could i do this in Go?</p> <hr/>**评论:**<br/><br/>TheMerovius: <pre><p><a href="http://play.golang.org/p/RnEBFCJ9h0" rel="nofollow">Try to decode it. If it error&#39;s, it&#39;s invalid.</a></p></pre>unique10983240197249: <pre><p>This seems to be the pretty straightforward Go way of doing things.</p></pre>captncraig: <pre><p>perhaps a regex match for valid base 64 chars (alphanumeric, <code>+</code> and <code>/</code>.Whether or not it means anything is up to you from there.</p> <p>You could also try to decode with the base64 package. If the input contains invalid base64 chars it will return an error. </p> <p>Why are you downloading unknown data?</p></pre>IntellectualReserve: <pre><p>Link to the data/website?</p></pre>bo-banane: <pre><p>I&#39;d go for http headers, or doesn&#39;t the server tell you what it&#39;s sending? Not sure if there&#39;s a content transfer encoding header in http as there is in mail.</p> <p>I&#39;m on mobile, so sorry if this doesn&#39;t actually exist.</p></pre>martingxx: <pre><p>The last 2 bits of every byte will be zero.</p></pre>anacrolix: <pre><p>I think you mean the 2 most significant bits, and it isn&#39;t true anyway. Recommend you look up base64 it&#39;s worth being familiar with it.</p></pre>uncle_bad_touches: <pre><p>Check the Content-Transfer-Encoding header. It should indicate base64 encoding or not.</p></pre>
249 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传