bin.enc()
bin.enc(data, key) → binary
Encrypts data with AES-256.
Encrypt payloads before sending them over untrusted networks or to insure data integrity,Keys are 256-bit values — derive one from a passphrase with bin.sha256(). Decrypted results include checksum validation.
The http and udp functions can also encrypt transparently (see setEnv("enc.key", …)).
Data is automatically padded and will be rounded up to the nearest block size.
Arguments
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| data | string | yes | — | Plaintext. Serialise objects first with string(obj). |
| key | binary | yes | — | 256-bit key, e.g. from bin.sha256(passphrase). |
Returns
binary
Encrypted data (slightly larger than the plaintext).
Example
let aesKey = bin.sha256("password");
let secretMsg = string({ msg: "I LOVE FLEXSCADA", code: 12.454 });
let encrypted = bin.enc(secretMsg, aesKey);
print("Size (Raw, Encrypted)", secretMsg.length, encrypted.length);