Skip to content

Majik Blob – A lightweight TypeScript/JavaScript library for securely encrypting and decrypting files (Blobs). Ideal for protecting assets before storage or transmission.

Notifications You must be signed in to change notification settings

jedlsf/majik-blob

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Majik Blob

Majik Blob is a lightweight JavaScript/TypeScript library for encrypting and decrypting files (Blobs) securely.
It’s ideal for scenarios where you want to store files in cloud storage or deliver files but prevent direct access or downloads without the correct key.


Live Demo

Majik Blob Thumbnail

Click the image to try Majik Blob.


✨ Features

  • 🔐 Encrypt any file type (images, audio, video, 3D models, documents, etc.)
  • 📦 Returns a single encrypted Blob (.mjkb) with metadata for integrity verification
  • 🧾 Preserves original MIME type & file extension
  • 🧪 Tamper detection and password verification
  • ⚡ Fully reversible with the correct key and RQX
  • 💨 Optional compression to reduce file size before encryption
  • 🌐 Browser-first, TypeScript-friendly


📦 Installation

npm i @thezelijah/majik-blob

Usage

Generate a Key

Encrypts the file and returns a .mjkb Blob. Majik Blob uses a password and an internal RQX key for encryption. Generate a key securely before encrypting:

import { MajikBlob } from "@thezelijah/majik-blob";
const { key, rqx } = MajikBlob.generateKey(32); // 32-character password

Encrypting Files

Optionally compress files before encryption to reduce size:

import { MajikBlob } from "@thezelijah/majik-blob";
import { downloadBlob } from "@thezelijah/majik-blob/utils";

const file = new File(["Hello world"], "example.txt", { type: "text/plain" });

const majik = new MajikBlob(key, file);
const encryptedBlob = await majik.getEncryptedBlob(rqx, true); // true enables compression

// Save or upload the encrypted file
downloadBlob(encryptedBlob, "mjkb", "example");

Decrypting Files

Decrypts a .mjkb Blob and restores the original file.

import { MajikBlob } from "@thezelijah/majik-blob";

const decrypted = await MajikBlob.decryptEncryptedBlob(encryptedBlob, key, rqx);

console.log(decrypted.data);       // Restored Blob
console.log(decrypted.type);       // Original MIME type
console.log(decrypted.extension);  // Original file extension

Reading File Extension Without Decryption

Reads the original file extension without decrypting the file.

const extension = await MajikBlob.getEncryptedFileExtension(encryptedBlob);
console.log(extension); // e.g. "glb", "mp3", "png"

Use Cases

  • Secure file uploads before storing in cloud storage
  • Obfuscated delivery of downloadable assets
  • Protecting media files (audio, video, 3D models)
  • Client-side encryption for creative tools
  • Controlled-access file distribution systems
  • DRM-adjacent workflows without heavy infrastructure

Best Practices

  • Use strong, unique passwords for each file.
  • Store un-hashed password/key in environment variables to prevent tampering.
  • Majik Blob is ideal for obfuscating files in storage; files cannot be opened without the correct key.
  • Always verify the key before decrypting to avoid corrupted files.
  • Compression is optional but recommended for large files.
  • AES-GCM ensures tamper detection and secure encryption.

Important: Always store the un-hashed encryption key and RQX in environment variables to prevent tampering and accidental exposure.

Contributing

Contributions, bug reports, and suggestions are welcome! Feel free to fork and open a pull request.


License

ISC — free for personal and commercial use.


Author

Made with 💙 by @thezelijah

About the Developer


Contact


What’s new in this version:

  1. Highlights AES-256-GCM encryption with random IVs (replaced Fernet).
  2. Mentions optional compression for smaller encrypted files.
  3. Clarifies integrity checks and tamper detection.
  4. Updated usage examples to include compression parameter.

About

Majik Blob – A lightweight TypeScript/JavaScript library for securely encrypting and decrypting files (Blobs). Ideal for protecting assets before storage or transmission.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published