New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

deadmanswitch-encryption

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deadmanswitch-encryption

Cross-platform encryption library for React Native and React web applications with password-based encryption

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

@deadmanswitch/encryption

Cross-Platform Encryption Library

A lightweight, cross-platform encryption library that works seamlessly with both React Native and React web applications. Uses password-based encryption with PBKDF2 key derivation and AES-GCM encryption.

Features

  • Cross-platform: Works in React Native and React web/Next.js
  • Password-based encryption: Secure PBKDF2 key derivation
  • AES-GCM encryption: Strong encryption with built-in authentication
  • TypeScript support: Full type definitions included
  • React Native: Encryption and decryption
  • React Web: Decryption only (as requested)

Installation

npm install @deadmanswitch/encryption

For React Native, you'll also need to install the crypto dependency:

npm install react-native-quick-crypto

After installation, you'll need to complete the platform setup. For React Native 0.60+, run:

cd ios && pod install

Usage

React Native (Encryption + Decryption)

import { encrypt, decrypt } from '@deadmanswitch/encryption';

// Encrypt data
const encryptData = async () => {
  const result = await encrypt('Hello, World!', {
    password: 'your-secure-password'
  });
  
  console.log('Encrypted:', result.encryptedData);
  console.log('Salt:', result.salt);
  console.log('IV:', result.iv);
  
  return result;
};

// Decrypt data
const decryptData = async (encryptionResult) => {
  const decrypted = await decrypt({
    password: 'your-secure-password',
    encryptedData: encryptionResult.encryptedData,
    salt: encryptionResult.salt,
    iv: encryptionResult.iv
  });
  
  console.log('Decrypted:', decrypted); // "Hello, World!"
  return decrypted;
};

React Web/Next.js (Decryption Only)

import { decrypt } from '@deadmanswitch/encryption';

// Decrypt data received from React Native
const decryptData = async () => {
  const decrypted = await decrypt({
    password: 'your-secure-password',
    encryptedData: 'encrypted-data-from-rn',
    salt: 'salt-from-rn',
    iv: 'iv-from-rn'
  });
  
  console.log('Decrypted:', decrypted);
  return decrypted;
};

API Reference

encrypt(data: string, options: EncryptionOptions): Promise<EncryptionResult>

Encrypts a string using password-based encryption.

Parameters:

  • data - The string to encrypt
  • options - Encryption options
    • password - The password to use for encryption
    • iterations? - Number of PBKDF2 iterations (default: 100000)
    • keyLength? - Key length in bits (default: 256)

Returns: Promise resolving to an EncryptionResult containing:

  • encryptedData - Base64 encoded encrypted data
  • salt - Base64 encoded salt
  • iv - Base64 encoded initialization vector

decrypt(options: DecryptionOptions): Promise<string>

Decrypts data using password-based decryption.

Parameters:

  • options - Decryption options
    • password - The password used for encryption
    • encryptedData - Base64 encoded encrypted data
    • salt - Base64 encoded salt
    • iv - Base64 encoded initialization vector
    • iterations? - Number of PBKDF2 iterations (default: 100000)
    • keyLength? - Key length in bits (default: 256)

Returns: Promise resolving to the decrypted string

Security Notes

  • Uses PBKDF2 with 100,000 iterations by default
  • Uses AES-GCM for authenticated encryption
  • Generates random salt and IV for each encryption
  • Password should be strong and stored securely
  • Never hardcode passwords in your application

Platform Detection

The library automatically detects the platform and uses the appropriate implementation:

  • React Native: Uses react-native-quick-crypto for native performance
  • Web/Next.js: Uses Web Crypto API

TypeScript

Full TypeScript support is included with exported interfaces:

import type { 
  EncryptionOptions, 
  EncryptionResult, 
  DecryptionOptions 
} from '@deadmanswitch/encryption';

License

MIT

Keywords

encryption

FAQs

Package last updated on 13 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts