Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/tools/building/encryption/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Encryption",
"position": 2
}
58 changes: 58 additions & 0 deletions docs/tools/building/encryption/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: Encryption mechanisms
sidebar_position: 1
---

AIR packages support encryption of contents in two main ways. The first of these uses a tool that's provided with the AIR SDK called `swfencrypt`, which operates across an entire SWF file. The second uses the AIR compiler to encrypt a binary object that is embedded within a normal SWF file and can then be decrypted at run-time.

### swfencrypt

The `swfencrypt` mechanism uses an internal key and initialization vector but this approach has been reverse engineered and published online, so this should not be considered secure. It is a command-line AIR application that has the following usage:
```
swfencrypt -in input.swf -out output.swf
```

So for example, pass in your input SWF file and provide an output filename, and the output will be an encrypted version of the input. When the SWF is loaded by the AIR runtime, it will be decrypted automatically. The SWF contents would be visible in memory so this is also not the most secure option, although the content would not be available if calling `LoaderInfo.bytes`.


### Embedding encrypted data

The AIR compiler can also be used to embed data and to encrypt it using a custom key, which makes this more secure as it can only be decrypted at runtime with that key. Normally, data can be embedded in a SWF file using a form such as:
```
[Embed(source="filename.dat", mimeType="application/octet-stream")]
private const MyData : Class;
```
Comment on lines +21 to +24
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ActionScript example uses spaces around the type annotation colon (e.g., MyData : Class). Elsewhere in the docs (including the coding conventions) the style is name:Type; update this snippet to match for consistency.

Copilot uses AI. Check for mistakes.

A new `encrypted` flag has been added to this tag, so that the data can be encrypted. There is a default encryption key that is generated,
if the flag is just set to `true`, otherwise the flag can be set to a string (ideally 16 characters long) which will then be used as the key.

```
[Embed(source="filename.dat", mimeType="application/octet-stream", encrypted="true")]
private const MyData1 : Class;
[Embed(source="filename.dat", mimeType="application/octet-stream", encrypted="encryption_key_1")]
private const MyData2 : Class;
```
Comment on lines +29 to +34
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same ActionScript formatting issue here: the type annotations are written with spaces around the colon (e.g., MyData1 : Class). Update to the repository’s documented convention (name:Type) for consistency.

Copilot uses AI. Check for mistakes.

A utility method is available within the AIR runtime in order to access the data:
```
// leave the second argument blank/null for the default key
var decrypted1:ByteArray = System.decryptBlob(MyData1);
// or use the same key string as in the 'encrypted' flag from the embed command
var decrypted2:ByteArray = System.decryptBlob(MyData2, "encryption_key_1");
```

Because the built-in key generation mechanism is common across all code, an additional compiler option has been added, in order to allow
the developer to provide a key that would be used by default (i.e. where the embed tag has `encrypted="true"`). This means that all content
can be encrypted from the same source code, with a key generated and passed to the compiler, that can later on be made available to the
application so that it can decrypt the content via `System.decryptBlob()`. The compiler option is:
```
-compiler.encryption-key=encryption_key_2
```
This is essentially equivalent to having all of the `Embed` fields using `encrypted="encryption_key_2"` where they currently just use `"true"`.

Using these mechanisms, it should be possible for binary data to be safely encrypted and protected, with the application able to safely
obtain and use the compile-time key later on at run-time via some authenticated server or hash mechanism. The decrypted data can then be
used in its normal form e.g. if it was actually a SWF to be passed to a Loader object, or if it was an image or other assets. Note that the
decrypted data may still be available in memory dumps of the process if a malicious user is trying to obtain this.


Loading