Base64问题需要咨询 [英] Base64 Problem Need Advice

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

问题描述

我已经注意到有关base64的信息,每个文件的编号不像md5 sha1 sha512一样长,并且想知道为什么或是否有不同类型的base64


我感兴趣的base64代码的一个示例:

Gyt7rmUcoMHxLPcV8qJliPMciP0aXZ/nsK + Gf0gtwVs


因此,如果存在不止一种,那么这又是哪种base64?如何编码base64文件以使其采用这种格式?


我目前用来编码base64的代码是:

公共函数ConvertToBase64(ByVal输入为字符串)
返回Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(Input))
结束函数

I have noticed something about base64 and the number for each file is not the same length like md5 sha1 sha512 and was wondering why or if there are different types of base64


One example of the base64 code I am interested in:

Gyt7rmUcoMHxLPcV8qJliPMciP0aXZ/nsK+Gf0gtwVs


So once more what kind of base64 is this if there is more than one kind and how might I encode a files base64 to make it in this format?


the code Im currently using to encode base64 is:

Public Function ConvertToBase64(ByVal Input As String)
Return Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(Input))
End Function

推荐答案

Base64编码与MD5,SHA1或SHA512无关.您当然可以对哈希函数的结果进行编码,但不会显示任何可能会出现问题的代码.

但是,代码中的一行可能会造成问题.这正在使用System.Text.ASCIIEncoding.ASCII.此编码不支持.NET(以及或多或少的现代软件)所使用的Unicode.通常情况下,您会丢失字符串数据.我建议在所有情况下都使用System.Text.UTF8Encoding.

—SA
The Base64 encoding has nothing to do with MD5, SHA1 or SHA512. You can encode the result of hash function of course, but you don''t show any code which could be a problem.

One line in your code can create a problem though. This is using System.Text.ASCIIEncoding.ASCII. This encoding does not support Unicode which is used by .NET (and all more or less modern software). You loose string data, in general case. I would recommend using System.Text.UTF8Encoding in all cases.

—SA


这篇关于Base64问题需要咨询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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