创建用户时,SHA2-512上的哈希功能名称无效

发布于 2025-01-18 06:07:33 字数 676 浏览 3 评论 0原文

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

作为Docs SAD在这里 https://developers.google.com/admin-sdk/directory/reference/reference/rest/rest/v1/users#user hashfunction可以是md5,可以是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:错误400:无效的哈希功能名称,无效

,如何理解,哈希函数名称有什么问题?

Trying to create user using from golang using library "google.golang.org/api/admin/directory/v1"

As docs sad here https://developers.google.com/admin-sdk/directory/reference/rest/v1/users#User hashFunction could be MD5, DES, SHA2-256, SHA2-512, so i'm writing code:

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

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

This results: googleapi: Error 400: Invalid Hash Function Name, invalid

So how to understand, whats wrong with hash function name ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诗化ㄋ丶相逢 2025-01-25 06:07:33

所以,我在这里找到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$ 转为十六进制编码值)

So, i found here https://developers.google.com/resources/api-libraries/documentation/admin/directory_v1/python/latest/admin_directory_v1.users.html#insert that right now only supported SHA-1, crypt and MD5, so documentation is wrong, and for SHA2 hashes use string "crypt" as hashFunction value and add to password corresponding crypt prefix ( for example for SHA2-512 add $6$ to hex encoded value )

寂寞陪衬 2025-01-25 06:07:33

对我来说,我还必须包含一个盐,以便后端接受密码(不确定这是否取决于域)。否则,在尝试调用 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$
  • 对 SHA-512 使用 $6$

然后 hashFunction 设置为 <代码>加密。

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

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

For me, I had to also include a salt, for the backend to accept the password (not sure if this is dependent on the domain). Otherwise I got the error "googleapi: Error 400: Invalid Password, invalid" when trying to call users.insert.

For example, if using SHA-256, the crypt format is:

$5$salt$hash

Pseudo-code example:

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

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

The magic number$5$ depends on the hash function used.

  • Use $1$ for DES, or MD5
  • Use $5$ for SHA-256
  • Use $6$ for SHA-512

Then the hashFunction is set to crypt.

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

More about the c crypt lib (not to be confused with the Unix utility of the same name), with valid hash examples that can be tested: https://en.wikipedia.org/wiki/Crypt_%28C%29

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文