从BASE64字符串转换为长期在C# [英] Convert from base64 string to long in C#
本文介绍了从BASE64字符串转换为长期在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我有使用以下code产生了一些字符串:
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);
}
我怎样才能得到一个独特的长从EN codeD的base64字符串,我的意思是,相反的操作,然后将其转换为长?
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
}
先谢谢了。
推荐答案
您不能一个base-64字符串转换为长
(或它可能会被截断,如果它不适合,因为长
仅用8个字节)...
You can't convert a base-64 string to a long
(or it might be truncated if it doesn't fit, as long
uses only 8 bytes)...
这是可能将其转换为字节数组(这是'的相反的'操作):
It's possible to convert it to a byte array (which is 'the opposite' operation):
byte[] hash = new byte[] { 65, 66, 67, 68, 69 };
string string64 = Convert.ToBase64String(hash);
byte[] array = Convert.FromBase64String(string64);
如果您的数组包含至少8个字节,那么你可以让你长值:
If your array contains at least 8 bytes, then you could get your long value:
long longValue = BitConverter.ToInt64(array, 0);
这篇关于从BASE64字符串转换为长期在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文