在 C# 中将 base64 字符串转换为 long
您好,我使用以下代码生成了一些字符串:
private static string CalcHashCode(byte[] data)
{
MD5CryptoServiceProvider md5Provider = new MD5CryptoServiceProvider();
Byte[] hash = md5Provider.ComputeHash(data);
return Convert.ToBase64String(hash);
}
如何从编码的 Base64 字符串中获取唯一的 long,我的意思是相反的操作,然后将其转换为 long?
private long CalcLongFromHashCode(string base64Hashcode)
{
//TODO
}
提前致谢。
Hi I have some strings generated using the following code:
private static string CalcHashCode(byte[] data)
{
MD5CryptoServiceProvider md5Provider = new MD5CryptoServiceProvider();
Byte[] hash = md5Provider.ComputeHash(data);
return Convert.ToBase64String(hash);
}
How can I get a unique long from a encoded base64 string, I mean, the opposite operation, and then convert it to long?
private long CalcLongFromHashCode(string base64Hashcode)
{
//TODO
}
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法将 base-64 字符串转换为
long
(或者如果不合适,它可能会被截断,因为long
仅使用 8 个字节)...可以将其转换为字节数组(这是“相反”操作):
如果您的数组至少包含 8 个字节,那么您可以获得 long 值:
You can't convert a base-64 string to a
long
(or it might be truncated if it doesn't fit, aslong
uses only 8 bytes)...It's possible to convert it to a byte array (which is 'the opposite' operation):
If your array contains at least 8 bytes, then you could get your long value:
首先,将字符串转换为 byte[],
然后将字节数组转换为 long
正如前面提到的,您将得到截断。
相反方向:
示例:
First, convert the string to a byte[],
then convert the byte array to a long
As has been mentioned, you'll get truncation.
The opposite direction:
Examples: