How to Password-Protect a .lottie File

Encrypt a .lottie archive with AES-256 and decrypt it again, using dotlottie-io's optional password parameter.

How to Password-Protect a .lottie File

Every I/O method in dotlottie-io accepts an optional password parameter. When provided, every ZIP entry — including manifest.json — is encrypted with AES-256.

Writing an encrypted archive

const { DotLottie } = require("@lottiefiles/dotlottie-io");
const { writeFileSync } = require("node:fs");

const dl = DotLottie.fromFile("source.lottie");
const encrypted = dl.toBytes("my-secret-password");
writeFileSync("protected.lottie", encrypted);

Reading an encrypted archive

const { readFileSync } = require("node:fs");

const loaded = DotLottie.fromBytes(readFileSync("protected.lottie"), "my-secret-password");
console.log(loaded.animationIds());

Lazy inspection of an encrypted archive

DotLottieReader accepts the same password parameter:

const { DotLottieReader } = require("@lottiefiles/dotlottie-io");

const reader = DotLottieReader.open("protected.lottie", "my-secret-password");
console.log(reader.animationIds());

Note that opening a password-protected archive with DotLottieReader.open() reads the whole file into memory up front — the low-memory streaming guarantee only applies to unencrypted archives.

Handling errors

Two distinct errors can be thrown when opening a protected archive:

MessageCause
"password required to open this archive"The archive is encrypted but no password was passed
"wrong password or corrupted archive"The password is incorrect, or the archive is corrupt
try {
  DotLottie.fromBytes(protectedBytes, "wrong-password");
} catch (e) {
  console.error(e.message); // "wrong password or corrupted archive"
}

See Errors for the full list of thrown errors.

Last updated: August 6, 2026 at 1:25 AMEdit this page