是否有哈希算法在C#中产生64位的哈希大小? [英] Is there a hash algorithm that produces a hash size of 64 bits in C#?

查看:326
本文介绍了是否有哈希算法在C#中产生64位的哈希大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要基于可变长度字符串生成一个哈希值,该字符串可以存储在不超过16个字段中(由于供应商的要求).

I need to produce a Hash value based off of a variable length string that I can store within a field no longer than 16 (due to vendor requirements).

我正在将通过C#脚本转换传递的几个字符串连接在一起,以计算哈希值.我受供应商的文件规范的约束,因为哈希的输出不能超过16.

I am concatenating together several strings that are being passed through a C# script transformation in order to calculate the Hash. I am constrained by the vendor's file specification in that the output of the hash cannot be any longer than 16.

有人有什么建议吗?例如,MD5算法的字符串转换的长度为32.

Does anyone have any suggestions? As an example the string conversion of the MD5 algorith has a length of 32.

推荐答案

设计了具有密码功能的函数,以便您可以将输出截断为一定大小,并且被截断的哈希函数仍然是安全的密码哈希函数.例如,如果将SHA-512输出的前128位(16字节)应用于某些输入,则前128位是与其他128位密码散列一样强的密码散列.

The cryptographic has functions are designed such that you may truncate the output to some size and the truncated hash function remains a secure cryptographic hash function. For example, if you take the first 128 bits (16 bytes) of the output of SHA-512 applied to some input, then the first 128 bits are a cryptographic hash as strong as any other 128-bits cryptographic hash.

解决方案是选择一些加密哈希函数-SHA-256,SHA-384和SHA-512是不错的选择-和

The solution is to choose some cryptographic hash function - SHA-256, SHA-384, and SHA-512 are good choices - and truncate the output to 128 bits (16 bytes).

-编辑-

基于这样的注释,即哈希值在编码为ASCII时必须适合16个ASCI字符,

Based on the comment that the hash value must, when encoded to ASCII, fit within 16 ASCI characters, the solution is

  • 首先,选择一些加密哈希函数(SHA-2系列包括SHA-256,SHA-384和SHA-512)
  • 然后,将所选哈希函数的输出截断为96位(12个字节)-也就是说,保留哈希函数输出的前12个字节,并丢弃其余字节
  • 然后,将截断后的输出以base-64编码为16个ASCII字符(128位)
  • 有效地产生96位强的加密哈希.

这篇关于是否有哈希算法在C#中产生64位的哈希大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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