Mercurial > encryptobin
annotate static-files/encryptobin.js @ 2:e5df7c795457 default tip
Put password field in a form so that it can be saved by Firefox.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Tue, 07 Apr 2009 23:41:34 -0700 |
parents | ecf3376d2a5a |
children |
rev | line source |
---|---|
1
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
1 function EncryptoBin(secret, crypto) { |
0 | 2 this.put = function put(data, cb) { |
1
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
3 if (!cb) |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
4 cb = function() {}; |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
5 |
0 | 6 jQuery.ajax( |
7 {type: "PUT", | |
8 url: "/" + secret, | |
1
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
9 data: crypto.encrypt(data), |
0 | 10 contentType: "text/plain", |
11 success: function(data) { cb(data); }, | |
12 error: function() { cb(null); }} | |
13 ); | |
14 }; | |
15 | |
16 this.get = function get(cb) { | |
17 jQuery.ajax( | |
18 {type: "GET", | |
19 url: "/" + secret, | |
1
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
20 success: function(data) { cb(crypto.decrypt(data)); }, |
0 | 21 error: function() { cb(null); }} |
22 ); | |
23 }; | |
24 } | |
25 | |
1
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
26 function AESCrypto(password, bits) { |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
27 this.encrypt = function AESEncrypt(data) { |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
28 return AESEncryptCtr(data, password, bits); |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
29 }; |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
30 |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
31 this.decrypt = function AESDecrypt(data) { |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
32 return AESDecryptCtr(data, password, bits); |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
33 }; |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
34 } |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
35 |
0 | 36 $(window).ready( |
37 function() { | |
38 var BITS = 256; | |
2
e5df7c795457
Put password field in a form so that it can be saved by Firefox.
Atul Varma <varmaa@toolness.com>
parents:
1
diff
changeset
|
39 if ($("#password").val()) { |
e5df7c795457
Put password field in a form so that it can be saved by Firefox.
Atul Varma <varmaa@toolness.com>
parents:
1
diff
changeset
|
40 var crypto = new AESCrypto($("#password").val(), BITS); |
1
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
41 var bin = new EncryptoBin(window.location.hash.slice(1), |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
42 crypto); |
0 | 43 |
1
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
44 bin.get( |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
45 function(data) { $("#plaintext").val(data); } |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
46 ); |
0 | 47 |
1
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
48 $("#plaintext").blur( |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
49 function commitChanges() { |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
50 bin.put($("#plaintext").val()); |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
51 }); |
ecf3376d2a5a
Changed the web page to be kind of like an editor.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
52 } |
0 | 53 }); |