Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

uppy-encrypt

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uppy-encrypt

Uppy plugin to encrypt and decrypt files in the browser before upload using libsodium-wrappers

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Uppy Encrypt

An Uppy Plugin to encrypt files on the browser before it's uploaded. Uppy Encrypt also comes with the ability to decrypt browser-side.

Uppy Encrypt uses libsodium.js for all the cryptographical magic.

Installation

npm i uppy-encrypt

Encryption Example

import { Uppy } from '@uppy/core';
import UppyEncryptPlugin from 'uppy-encrypt';

const uppy = new Uppy();
uppy.use(UppyEncryptPlugin);

// Optional: Set password manually, or disregard and a random password will be auto-generated
// uppy.setMeta({ password: '$upers3cret!' });

uppy.on('complete', async (result) => {
  for (const file of result.successful) {
    const salt = file.meta.encryption.salt; // Salt value used to increase security
    const header = file.meta.encryption.header; // Header encryption data to kick off the decryption process
    const hash = file.meta.encryption.hash; // Secure 1-way hash of the password
    const meta = file.meta.encryption.meta;  // Encrypted file meta data (file name, type)
    // ^ These are all safe to store in a database
  }
});

Decryption Example

import { UppyDecrypt, uppyEncryptReady } from 'uppy-encrypt';

// Use the values generated from the encryption process
// Usually, these would be stored/retrieved from a database
const decrypt = async (hash, password, salt, header, meta, encryptedFileUrl) => {
  // Ensure required libraries are loaded
  await uppyEncryptReady();

  // Verify provided password against the stored hash value
  if (!UppyDecrypt.verifyPassword(hash, password)) {
    // Invalid password
    return;
  }

  // Decrypt Metadata
  const decryptor = new UppyDecrypt(password, salt, header);
  const decryptedMeta = decryptor.getDecryptedMetaData(meta.header, meta.data);

  // Fetch & Decrypt the encrypted file
  const file = await fetch(encryptedFileUrl);
  const blob = await file.blob();
  const decrypted = await decryptor.decryptFile(blob);

  // Do something with the decrypted file, like download it
  if (decrypted) {
    const aElement = document.createElement('a');
    aElement.setAttribute('download', decryptedMeta.name);
    const href = URL.createObjectURL(decrypted);
    aElement.href = href;
    aElement.setAttribute('target', '_blank');
    aElement.click();
    URL.revokeObjectURL(href);
  }
}

Keywords

FAQs

Package last updated on 01 Jan 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc