Expo Application Services
API Reference


expo-crypto enables you to hash (encrypt) data in an equivalent manner to the Node.js core crypto API.

Platform Compatibility

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb


โ†’ย expo install expo-crypto

If you're installing this in a bare React Native app, you should also follow these additional installation instructions.

Basic Crypto usage
import React, { useEffect } from 'react';
import { StyleSheet, View, Text } from 'react-native';
import * as Crypto from 'expo-crypto';

export default function App() {
  useEffect(() => {
    (async () => {
      const digest = await Crypto.digestStringAsync(
        'GitHub stars are neat ๐ŸŒŸ'
      console.log('Digest: ', digest);
      /* Some crypto operation... */
  }, []);

  return (
    <View style={styles.container}>
      <Text>Crypto Module Example</Text>

%%placeholder-start%%const styles = StyleSheet.create({ ... }); %%placeholder-end%%const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',

import * as Crypto from 'expo-crypto';

  algorithm: CryptoDigestAlgorithm,
  data: string,
  options: CryptoDigestOptions = { encoding: CryptoEncoding.HEX }
): Promise<string>
The digestStringAsync() method of Crypto generates a digest of the supplied data string with the provided digest algorithm. A digest is a short fixed-length value derived from some variable-length input. Cryptographic digests should exhibit collision-resistance, meaning that it's very difficult to generate multiple inputs that have equal digest values. You can specify the returned string format as one of CryptoEncoding. By default the resolved value will be formatted as a HEX string. On web, this method can only be called from a secure origin (https) otherwise an error will be thrown.
๐ŸŽ iOS๐Ÿ’š Android๐Ÿ’ป Web
algorithmCryptoDigestAlgorithmTransforms a value into a fixed-size hash (usually shorter than the initial value).
datastringThe value that will be used to generate a digest.
optionsCryptoDigestOptionsFormat of the digest string. Defaults to: CryptoDigestOptions.HEX
digestPromise<string>Resolves into a value representing the hashed input.

  • ERR_CRYPTO_UNAVAILABLE - (Web only) Access to the WebCrypto API is restricted to secure origins (https). You can run your web project from a secure origin with expo start --https.
  • ERR_CRYPTO_DIGEST - An invalid encoding type provided.
const digest = await Crypto.digestStringAsync(
  '๐Ÿฅ“ Easy to Digest! ๐Ÿ’™'

Cryptographic hash function is an algorithm that can be used to generate a checksum value. They have a variety of applications in cryptography.
Cryptographic hash functions like SHA1, MD5 are vulnerable! Attacks have been proven to significantly reduce their collision resistance.
NameTypeDescriptionCollision Resistant๐ŸŽ iOS๐Ÿ’š Android๐Ÿ’ป Web
SHA1string160 bitsโŒโœ…โœ…โœ…
SHA256string256 bitsโœ…โœ…โœ…โœ…
SHA384string384 bitsโœ…โœ…โœ…โœ…
SHA512string512 bitsโœ…โœ…โœ…โœ…
MD2string128 bitsโŒโœ…โŒโŒ
MD4string128 bitsโŒโœ…โŒโŒ
MD5string128 bitsโŒโœ…โœ…โŒ

NameType๐ŸŽ iOS๐Ÿ’š Android๐Ÿ’ป Web
Base64 Format
  • Has trailing padding.
  • Does not wrap lines.
  • Does not have a trailing newline.

NameTypeDescription๐ŸŽ iOS๐Ÿ’š Android๐Ÿ’ป Web
encodingCryptoEncodingFormat the digest is returned inโœ…โœ…โœ…

ERR_CRYPTO_UNAVAILABLE(Web only) Access to the WebCrypto API is restricted to secure origins (https).
ERR_CRYPTO_DIGESTAn invalid encoding type provided.