Preview · Not published yet

Encrypt every asset. Decrypt only when needed.

An APK, AAB or IPA is a ZIP archive. Anyone can rename it, unzip it and copy your HTML, JavaScript, images and audio. html2app encrypts each file at build time, and the app's local server decrypts a file only when the web view requests it.

  • Every file, not only code
  • Decrypted per request, in memory
  • AES-256-GCM with authentication
How app packages work

APK, AAB and IPA are all ZIP archives

An app package is a container. Open it and you find the files your build produced, with the same names and the same contents.

APK

Android install file

A ZIP archive with compiled code, resources and assets. Android installs it directly on a device. Web files usually sit in the assets folder, where they can be read.

AAB

Android App Bundle

The publishing format for Google Play. It is a ZIP-based archive too. Google Play generates device-specific APKs from it, and devices cannot install the bundle itself.

IPA

iOS app package

A ZIP archive with a Payload folder that holds the app bundle: the binary, resources and your web files.

Typical wrappers

Wrappers copy your web build into the package as it is

Cordova, Capacitor and most web-to-app builders copy the compiled web folder into the native project. The web view then loads those files from inside the app. Core versions of these tools do not encrypt the files, so each one stays readable after unzipping.

Typical wrapper

The web files go into the package unchanged.

  1. Web build folder
  2. Copied into the native project
  3. Packed into the ZIP package
  4. Anyone unzips the package
  5. Every asset is readable
html2app with encryption

Each file is encrypted before it goes into the package.

  1. Web build folder
  2. Each file encrypted
  3. Packed into the ZIP package
  4. Anyone unzips the package
  5. Only ciphertext is visible
Comparison

Typical wrappers and html2app, side by side

The comparison covers the common default setup of each tool.

Question Typical wrapper or builder html2app (preview)
Readable after unzipping the package Yes. HTML, CSS, JavaScript, images and audio stay as they are. No. Each file is stored as ciphertext.
Encryption at build time Not in the core of Capacitor or Cordova. Yes, for every file in the build.
Decryption Not needed. Per request, by the local server middleware, in memory only.
Encryption add-ons Some exist. Their maintenance varies a lot. Built in. No plugin to install.

If you use an add-on for Cordova or Capacitor, check its last release, platform support and open issues before you rely on it.

How it works

Encrypted at build time, decrypted on request

The package never holds readable copies of your files. The local server opens one file at a time, when the web view asks for it.

01 Request The web view asks for script.js.crypt
02 Read The local server reads the ciphertext from the package
03 Decrypt The middleware runs AES-256-GCM on that one file
04 Respond The plain bytes go out in the response, held in memory

At build time

  1. 1

    Encrypt each file

    Every file in the web build is encrypted with AES-256-GCM. The output holds a 12-byte nonce, the ciphertext and a 16-byte authentication tag.

  2. 2

    Keep the name, add the extension

    script.js becomes script.js.crypt. The extension tells the server which files to decrypt.

  3. 3

    Package only the encrypted files

    The APK, AAB or IPA carries the .crypt files. No readable copy goes into the package.

At runtime

  1. 1

    Request one file

    The web view requests a file. The local server finds the encrypted version in the package.

  2. 2

    Decrypt that file only

    The middleware decrypts the requested file. Files nobody requests are never decrypted.

  3. 3

    Serve it from memory

    The content goes out with the MIME type of the original file name. The middleware does not write it to disk.

server.dart Wire the middleware
final handler = const Pipeline()
    .addMiddleware(decryptionMiddleware(
      decryptHandler: decryptAsset,
      encryptedExtensions: ['.crypt', '.enc', '.encrypted'],
    ))
    .addHandler(assetHandler);

The middleware sits between the file server and the response. Only requests for an encrypted extension reach the decrypt step.

decrypt_asset.dart Simplified sketch
// Layout per file: [12-byte nonce][ciphertext][16-byte tag]
Future<List<int>> decryptAsset(String path, List<int> encryptedBytes) async {
  if (encryptedBytes.length < 28) {
    throw FormatException('Encrypted file too short');
  }

  final data = Uint8List.fromList(encryptedBytes);
  final nonce = data.sublist(0, 12);
  final cipherText = data.sublist(12, data.length - 16);
  final tag = Mac(data.sublist(data.length - 16));

  // Key source is an open design question, see Limits. The app needs it at runtime.
  final key = await appKey();

  // AES-GCM checks the tag first. A changed file throws instead of returning bytes.
  return AesGcm.with256bits().decrypt(
    SecretBox(cipherText, nonce: nonce, mac: tag),
    secretKey: key,
  );
}

A sketch based on the decryption example in the middleware documentation, not the production code.

Try it

Unzip the same app two ways

Pick a file, then switch between a typical wrapper package and an html2app package. The previews show what anyone sees after unzipping.

index.html
<!doctype html>
<html lang="en">
  <script src="js/app.js"></script>
</html>

Illustration with placeholder data. The byte values are examples, not output from a build.

Limits

What encryption does not protect against

Encryption raises the effort needed to copy your assets. It does not make the app secret. Know these limits before you rely on it.

Protects against

  • Copying images, audio and code from a downloaded APK, AAB or IPA
  • Casual inspection of your web files after unzipping the package
  • Silent changes to an encrypted file, because the GCM tag check fails

Does not protect against

  • A determined attacker who reverse engineers the app. The app needs the key to decrypt, so the key is on the device.
  • Memory inspection or debugging while the app runs. Decrypted content exists in memory while the page uses it.
  • Secrets with server-side power, such as admin API keys. Keep those on your backend, not in the app.

Treat encryption as one layer. Keep sensitive logic and secrets on a server you control.

FAQ

Common questions

Is this available yet?

No. This page describes a feature that is not published yet. Details may change before release.

Which files are encrypted?

Every file in the web build, including HTML, CSS, JavaScript, images, audio and video. Each encrypted file keeps its original name and adds an encrypted extension such as .crypt.

What happens if someone changes an encrypted file?

Decryption fails. AES-GCM checks the authentication tag before it returns any bytes, so the local server returns an error instead of the modified content.

Are decrypted files saved to disk?

No. The decryption middleware returns the bytes in memory for the response. It does not write them to disk.

Can I use an encryption plugin for Capacitor or Cordova instead?

You can, if it fits your setup. Check the plugin's last release, platform support and open issues first, because add-on maintenance varies a lot.

Ship your web app without leaving its files open

Encrypted assets are in preview. Build on html2app.dev now, and read the developer app guide in the meantime.