How to Generate a UUID in Your Expo App

DavidDavid November 15, 2026 7 min read
A smartphone lying on a walnut desk beside a ring of brass keys and a steel combination padlock, with a sheet of printed dots behind them in warm morning light
Original image, App Store Launch Club

How to generate a UUID in your Expo app, in short

Run npx expo install expo-crypto. In any file, import * as Crypto from 'expo-crypto' and call const id = Crypto.randomUUID(). You get a version 4 UUID string, generated from cryptographically secure random values. The call is synchronous, so you can use it inline when you create an object, with no await and no loading state.

expo-crypto does more than UUIDs. It is the module you reach for whenever an app needs randomness you can trust, a hash of some data, or simple AES encryption. The table below is the whole API in one place.

expo-crypto at a glance (SDK 58)

QuestionAnswer
Installnpx expo install expo-crypto
PlatformsAndroid, iOS, tvOS and web
Works in Expo Go?Yes
Generate a UUIDCrypto.randomUUID() (version 4, synchronous)
Hash a stringCrypto.digestStringAsync(algorithm, text)
Hash bytesCrypto.digest(algorithm, typedArray)
Random bytesgetRandomBytesAsync(n), getRandomBytes(n) or getRandomValues(array)
Encrypt and decryptaesEncryptAsync and aesDecryptAsync with an AESEncryptionKey (AES-GCM)

When you actually need a UUID

A UUID is an ID you can create on the phone without asking a server for one, and still be confident it will not clash with any other ID. That makes it the right default in a few common situations in indie apps.

Where a client-side UUID fits

SituationUse randomUUID?Why
Records created offline, synced laterYesThe ID exists before the server ever sees the record, so nothing has to be renamed on sync
Rows in a local SQLite databaseYesSafe to merge across devices, unlike auto-increment numbers
Idempotency key for a purchase or form submitYesLets your backend ignore a retried request it already handled
File names for photos or exports you saveYesNo collisions when two files are saved in the same second
Short codes users type or read aloudNo36 characters is too long. Generate a short code from random bytes instead
Session tokens or passwordsNoIssue those on your server. Do not mint auth secrets on the client

Step 1: Install expo-crypto

Run npx expo install expo-crypto. On SDK 58 that installs the 58.0.x line, matched to your SDK, which is why you use expo install rather than plain npm install. The module is included in Expo Go, needs no config plugin and asks for no permissions, so you can try everything in this guide on your phone right away.

If you are unsure whether a module needs a development build, our [Expo Go vs development build](/blog/expo-go-vs-development-build) guide explains how to tell.

Step 2: Generate a UUID with randomUUID

Call Crypto.randomUUID() wherever you create a new thing. A typical pattern is a small helper, for example const newNote = (text: string) => ({ id: Crypto.randomUUID(), text, createdAt: Date.now() }), so every note gets its ID at birth rather than after a save.

  • It returns a plain string, so it stores cleanly in SQLite, AsyncStorage, Supabase or any JSON payload.
  • It follows the version 4 UUID format, the standard UUID format, so it fits a uuid column in Postgres or Supabase.
  • Generate the ID once and keep it. Do not call randomUUID inside render or a list key prop, or every render creates a new ID and React treats every row as new.
  • You do not need the separate uuid npm package for this. Leaving it out means one fewer dependency to keep compatible with your SDK.

Step 3: Hash a string with digestStringAsync

A hash turns any input into a short fixed-length fingerprint. The same input always gives the same hash, and you cannot get the input back from it. Use it to check whether some content changed, to build a cache key from a long URL, or to compare a value without keeping the original around.

Call const hash = await Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, text). By default the result is a hex string. Pass { encoding: Crypto.CryptoEncoding.BASE64 } as the third argument if you want base64 instead. To hash bytes rather than text, use Crypto.digest(algorithm, typedArray), which resolves to an ArrayBuffer.

Which hash algorithm to pick

AlgorithmPlatformsUse it?
SHA-256AllYes, the default choice. Collision resistant
SHA-384, SHA-512AllFine when a protocol asks for them. Also collision resistant
SHA-1AllOnly to match an older system that requires it
MD5Android and iOSOnly for legacy checksums, never for anything security related
MD2, MD4iOS onlyNo

Step 4: Get secure random bytes

When you need randomness that is not a UUID, such as a short invite code, a nonce or a salt, expo-crypto gives you three ways to get it.

  • await Crypto.getRandomBytesAsync(16) returns a Uint8Array of 16 secure random bytes. This is the safest default.
  • Crypto.getRandomBytes(16) does the same synchronously. It falls back to Math.random during development, so do not judge its output from a debug session, and prefer the async version for anything that matters.
  • Crypto.getRandomValues(new Uint8Array(16)) fills an existing typed array in place, the same shape as the web standard, which helps when a library expects that API.
  • getRandomBytes and getRandomBytesAsync accept a byte count from 0 to 1024. Anything outside that range throws a TypeError.

