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 usedata: String to hashoptions: 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
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
- Use SHA-256 or Higher: For security-sensitive applications
- Salt Passwords: Add random salt when hashing passwords
- Don’t Roll Your Own: Use established libraries for encryption
- Secure Random: Use
getRandomBytesAsync()for security-critical randomness - Consider bcrypt: For password hashing, consider
bcryptorscryptlibraries
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.