User Tools

Site Tools


Sidebar

Privacy Policy

News

Version 2.50 is out since Jan 1st 2022


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

built_in:crypt

This is an old revision of the document!


Crypt control

This control provides methods for encryption and decryption.

Methods

Some controls use the same methods.
For examples of the same methods look here.

Method Description
Crypt.Decrypt( text,password )
Crypt.Encrypt( text,password )
Crypt.GetType()
Crypt.Hash( text,mode )
Crypt.Release()

Sample code

The code samples available from the IDE include a Security Encryption sample which demonstrates the use of this control.

Password check

The following code demonstrates the use of an md5 hash to check a password.

The first time a password is entered, its hash is saved. Every subsequent time, the password's hash is compared against the saved version.

If it does not match, the app does not continue.

md5.js
//Called when application is started.
function OnStart()
{
    var crypt = app.CreateCrypt();
    var chk = app.LoadText("hash","unset");
    var pass = prompt("","Please enter password");
    if (pass==null) app.Exit();
    var md5 = crypt.Hash( pass, "MD5" );
    if (chk == "unset") app.SaveText("hash", md5)
    else if(chk != md5) app.Exit();
 
    //Create a layout with objects vertically centered.
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );    
 
    //Create a text label and add it to layout.
    txt = app.CreateText( "Hello" );
    txt.SetTextSize( 32 );
    lay.AddChild( txt );
    
    //Add layout to app.    
    app.AddLayout( lay );
}
built_in/crypt.1442871756.txt.gz · Last modified: 2015/09/22 05:42 (external edit)