For a short human-friendly code, take the random bytes and map each one onto an alphabet that skips look-alike characters such as 0 and O or 1 and l. Ask Claude Code to do that mapping without modulo bias, which is a common slip in quick implementations.

Step 5: Encrypt and decrypt data with AES

Current expo-crypto also does AES-GCM encryption, which is what you want when data has to be stored privately and read back later, such as a cached file of sensitive notes. A hash cannot do this, because a hash is one way.

  1. Create a key with const key = await AESEncryptionKey.generate(). It defaults to 256 bits. You can pass 128 or 192, but 192 is not supported on web.
  2. Encrypt with const sealed = await aesEncryptAsync(plaintext, key). Plaintext can be a Uint8Array, or a string, but a string must already be base64 encoded. Passing raw text is the most common mistake here.
  3. Turn the result into something you can store with await sealed.combined('base64'), which packs the IV, ciphertext and authentication tag together. Without the argument you get bytes.
  4. To read it back, rebuild it with AESSealedData.fromCombined(stored) and call await aesDecryptAsync(sealed, key). You get bytes by default, or pass { output: 'base64' }.
  5. Save the key with await key.encoded('hex') and restore it with await AESEncryptionKey.import(hex, 'hex'). Defaults are a 12-byte IV and a 16-byte tag, and on Apple platforms the tag is always 16 bytes.

Have Claude Code build it for you

Open your project in the Claude Code desktop app and describe the result you want. Left alone, AI-written code here often installs the uuid package plus a polyfill you do not need, builds IDs from Math.random, calls randomUUID inside render, picks MD5 for hashing, or passes plain text to aesEncryptAsync. A prompt that heads those off:

Then add a line to your [CLAUDE.md](/blog/claude-md-for-expo-apps) such as "IDs: always newId() from src/lib/ids.ts (expo-crypto randomUUID), never Math.random, hashes are SHA-256" so later sessions keep following the rule.

The short version

To generate a UUID in your Expo app: install expo-crypto and call Crypto.randomUUID() when you create a record. Use digestStringAsync with SHA-256 when you need a fingerprint, getRandomBytesAsync when you need raw randomness, and aesEncryptAsync with a key kept in SecureStore when you need data back later. Drop Math.random from anything that has to be unique or secret.

If you are building your first iOS app with Claude Code and Expo and want a second set of eyes before App Review, bring it to App Store Launch Club. Members share their builds and help each other get unstuck, and the [curriculum](/curriculum) covers the full path from first build to first users. If you are protecting sensitive screens too, our guide to [preventing screenshots](/blog/how-to-prevent-screenshots-in-your-expo-app) pairs well with this one. Join at applaunchclub.co for $9 a month.

Free app-building tips, straight to your inbox

Short, practical drops on app ideas, validating fast, store listings, and passing app review. No spam, unsubscribe anytime.

Frequently asked questions

How do I generate a UUID in an Expo app?

Install expo-crypto with npx expo install expo-crypto, import * as Crypto from 'expo-crypto' and call Crypto.randomUUID(). It returns a version 4 UUID string synchronously, built from cryptographically secure random values.

Does expo-crypto work in Expo Go?

Yes. It is included in Expo Go and runs on Android, iOS, tvOS and web, with no config plugin and no permissions.

Do I need the uuid package in an Expo app?

No. Crypto.randomUUID() from expo-crypto generates version 4 UUIDs on its own, so you can skip adding the uuid package and any random values polyfill to your project.

How do I hash a string with SHA-256 in Expo?

Call await Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, text). It returns a hex string by default. Pass { encoding: Crypto.CryptoEncoding.BASE64 } as the third argument for base64.

Can expo-crypto encrypt data?

Yes. It supports AES-GCM through AESEncryptionKey, aesEncryptAsync and aesDecryptAsync. String plaintext must be base64 encoded first, and the key should be stored in expo-secure-store, never next to the encrypted data.

Why does digestStringAsync throw on web?

On web, hashing only works from a secure origin, meaning https or localhost. Serve the web build over https and the error goes away.

Last reviewed by David on November 15, 2026

David

Written by

David

Founder and app builder

Keep reading

ExpoClaude Code

How to Add Notification Actions to Your Expo App

To add notification actions to an Expo app, register a category with Notifications.setNotificationCategoryAsync, give it action buttons (and optionally a text reply), set categoryIdentifier on the notification, then read response.actionIdentifier in a response listener. Here is every action option, how to handle taps when the app was closed, the Android and iOS differences, and a Claude Code prompt that wires it all up.

David 8 min
Read article
ExpoClaude Code

How to Schedule Local Notifications in Your Expo App

To schedule local notifications in an Expo app, install expo-notifications, set a notification handler, ask for permission, create an Android channel, then call scheduleNotificationAsync with your content and a trigger like DAILY, WEEKLY or DATE. Here is every trigger type, how to cancel and list what is scheduled, why Android reminders arrive late, and a Claude Code prompt that builds the whole reminder flow.

David 8 min
Read article

Ready to build it yourself?

Join App Store Launch Club, the #1 community for building and launching apps, for $9/month.

← Back to the blog