Skip to main content

expo-crypto

Version: 55.0.6 Provides cryptography primitives for Android, iOS and web. Supports digest algorithms, random value generation, and CryptoDigestAlgorithm for secure hashing.

Installation

Usage

API Reference

Methods

(algorithm: CryptoDigestAlgorithm, data: string, options?: CryptoDigestOptions) => Promise<string>
Generates a digest hash of the provided stringParameters:
  • algorithm: Hash algorithm to use
  • data: String to hash
  • options: Optional encoding format
(algorithm: CryptoDigestAlgorithm, data: TypedArray) => Promise<TypedArray>
Generates a digest hash of typed array data
(byteCount: number) => Promise<Uint8Array>
Generates cryptographically secure random bytes
(byteCount: number) => Uint8Array
Synchronous version of getRandomBytesAsync
() => string
Generates a random UUID (v4)

Enums

CryptoDigestAlgorithm

CryptoEncoding

Examples

Hash Password

Verify Password

Generate Random Token

Hash File Content

Generate UUID for Records

Hash with Different Algorithms

Generate Secure Random String

Create HMAC-like Hash

Complete Example

Platform Support

Algorithm Support

MD5, SHA-1, MD2, and MD4 are cryptographically broken and should not be used for security purposes. Use SHA-256 or higher for secure applications.

Use Cases

  • Password Hashing: Hash passwords before storage (use with salt)
  • Data Integrity: Verify file/data hasn’t been tampered with
  • Unique IDs: Generate UUIDs for records
  • Tokens: Create secure random tokens
  • Cache Keys: Generate consistent keys for caching
  • Checksums: Verify downloaded files

Best Practices

  1. Use SHA-256 or Higher: For security-sensitive applications
  2. Salt Passwords: Add random salt when hashing passwords
  3. Don’t Roll Your Own: Use established libraries for encryption
  4. Secure Random: Use getRandomBytesAsync() for security-critical randomness
  5. Consider bcrypt: For password hashing, consider bcrypt or scrypt libraries
For password hashing, consider using a dedicated library like bcrypt that includes proper salting and key stretching. expo-crypto provides hashing primitives but doesn’t include these features by default.

Resources