A small dependencyless library that provides only a special class for encrypting and decrypting arbitrary files using PNG images as cryptographic keys in place of typical password strings. It provides both AES-GCM and Vigenère encryption/decription method
npm install uglycryUglyCry is a micro-library that provides only a special class for encrypting and decrypting arbitrary files using PNG images as cryptographic keys in place of typical password strings.
It supports two encryption modes:
- AES-GCM (256-bit) — secure, modern browser-native cryptography
- Vigenère cipher — simple, educational, intentionally weak
No key derivation is performed, the entire PNG’s full binary data is used as the key material itself.
UglyCry can optionally apply 32 reversible obfuscation layers using multiple (16, chance of ~x3 each) data-scrambling functions. This layer sequence is generated from the png's hash (deterministic and reversible).
It works entirely client-side, accepting input from (given key input is valid PNG):
- File objects
- elements
- DOM elements that expose .files[0]
- Data URLs previously produced by UglyCry itself
No server environment required.
UglyData class:Construction:
``js`
new UglyData(processVigenere, obfuscateFingerprint, reportLogs);
Construction arguments:
(bool) processVigenere - If true, sets the encryption method to fbe a simple and insecure Vigenere cipher encryption. Otherwise, uses the standard AES-GCM encryption method.
(bool) obfuscateFingerprint - If true, sets the obfuscation layering process to run after encryption, and to reverse the layers before decryption. Otherwise, skip that part of the process.
(bool) reportLogs - If true, console.log() the package's functions at each and every step of the processes for easy testing.
_____________________________
Provides public fields:
- keyName [string]
> name of the file used as the key.
> Can be set using the loadKey(element) method.
- keyHash [string]
> a 32-character (128-bit) non-cryptographic hash derived from the PNG key, used for generating obfuscation-layer order.
> Can be set using the loadKey(element) method.
- keyBlob [string]
> string containing the blob of data from the key's loaded file.
> Can be set using the loadKey(element) method.
- subjectName [string]
> name of the file used as the subject.
> Can be set using the loadSubject(element) method.
- subjectBlob [string]
> string containing the blob of data from the subject's loaded file.
> Can be set using the loadSubject(element) method.
_____________________________
Provides public methods:
- loadKey(elementOrObject)
> Loads the PNG key used as the cryptographic key (File/DOM).
> Stores the file name under keyName and DataURL data under keyBlob before
hashing the key and storing that in keyHash.
- loadSubject(elementOrObject)
> Loads the file subject to encryption or decryption (File/DOM).
> Stores the file name under subjectName and its data under subjectBlob
(as either plaintext or a DataURL data depending on if it's a .ugly file).
- processUgly(isDecryption) - returns the [File] result of running a cipher
on subjectBlob using keyBlob.
> If this object's obfuscateFingerprint = true,
also runs through the obfuscation process.
> If this object's processVigenere = true,
runs using the vigenere cipher.
Otherwise, runs using the AES-GCM cipher.
> If isDecryption= true, decrypt.
Otherwise, encrypt.
_____________________________
`js
import UglyData from 'uglycry';
let vigenereMode = false;
let obfuscateFingerprint = true;
let printUcLogs = true;
console.log("Creating UglyData instance for AES encryption with obfuscation...");
const ucAesObfuscate = new UglyData(vigenereMode, obfuscateFingerprint, printUcLogs);
console.log("Loading images for encryption/decryption...");
await ucAesObfuscate.loadKey(document.getElementById('keyInput'));
await ucAesObfuscate.loadSubject(document.getElementById('subjectInput'));
console.log("Encrypting...");
const encryptedFile = await ucAesObfuscate.processUgly(false);
console.log("Encrypted file:", encryptedFile);
console.log("Decrypting...");
const decryptedFile = await ucAesObfuscate.processUgly(true);
console.log("Decrypted file:", decryptedFile);
``
_____________________________