创建用户时 SHA2-512 上的哈希函数名称无效

问题描述 投票:0回答:2

尝试使用库“google.golang.org/api/admin/directory/v1”从 golang 创建用户

因为文档在这里很伤心https://developers.google.com/admin-sdk/directory/reference/rest/v1/users#User hashFunction 可以是 MD5、DES、SHA2-256、SHA2-512,所以我米写代码:

hash := sha512.Sum512([]byte("random password value))
encoded := hex.EncodeToString(hash[:])

payload := &admin.User{
    Password:     "$6$" + encoded,
    HashFunction: "SHA2-512"
}

结果:googleapi: Error 400: Invalid Hash Function Name, invalid

那么怎么理解,哈希函数名有什么问题?

google-admin-sdk google-directory-api
2个回答
1
投票

所以,我在这里 https://developers.google.com/resources/api-libraries/documentation/admin/directory_v1/python/latest/admin_directory_v1.users.html#insert 现在只支持 SHA-1, crypt 和 MD5,所以文档是错误的,对于 SHA2 哈希,使用字符串“crypt”作为 hashFunction 值并添加到密码对应的 crypt 前缀(例如对于 SHA2-512,将 $6$ 添加到十六进制编码值)


0
投票

对我来说,我还必须包含一个盐,以便后端接受密码(不确定这是否取决于域)。否则我在尝试调用 users.insert 时收到错误“googleapi:错误 400:无效密码,无效”。

例如,如果使用 SHA-256,则加密格式为:

$5$salt$hash

伪代码示例:

salt := "some random string"
password := "I'm a password <= 100 chars"
hash = sha256sum(passsword + salt)

crypt := "$5$" + hexEncode(salt) + "$" + hexEncode(password)

幻数

$5$
取决于使用的散列函数。

  • 对DES使用
    $1$
    ,或者MD5
  • 对 SHA-256 使用
    $5$
  • 使用
    $6$
    用于 SHA-512

然后将 hashFunction 设置为

crypt
.

来自:https://developers.google.com/admin-sdk/directory/reference/rest/v1/users#User

有关 c

crypt
lib 的更多信息(不要与同名的 Unix 实用程序混淆),以及可以测试的有效哈希示例:https://en.wikipedia.org/wiki/Crypt_%28C% 29

© www.soinside.com 2019 - 2024. All rights reserved.