Hash data¶
Answers the hash of the body : an HMAC-SHA256, keyed with the nonce of the default secret (or its secret when there is no nonce). A text is hashed as it is, exactly like the hashing conversion of a schema hashes a column. So the hash of a tax id made here equals the one stored in the table, and finds the row.
In short
- Send a value, get its hash as a hex text.
- The same value and the same secret always give the same hash.
- Use it to look up a column that the schema stores hashed.
| Method | POST |
| URL | /api/system-api/admin/hash-data : admin is the user path of your account |
| Body | the value to hash : a string, or any JSON |
| Answer | data : the hash, a hex string |
| From code | g.sys.system.hash |
The call¶
Answer
{ "success": true, "statusCode": 200, "data": "be2a6a457cc36a48e4e231411d8d6498213f7ffb6d1e03066dd7fbaa6ec9402e" }
- The algorithm is
hashingAlgorithmof the secret :SHA256is the one supported. - The same value always gives the same hash for the same secret, which is the point : hash a value on the way in and compare hashes on the way out.
Look up a hashed column¶
Find the customer whose tax id (hashed in the table) is known
taxId := g.Req.Body().String("taxId")
digest, err := g.Sys.System.Hash(taxId)
if err != nil {
return nil, err
}
suppliers, err := g.Sys.Db.Query(am.Query{Instance: "mongodb", Database: "shop", Collection: "suppliers", Find: am.M{"tax_id_hash": digest}})
if err != nil {
return nil, err
}
- Keep an encrypted copy of the value in another field when you also need to read it back : encryption is reversible, hashing is not.
Access, headers and errors¶
- Over HTTP, a system API answers only once its settings open it :
TOKEN_ACCESS(the token of an API user whose group grants this system API) orIS_PUBLIC. Without settings it isNO_ACCESS: only your code (g.sys) and the admin panel reach it. - The settings can also keep the answer in the cache, or ask for the token of a person (
authProviders). Pre and post hooks run around it, as around any API. - It takes the request headers and answers the envelope.
401: no valid token, or the API isNO_ACCESS.403: no group grants it.400: the body is wrong, and the message names the key.
Related : All APIs · System API settings · System APIs from code