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()
import * as crypto from "@web5/crypto/utils";
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).
The package is available here on npm.
Author : Kevin Kouomeu
I hope you enjoyed reading this, and I'm curious to hear if this tutorial helped you. Please let me know your thoughts below in the comments. Don't forget to subscribe to my newsletter to avoid missing my upcoming blog posts.
You can also find me here LinkedIn • Twitter • GitHub or Medium
I hope you enjoyed reading this, and I'm curious to hear if this tutorial helped you. Please let me know your thoughts below in the comments. Don't forget to subscribe to my newsletter to avoid missing my upcoming blog posts.
You can also find me here LinkedIn • Twitter • GitHub or Medium