将哈希值转换为十六进制字符串
在此页面上:
http://www.shutterfly.com/documentation/OflyCallSignature.sfly
它说一旦你生成了一个哈希值,你就会:
将哈希值转换为十六进制字符串
csharp 中有代码可以做到这一点吗?
on this page:
http://www.shutterfly.com/documentation/OflyCallSignature.sfly
it says once you generate a hash you then:
convert the hash to a hexadecimal character string
is there code in csharp to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要获取哈希值,请使用
System.Security .Cryptography.SHA1Managed
类。编辑:像这样:
要将哈希转换为十六进制字符串,请使用以下代码:
如果您想要更快的实现,请使用以下函数:
To get the hash, use the
System.Security.Cryptography.SHA1Managed
class.EDIT: Like this:
To convert the hash to a hex string, use the following code:
If you want a faster implementation, use the following function:
我还不能发表评论,没有足够的代表,但 Lior 将 Java 与 C# 混合在一起是一个非常错误的答案。C# 中的字节是无符号字节,这与所有其他整数类型完全相反在 C# 中,默认情况下是有签名的。
0xFF 部分完全没有意义,因为即使字节已签名,例如 0xFE 也是 -2。例如,使用按位与 0xFE 和 0xFF 不会阻止负数 0xFE 成为结果。 0x7F 会。关于最重要的答案,我很确定这些微优化可能会有所帮助,尽管它们是可能不会产生任何真正差异的微优化,因为 JIT 编译器可能只是做其他事情而且因为计算机速度太快了。
小改动使其使用位移位和按位运算而不是除法器和模数。
这是另一个“优化”,尽管我认为它更具可读性。也许那是因为我熟记了大部分 ASCII 表。
如果您想实现小写十六进制(不使用 ToLower),只需将 55 与 87 交换即可。这使得它非常简单。
更新:看起来 Lior 或某人删除了他非常不恰当的答案。这是一个很好的举动。
I can't comment yet, not enough rep, but Lior is mixing Java with C# in a very wrong answer.byte in C# is an unsigned byte, which is the complete opposite of all other whole number types in C#, which are signed by default.
The 0xFF part is completely pointless because even if byte was signed, 0xFE for example is -2. Using a bitwise-and with 0xFE and 0xFF, for example, would not stop negative number 0xFE from being the outcome. 0x7F would.Regarding the top answer, I'm pretty sure these micro-optimizations might help, albeit, they're micro-optimizations that are likely to not make any real difference because the JIT compiler might just do something else and because computers are just too blazing fast.
Small change to make it use bitshift and bitwise ops instead of the divider and modulo.
This is the other "optimization", although I see it as a more readable thing. Maybe that's because I know most of the ASCII table by heart.
If you're trying to achieve lower case hex (without ToLower), just swap 55 with 87. It makes it quite simple.
Update: It looks like Lior or someone removed his very off answer. That was a good move.