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);
uppy.on('complete', async (result) => {
for (const file of result.successful) {
const salt = file.meta.encryption.salt;
const header = file.meta.encryption.header;
const hash = file.meta.encryption.hash;
const meta = file.meta.encryption.meta;
}
});
Decryption Example
import { UppyDecrypt, uppyEncryptReady } from 'uppy-encrypt';
const decrypt = async (hash, password, salt, header, meta, encryptedFileUrl) => {
await uppyEncryptReady();
if (!UppyDecrypt.verifyPassword(hash, password)) {
return;
}
const decryptor = new UppyDecrypt(password, salt, header);
const decryptedMeta = decryptor.getDecryptedMetaData(meta.header, meta.data);
const file = await fetch(encryptedFileUrl);
const blob = await file.blob();
const decrypted = await decryptor.decryptFile(blob);
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);
}
}