Back

CreateCrypt

JS Py
Hello World
Content:
- Properties
- Methods

The Crypt component is used to en- or decrypt a string with a given key or to create a hash of it.

crp = app.CreateCrypt( options? ) → app object: Crypt

Example - Basic

function OnStart()
{
    text = "Hello World!";
    crpt = app.CreateCrypt();
    var encr = crpt.Encrypt(text, "key");
    var decr = crpt.Decrypt(encr, "key");
    var hash = crpt.Hash(text);


    app.Alert(
        'text: "' + text + '"\n' +
        'encr: "' + encr + '"\n' +
        'decr: "' + decr + '"\n' +
        'hash: "' + hash + '"\n' ,
        "Data"
    );
}
from native import app

def OnStart():
    text = "Hello World!"
    crpt = app.CreateCrypt()
    encr = crpt.Encrypt(text, "key")
    decr = crpt.Decrypt(encr, "key")
    hash = crpt.Hash(text)

    app.Alert(
        'text: "' + text + '"\n' +
        'encr: "' + encr + '"\n' +
        'decr: "' + decr + '"\n' +
        'hash: "' + hash + '"\n' ,
        "Data"
    )
    Copy     Copy All       Run      

Example - Encrypt using device id

function OnStart()
{
    crp = app.CreateCrypt();
    ShowDialog( "Hello World" );
}

function ShowDialog( data )
{
    app.ShowTextDialog("input text", data, OnText);
}

function OnText( text )
{
    var dlg = app.CreateYesNoDialog( "Choose option", "NoCancel" );
    dlg.SetOnTouch( OnAction );
    dlg.data.text = text;
    dlg.Show();
    dlg.SetButtonText( "Encrypt", "Decrypt" );
}

function OnAction( result )
{
    if( result == "Yes" )
    {
        result = crp.Encrypt( this.data.text, app.GetDeviceId() );
        ShowDialog( result );
    }
    else if( result == "No" )
    {
        result = crp.Decrypt( this.data.text, app.GetDeviceId() );
        ShowDialog( result );
    }
}
from native import app

def OnStart():
    global crp
    crp = app.CreateCrypt()
    ShowDialog("Hello World")

def ShowDialog(data):
    app.ShowTextDialog("input text", data, OnText)

def OnText(text):
    global data
    dlg = app.CreateYesNoDialog("Choose option", "NoCancel")
    dlg.SetOnTouch(OnAction)
    dlg.data = {"text": text}
    dlg.Show()
    dlg.SetButtonText("Encrypt", "Decrypt")

def OnAction(result):
    if result == "Yes":
        result = crp.Encrypt(this.data["text"], app.GetDeviceId())
        ShowDialog(result)
    elif result == "No":
        result = crp.Decrypt(this.data["text"], app.GetDeviceId())
        ShowDialog(result)
Copy All       Run      

Properties

The following properties are available on the Crypt object:

dataObject: { key, value }

Methods

The following methods are available on the Crypt object:

Decrypt( text, password ) → String
Encrypt( text, password ) → String
GetType() → String: “Crypt”
Hash( text, mode, options? ) → String
all types
String
String: comma “,” separated
String: “MD5” or “SHA” or “SHA-1” or “SHA-224” or “SHA-256” or “SHA-384” or “SHA-512”
String: “Wrap”
Object: { command: args }
crp.Batch
Batch method calls to be able to set all object's properties at once.
Note that you need to specify each parameter (use “” or null to leave some out)
Inherited methods can be called by appending an underscore to the function name (ie. txt.Batch({ SetBackColor_: [“red”] })
crp.data
An object for saving individual extra properties.
crp.Decrypt
Decrypt text with a key.
crp.Encrypt
Encrypt text with a key.
crp.GetType
Returns the control class name.
crp.Hash
Build a hash of a string for one-way encryption.
crp.SetDescription
Set a control description for accessibility