创建用户时,SHA2-512上的哈希功能名称无效
尝试使用库使用库“ 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: "$6quot; + 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以,我在这里找到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 )
对我来说,我还必须包含一个盐,以便后端接受密码(不确定这是否取决于域)。否则,在尝试调用 users.insert 时,我收到错误“googleapi:错误 400:无效密码,无效”。
例如,如果使用 SHA-256,则加密格式为:
伪代码示例:
幻数
$5$
取决于所使用的哈希函数。$1$
,或 MD5$5$
$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%29For 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:
Pseudo-code example:
The magic number
$5$
depends on the hash function used.$1$
for DES, or MD5$5$
for SHA-256$6$
for SHA-512Then 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