散列密码有时超过 128 个字符

Hashed password sometimes longer than 128 characters

我遇到了一个奇怪的安全相关问题,最近我在尝试在 nvarchar(130) 的 SQL 服务器数据库字段中插入哈希密码时遇到了规律但间歇性的错误:

<cfqueryparam value="#hashpass#" cfsqltype="cf_sql_char" maxLength="130">

hashpass 变量是这样设置的:

<cfset hashpass =  Hash(arguments.password & getsalt.user_salt, "SHA-512")>

想知道 SHA-512 哈希怎么可能超过 128 个字符,而文档却说它应该始终正好是 128?这是 ColdFusion 10 错误:

[Macromedia][SQL服务器 JDBC 驱动程序][SQL服务器]字符串或二进制数据将被截断。

从您的错误看来,问题出在数据库级别,因为 ColdFusion 没有让您对 cfqueryparam 标记的 maxlength 检查失败,并且允许执行查询。我刚刚测试过尝试传递一个超过 maxlength 属性(在 CF10 上)中指定的长度的字符串并得到错误:

The cause of this output exception was that: 
coldfusion.tagext.sql.QueryParamTag$InvalidDataException: 
Invalid data value this-is-a-string-that-is-too-long exceeds maxlength setting 10..`

正如问题评论中提到的 Adam Cameron,似乎是您查询中的另一个字段引发了错误。

由于散列密码的长度为 128 个字符 - 您验证 130 个字符是否有原因?