-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
83 lines (63 loc) · 2.33 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*jslint maxerr:1000 */
var my = {
mod : require('SlowAES/Ti.SlowAES')
};
(function () {
var win = Ti.UI.createWindow({
backgroundColor: '#fff', title: 'AES Crypto Example',
barColor:'#000',layout:'vertical',fullscreen:false, exitOnClose:true
});
win.add(Ti.UI.createLabel({
top:10, height:65, left:5, right:5,color:'#000',
textAlign:'left',text:'Demonstration on how to use Ti.SlowAES for AES Encryption in JavaScript.',
font:{fontSize:14}
}));
win.add(Ti.UI.createLabel({
top:10, height:25, left:5, right:5,color:'#000',
textAlign:'left',text:'Enter Secret',
font:{fontSize:14}
}));
var txtSecret = Ti.UI.createTextField({
value:'DoNotTell',hintText:'Enter Secret',
height:45, left:5, right:5,
borderStyle:Ti.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(txtSecret);
win.add(Ti.UI.createLabel({
top:10, height:25, left:5, right:5,color:'#000',
textAlign:'left',text:'Enter Info to Encrypt',
font:{fontSize:14}
}));
var txtToEncrypt = Ti.UI.createTextField({
value:'some information we want to encrypt',
hintText:'Enter information to encrypt',
height:45, left:5, right:5,
borderStyle:Ti.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(txtToEncrypt);
var encryptedLabel = Ti.UI.createLabel({
top:10, height:65, left:5, right:5,color:'#000',
textAlign:'left',font:{fontSize:14}
});
win.add(encryptedLabel);
var btnEncrypt = Ti.UI.createButton({
title:'Run Encryption Test', top:25, height:45, left:5, right:5
});
win.add(btnEncrypt);
btnEncrypt.addEventListener('click',function(x){
encryptedLabel.text = '';
//Create a new instance of the SlowAES module
var crypto = new my.mod();
//Demonstrate how to encrypt a value
var encryptedValue = crypto.encrypt(txtToEncrypt.value,txtSecret.value);
encryptedLabel.text = 'Encrypted:' + encryptedValue;
//Demonstrate how to decrypt a value already encrypted
var decryptedValue = crypto.decrypt(encryptedValue,txtSecret.value);
alert((txtToEncrypt.value ===decryptedValue) ?
'Encryption Test successfully run, please check console for details.' :
'Test failed, please check console for details.');
//The below test can also be run to verify the encryption process
crypto.passCryptoTest(txtToEncrypt.value,txtSecret.value);
});
win.open({modal:true});
})();