google-admin-sdkgoogle-directory-api

Invalid Hash Function Name on SHA2-512 when creating user


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$" + encoded,
    HashFunction: "SHA2-512"
}

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

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


Solution

  • 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 )