aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/encrypt_object.js
blob: b2efa8b5abfd177bce08bace161b822b54d9a3fd (plain)
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
load('jsbn.js')
load('jsbn2.js')
load('rsa.js')
load('rsa2.js')
load('sjcl.js')
load('prng4.js')
load('rng.js')

var root = '/var/lib/alias'
var priv_key_string = read(root + '/guillaume@alias.im/privkey/object')
var pub_key_string1 = read(root + '/guillaume@alias.im/pubkey/object')
var pub_key_string2 = read(root + '/thrasibule@alias.im/pubkey/object')
var pub_key1 = new RSAKey()
var pub_key1_json = JSON.parse(pub_key_string1)
pub_key1.setPublic(pub_key1_json.n,pub_key1_json.e)
var pub_key2 = new RSAKey()
var pub_key2_json = JSON.parse(pub_key_string2)
pub_key2.setPublic(pub_key2_json.n,pub_key2_json.e)


varpriv_key = sjcl.decrypt("Mvdujq06",priv_key_string)

var profile = '<h2><span id="firstname">John</span> <span id="lastname">Doe</span></h2>\
<ul>\
<li><span class="description">Sex:</span> <span id="sex" class="editable">Male</span></li>\
<li><span class="description">Born:</span> <span id="birthdate" class="editable">02/02/1980</span></li>\
<li><span class="description">Email:</span> <span id="email" class="editable">john.doe@alias.im</li>\
<li><span class="description">Adress:</span> <span id="adress" class="editable">450 W. 33 Street</span>\
<span id="city" class="editable">New York City</span> </li>\
<ul>'

//sjcl.random.startCollectors() 
var aeskey = sjcl.random.randomWords(4,0)
var aeskeyb64 = sjcl.codec.base64.fromBits(aeskey)
var object = sjcl.encrypt(aeskey,profile)
var enckey1 = pub_key1.encrypt(aeskeyb64)
var enckey2 = pub_key2.encrypt(aeskeyb64)
print("This is the content of the encrypted object:")
print(object)
print("This is the encryption key encrypted with the public key of guillaume@alias.im")
print(enckey1)
print("This is the encryption key encrypted with the public key of thrasibule@alias.im")
print(enckey2)