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"
);
}
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 );
}
}
Methods
The following methods are available on the Crypt object:
string
string: comma “,” separated
string: “MD5” or “SHA-1” or “SHA-256”
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.