MySQL SHA2函数似乎无法正常工作 [英] MySQL SHA2 function does not appear to work

查看:452
本文介绍了MySQL SHA2函数似乎无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySql 5.5.32,尝试在业务层中的存储过程中重现一些代码,以便为使用sql的用户设置密码.看来SHA2函数有问题,但是也许我遗漏了一些东西:

I'm using MySql 5.5.32 and trying to reproduce some code in a stored procedure that we have in the business layer so I can set passwords for people using sql. It appears that there is something wrong with the SHA2 function though, but maybe I'm missing something:

SELECT length(SHA2("bob", 512))

返回128.不是64吗?

Returns 128. Shouldn't it be 64?

SELECT length(SHA2("bob", 256))

哪个返回64,所以看来我丢失了某些内容,或者SHA2中存在错误.有什么想法吗?

Which returns 64, so it appears that either I missing something, or there is a bug in SHA2. Any ideas?

推荐答案

注释是正确的,即使文档中说它返回二进制字符串,也返回十六进制编码字符串.要获得正确的长度,请使用:

Comment was correct, even though the docs say that it returns binary string, it returns hex encoded string. To get the correct length use:

SELECT length(unhex(SHA2("bob", 512)));

这篇关于MySQL SHA2函数似乎无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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