In this bog post, I want to show you how to generate a UUID easily using the crypto interface, and why it's important in secure contexts.
What is crypto Interface
The Crypto
interface represents basic cryptography features available in the current context. It allows access to a cryptographically strong random number generator and to cryptographic primitives.
How to generate UUID
To generate a UUID with the crypto interface, you need to use the randomUUID()
const uuid = crypto.randomUUID();
console.log(uuid); // Output "36b8f84d-df4e-4d49-b662-bcde71a8764f"
More
You should avoid using the Web Crypto API in insecure contexts, even though the Crypto
interface is present in insecure contexts, as is the crypto property. In addition, the method randomUUID()
is only available on secure contexts (HTTPS and localhost).
🔍. Similar posts
How to Add a Binary Folder Path to the PATH Environment Variable on macOS Using Vim
22 Jan 2025
The Simple Way to Run a Long Docker Command in Multiline
14 Jan 2025
How to Hard Reset Your Git Repository to 10 Minutes Ago
04 Sep 2024