Created
February 20, 2021 14:43
-
-
Save ccondry/7f362acb66e4a73f4e25ce8689e72bb5 to your computer and use it in GitHub Desktop.
create a short alphanumeric hash using shake128
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto') | |
// create hash of user sub, and append it to the first 8 characters of the user sub | |
function getHash (sub) { | |
const hash = crypto | |
.createHash('shake128', {outputLength: 6}) | |
.update(sub, 'utf-8') | |
.digest('base64') | |
// you could remove this replace statement if you didn't want to alter the base64 or number of output characters | |
// this is here so that only alphanumerics are returned. but it does change the length of some hashes (consistently) | |
.replace('+', '') | |
return sub.split('@').shift().slice(0, 8) + hash | |
} | |
module.exports = getHash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
oh, it's for Node.js of course