Last active
August 11, 2020 13:34
-
-
Save dbwodlf3/6c0dda5ae82f07ad18665850c3977c1d to your computer and use it in GitHub Desktop.
JavaScript Code creating ID from time stamp with sha256
This file contains hidden or 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
| async function makeId(number){ | |
| let bitMask1 = 0xffffffffffffffffffffffffffffffff00000000000000000000000000000000; | |
| let bitMask2 = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff; | |
| let bitArray = new Uint32Array(2); | |
| bitArray[0] = bitMask1^number; | |
| bitArray[1] = bitMask2^number; | |
| let hashBuffer = await crypto.subtle.digest('sha-256',bitArray); | |
| let hashArray = Array.from(new Uint8Array(hashBuffer)); | |
| let id = hashArray.map(b => b.toString(16)).join(''); | |
| return id; | |
| } | |
| makeId(Date.now()).then((id)=>{console.log(id);}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment