forked from srajgure/MailEnc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.js
105 lines (81 loc) · 3.79 KB
/
action.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
InboxSDK.load('1', 'sdk_Akshay_0b1daa8634').then(function(sdk){
sdk.Compose.registerComposeViewHandler(function(composeView){
composeView.addButton({
title: "AES-ENC",
iconUrl: 'https://img.icons8.com/cotton/64/000000/lock.png',
onClick: function(event) {
//Get Message from compose box.
do{
var key = prompt("Please enter your key:", "KEY");
window.alert(key);
}while(key.length != 16)
key = key.split('');
for(var i=0; i<key.length; i++) { key[i] = +key[i].charCodeAt(0); }
var temp=event.composeView.getHTMLContent();
var enc = "Encrypted with AES : ";
enc = enc.concat(encrypt(temp, key));
event.composeView.setBodyText(enc);
},
});
composeView.addButton({
title: "RSA-ENC",
iconUrl: 'https://icons.iconseeker.com/png/fullsize/scrap/lock-6.png',
onClick: function(event) {
//Get Message from compose box.
var temp = event.composeView.getHTMLContent();
var N = '009afdccef68a56efc68669b498af90bd7cf3466646a853138a8e83d43072687be55575fd3dc15c0a39880389b07148dcbe175ab0f6e971b0638b69dad947d60fd';
var E = '0x010001';
//exponent
var encObj = new RSAKey();
encObj.setPublic(N,E);
var msg = encObj.encrypt(temp);
event.composeView.setBodyText(msg);
},
});
});
sdk.Conversations.registerMessageViewHandler(function(messageView){
messageView.addToolbarButton({
section: sdk.Conversations.MessageViewToolbarSectionNames.MORE,
title: "Decrypt AES",
iconUrl: 'https://image.flaticon.com/icons/svg/2471/2471529.svg',
onClick: function(event) {
//Get Message from compose box.
var cipher = messageView.getBodyElement().textContent;
cipher = cipher.substring(21, cipher.length-1);
do{
var key = prompt("Please enter your key:", "KEY");
window.alert(key);
}while(key.length != 16)
key = key.split('');
for(var i=0; i<key.length; i++) { key[i] = +key[i].charCodeAt(0); }
var plaintxt = decrypt(cipher, key);
//open a new html page containing decrypted text
var opened = window.open("");
var htmlstring = "<html><head><title>Decrypted text : </title></head><body>";
htmlstring = htmlstring.concat(plaintxt);
htmlstring = htmlstring.concat("</body></html>")
opened.document.write(htmlstring);
},
});
messageView.addToolbarButton({
section: sdk.Conversations.MessageViewToolbarSectionNames.MORE,
title: "Decrypt RSA",
iconUrl: 'https://icons.iconseeker.com/png/fullsize/scrap/lock-6.png',
onClick: function(event) {
//Get Message from compose box.
var cipher = messageView.getBodyElement().textContent;
var N = '009afdccef68a56efc68669b498af90bd7cf3466646a853138a8e83d43072687be55575fd3dc15c0a39880389b07148dcbe175ab0f6e971b0638b69dad947d60fd';
var D = '052b760c7e47165ea0f4db3526c78bd794f7c07a94fb005b4d7701a41cb6f24c1fae798447b8e82346ce47a53dcc26ed9fc37aa8508bc587040a64cf58fed999';
var E = '0x010001';
var encObj = new RSAKey();
encObj.setPrivate(N,E,D);
var plaintxt = encObj.decrypt(cipher);
var opened = window.open("");
var htmlstring = "<html><head><title>Decrypted text : </title></head><body>";
htmlstring = htmlstring.concat(plaintxt);
htmlstring = htmlstring.concat("</body></html>")
opened.document.write(htmlstring);
},
});
});
});