Rev 76 | Rev 83 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 76 | Rev 82 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * UUID & MAC Utils |
4 | * UUID & MAC Utils |
5 | * Copyright 2017 - 2023 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2017 - 2024 Daniel Marschall, ViaThinkSoft |
6 | * Version 2023-11-10 |
6 | * Version 2024-03-09 |
7 | * |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | * you may not use this file except in compliance with the License. |
9 | * you may not use this file except in compliance with the License. |
10 | * You may obtain a copy of the License at |
10 | * You may obtain a copy of the License at |
11 | * |
11 | * |
Line 44... | Line 44... | ||
44 | <li><a href="#gen_uuid">Generate random and/or time-based UUIDs</a><ul> |
44 | <li><a href="#gen_uuid">Generate random and/or time-based UUIDs</a><ul> |
45 | <li><a href="#gen_uuidv7"><font color="green">New:</font> Generate Unix Epoch time-based (version 7) UUID</a></li> |
45 | <li><a href="#gen_uuidv7"><font color="green">New:</font> Generate Unix Epoch time-based (version 7) UUID</a></li> |
46 | <li><a href="#gen_uuidv6"><font color="green">New:</font> Generate reordered Gregorian time-based (version 6) UUID</a></li> |
46 | <li><a href="#gen_uuidv6"><font color="green">New:</font> Generate reordered Gregorian time-based (version 6) UUID</a></li> |
47 | <li><a href="#gen_uuidv4">Generate random (version 4) UUID</a></li> |
47 | <li><a href="#gen_uuidv4">Generate random (version 4) UUID</a></li> |
48 | <li><a href="#gen_uuidv1">Generate Gregorian time-based (version 1) UUID</a></li> |
48 | <li><a href="#gen_uuidv1">Generate Gregorian time-based (version 1) UUID</a></li> |
- | 49 | <li><a href="#gen_uuidv8_sqlserver"><font color="green">New:</font> Generate SQL server sortable time-based (version 8) UUID</a></li> |
|
49 | </ul></li> |
50 | </ul></li> |
50 | <li><a href="#gen_other_uuid">Generate other UUID types</a><ul> |
51 | <li><a href="#gen_other_uuid">Generate other UUID types</a><ul> |
51 | <li><a href="#gen_uuid_ncs">NCS (variant 0) UUID</a></li> |
52 | <li><a href="#gen_uuid_ncs">NCS (variant 0) UUID</a></li> |
52 | <li><a href="#gen_uuidv2">Generate DCE Security (version 2) UUID</a></li> |
53 | <li><a href="#gen_uuidv2">Generate DCE Security (version 2) UUID</a></li> |
53 | <li><a href="#gen_uuidv35">Generate name-based (version 3 / 5 / <font color="green">New: 8</font>) UUID</a></li> |
54 | <li><a href="#gen_uuidv35">Generate name-based (version 3 / 5 / <font color="green">New: 8</font>) UUID</a></li> |
Line 239... | Line 240... | ||
239 | <form method="GET" action="interprete_uuid.php"> |
240 | <form method="GET" action="interprete_uuid.php"> |
240 | <input type="hidden" name="version" value="1"> |
241 | <input type="hidden" name="version" value="1"> |
241 | <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Create and display another UUID"> |
242 | <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Create and display another UUID"> |
242 | </form> |
243 | </form> |
243 | 244 | ||
- | 245 | <h3 id="gen_uuidv8_sqlserver">Generate SQL server sortable time-based (version 8) UUID</h3> |
|
- | 246 | ||
- | 247 | <p><i>The sorting of SQL Server is rather confusing and incompatible with UUIDv6 and UUIDv7.<br> |
|
- | 248 | Therefore this method developed by <a href="https://www.hickelsoft.de/">HickelSOFT</a> |
|
- | 249 | generates UUID which are sortable by SQL Server.<br> |
|
- | 250 | Version 1: Resolution of 1 milliseconds, random part of 16 bits, local timezone, NOT UUIDv8 conform.<br> |
|
- | 251 | Version 2: Resolution of 1 milliseconds, random part of 18 bits, UTC time, UUIDv8 conform.</i><br> |
|
- | 252 | <a href="https://gist.github.com/danielmarschall/7fafd270a3bc107d38e8449ce7420c25">C# implementation</a> | |
|
- | 253 | <a href="https://github.com/danielmarschall/uuid_mac_utils/blob/master/includes/uuid_utils.inc.php">PHP implementation</a> |
|
- | 254 | </p> |
|
- | 255 | ||
- | 256 | <script> |
|
- | 257 | function show_uuidv8_sqlserver_info() { |
|
- | 258 | document.getElementById("uuidv8_sqlserver_info_button").style.display = "none"; |
|
- | 259 | document.getElementById("uuidv8_sqlserver_info").style.display = "block"; |
|
- | 260 | } |
|
- | 261 | </script> |
|
- | 262 | <p><a id="uuidv8_sqlserver_info_button" href="javascript:show_uuidv8_sqlserver_info()">Show format</a> |
|
- | 263 | <pre id="uuidv8_sqlserver_info" style="display:none">Version 2: Resolution of 1 milliseconds, random part of 18 bits, UTC time, UUIDv8 conform: |
|
- | 264 | - 16 bit Random data |
|
- | 265 | - 8 bit UTC Milliseconds transformed from 1000ms to 0..255 (hex encoded) |
|
- | 266 | - 8 bit UTC Seconds (hex encoded) |
|
- | 267 | - 16 bit UTC Minute of the day (1..1440, hex encoded) |
|
- | 268 | - 4 bit UUID version 8 |
|
- | 269 | - 12 bit UTC Day of the year (1..366, hex encoded) |
|
- | 270 | - 2 bit UUID Variant (0b10) |
|
- | 271 | - 2 bit Random data |
|
- | 272 | - 12 bit UTC Year (hex encoded) |
|
- | 273 | - 48 bit Signature "HICKEL" = 0x4849434B454C |
|
- | 274 | ||
- | 275 | Version 1: Resolution of 1 milliseconds, random part of 16 bits, local timezone, NOT UUIDv8 conform. |
|
- | 276 | - 16 bit Random data |
|
- | 277 | - 8 bit Generator's local timezone Milliseconds transformed from 1000ms to 0..255 (hex encoded) |
|
- | 278 | - 8 bit Generator's local timezone Seconds (BCD encoded) |
|
- | 279 | - 8 bit Generator's local timezone Minute (BCD encoded) |
|
- | 280 | - 8 bit Generator's local timezone Hour (BCD encoded) |
|
- | 281 | - 8 bit Generator's local timezone Day (BCD encoded) |
|
- | 282 | - 8 bit Generator's local timezone Month (BCD encoded) |
|
- | 283 | - 8 bit Generator's local timezone 2-digit year (BCD encoded) |
|
- | 284 | - 8 bit Generator's local timezone 2-digit century (BCD encoded) |
|
- | 285 | - 48 bit Signature 0x000000000000</pre></p> |
|
- | 286 | ||
- | 287 | <?php |
|
- | 288 | if (AUTO_NEW_UUIDS > 0) { /** @phpstan-ignore-line */ |
|
- | 289 | echo '<p>Here are '.AUTO_NEW_UUIDS.' UUIDs that were created just for you! (Reload the page to get more)</p>'; |
|
- | 290 | ||
- | 291 | echo '<pre>'; |
|
- | 292 | for ($i=0; $i<AUTO_NEW_UUIDS; $i++) { |
|
- | 293 | $uuid = gen_uuid_v8_sqlserver_sortable(); |
|
- | 294 | echo '<a href="interprete_uuid.php?uuid='.$uuid.'">'.$uuid.'</a><br>'; |
|
- | 295 | } |
|
- | 296 | echo '</pre>'; |
|
- | 297 | } |
|
- | 298 | ?> |
|
- | 299 | ||
- | 300 | <form method="GET" action="interprete_uuid.php"> |
|
- | 301 | <input type="hidden" name="version" value="8_sqlserver_v2"> |
|
- | 302 | <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Create and display another UUID (new version)"> |
|
- | 303 | </form><br> |
|
- | 304 | ||
- | 305 | <form method="GET" action="interprete_uuid.php"> |
|
- | 306 | <input type="hidden" name="version" value="8_sqlserver_v1"> |
|
- | 307 | <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Create and display another UUID (old version)"> |
|
- | 308 | </form> |
|
- | 309 | ||
- | 310 | ||
- | 311 | ||
244 | <h2 id="gen_other_uuid">Generate other UUID types</h2> |
312 | <h2 id="gen_other_uuid">Generate other UUID types</h2> |
245 | 313 | ||
246 | <p><i>The following types of UUIDs are less common and/or require special knowledge. Please only use the following |
314 | <p><i>The following types of UUIDs are less common and/or require special knowledge. Please only use the following |
247 | generators if you know what you are doing.</i></p> |
315 | generators if you know what you are doing.</i></p> |
248 | 316 | ||
Line 395... | Line 463... | ||
395 | if ($algo == 'shake128') $bits = 999; |
463 | if ($algo == 'shake128') $bits = 999; |
396 | else if ($algo == 'shake256') $bits = 999; |
464 | else if ($algo == 'shake256') $bits = 999; |
397 | else $bits = strlen(hash($algo, '', true)) * 8; |
465 | else $bits = strlen(hash($algo, '', true)) * 8; |
398 | if ($bits < 128) $friendlyName .= " (Small hash size! $bits bits)"; // <-- this is not described in Appendix C.2 |
466 | if ($bits < 128) $friendlyName .= " (Small hash size! $bits bits)"; // <-- this is not described in Appendix C.2 |
399 | 467 | ||
400 | $space = $algo; |
- | |
401 | $tmp[$friendlyName] = '<option value="8_namebased_'.$space.'">'.htmlentities($friendlyName).'</option>'; |
468 | $tmp[$friendlyName] = '<option value="8_namebased_'.$algo.'">'.htmlentities($friendlyName).'</option>'; |
402 | } |
469 | } |
403 | natsort($tmp); |
470 | natsort($tmp); |
404 | foreach ($tmp as $html) { |
471 | foreach ($tmp as $html) { |
405 | echo "\t\t$html\n"; |
472 | echo "\t\t$html\n"; |
406 | } |
473 | } |