Sidebar

Home



Expressions V4


Tutorials

How-To

Reference

  Lexical basics
  Type system
  Variables and assignment
  Operators
  Expression rules
  Control flow
  Functions
  Built-in functions
   None and NaN
   Arithmetic
   Algebra
   Logarithmic and Exponential
   Trigonometric
   Rounding and Centering
   Strings
   Output, Formatting, and Errors
   Dialogs, Clipboard, Platform, and Paths
  Methods and properties
  Built-in methods
   Common Value Methods
   Number Methods
   String Basic Methods
   String Slice Methods
   String Parsing Methods
   String Formatting Methods
   String Regex Methods
   String Trim and Case Methods
  Objects
  Built-in objects
   Global objects
    settings
    session
    python
   Collections
    array
    map
    data_array
   File Format I/O
    image_data
    image_stream
   Utils
    crypto
    timer
   Comm
    serial
   Dialogs
    file_open
    file_save
    msg_ok
    msg_ok_cancel
    msg_yes_no
    msg_password
   GUI objects
    window
    panel
    group
    splitpanel
    label
    textbutton
    drawablebutton
    togglebutton
    togglegroup
    textinput
    textedit
    numinput
    slider
    combobox
    listbox
    progressbar
    led
    separator
    menu
    image
    snake
  Classes and user-defined objects
  Include system
  Error model
  Execution model and sessions
  Host integration
  Limits and performance
  Formal reference
  Glossary

Cookbook

exprv4:reference:objects:crypto

crypto

`crypto` encrypts and decrypts `data_array` values or files.

A crypto object starts without a key. Set a key before calling `encrypt`, `decrypt`, `encrypt_file`, or `decrypt_file`.


Constructor

crypto()

Creates an empty crypto object.

c = crypto();
print(c.ready);      // false
print(c.mode);       // none

Properties

Property Type Description
`ready` boolean `true` when a key has been configured.
`mode` string Current key mode: `none`, `raw`, `password`, or `controller`.

Methods

clear()

Clears the configured key and returns the crypto object.

c = crypto().key_password('secret');
c.clear();
print(c.ready);      // false

key_raw(key)

Sets a raw key from a `data_array` and returns the crypto object.

Arguments:

Argument Description
`key` Raw key bytes as a `data_array`.
key = data_array();
key.add_string('my raw key');
c = crypto().key_raw(key);

key_password(password)

Derives a key from `password` and returns the crypto object.

c = crypto().key_password('secret');

key_controller(uniqueId)

Sets a controller-based key and returns the crypto object.

Arguments:

Argument Description
`uniqueId` Controller unique ID bytes as a `data_array`.

key_export()

Exports the current key and returns it as a string.

c = crypto().key_password('secret');
key_text = c.key_export();

key_export(filePath)

Exports the current key to `filePath` and returns `true` on success.

crypto().key_password('secret').key_export('key.txt');

key_import(keyOrFile)

Imports a key from an exported key string or from an existing file path. Returns the crypto object.

c1 = crypto().key_password('secret');
key_text = c1.key_export();
 
c2 = crypto().key_import(key_text);

encrypt(data)

Encrypts a `data_array` and returns encrypted bytes as a new `data_array`.

plain = data_array();
plain.add_string('secret text');
 
encrypted = crypto().key_password('pw').encrypt(plain);

decrypt(data)

Decrypts a `data_array` and returns decrypted bytes as a new `data_array`.

c = crypto().key_password('pw');
encrypted = c.encrypt(data_array().add_string('ABC'));
plain = c.decrypt(encrypted);

encrypt_file(sourcePath, destinationPath)

Encrypts one file into another file and returns `true` on success.

c = crypto().key_password('pw');
c.encrypt_file('plain.bin', 'plain.bin.crp');

decrypt_file(sourcePath, destinationPath)

Decrypts one file into another file and returns `true` on success.

c = crypto().key_password('pw');
c.decrypt_file('plain.bin.crp', 'plain_restored.bin');

Previous: Utils

Next: timer

exprv4/reference/objects/crypto.txt · Last modified: by 127.0.0.1

Page Tools