changeset 1:ecf3376d2a5a

Changed the web page to be kind of like an editor.
author Atul Varma <varmaa@toolness.com>
date Tue, 07 Apr 2009 16:21:25 -0700
parents 1c8dbbdce596
children e5df7c795457
files static-files/encryptobin.js static-files/index.html
diffstat 2 files changed, 29 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/static-files/encryptobin.js	Tue Apr 07 16:07:54 2009 -0700
+++ b/static-files/encryptobin.js	Tue Apr 07 16:21:25 2009 -0700
@@ -1,9 +1,12 @@
-function EncryptoBin(secret) {
+function EncryptoBin(secret, crypto) {
   this.put = function put(data, cb) {
+    if (!cb)
+      cb = function() {};
+
     jQuery.ajax(
       {type: "PUT",
        url: "/" + secret,
-       data: data,
+       data: crypto.encrypt(data),
        contentType: "text/plain",
        success: function(data) { cb(data); },
        error: function() { cb(null); }}
@@ -14,47 +17,37 @@
     jQuery.ajax(
       {type: "GET",
        url: "/" + secret,
-       success: function(data) { cb(data); },
+       success: function(data) { cb(crypto.decrypt(data)); },
        error: function() { cb(null); }}
     );
   };
 }
 
+function AESCrypto(password, bits) {
+  this.encrypt = function AESEncrypt(data) {
+    return AESEncryptCtr(data, password, bits);
+  };
+
+  this.decrypt = function AESDecrypt(data) {
+    return AESDecryptCtr(data, password, bits);
+  };
+}
+
 $(window).ready(
   function() {
     var BITS = 256;
-    var bin = new EncryptoBin(window.location.hash.slice(1));
-
-    $("#update").click(
-      function() {
-        bin.get(function(data) {
-                  $("#ciphertext").val(data);
-                });
-      });
-
-    $("#commit").click(
-      function() {
-        bin.put($("#ciphertext").val(),
-                function(response) { console.log(response); });
-      });
+    if ($("#pass").val()) {
+      var crypto = new AESCrypto($("#pass").val(), BITS);
+      var bin = new EncryptoBin(window.location.hash.slice(1),
+                                crypto);
 
-    $("#encrypt").click(
-      function() {
-        $("#ciphertext").val(
-          AESEncryptCtr(
-            $("#plaintext").val(),
-            $("#pass").val(),
-            BITS
-          ));
-      });
+      bin.get(
+        function(data) { $("#plaintext").val(data); }
+      );
 
-    $("#decrypt").click(
-      function() {
-        $("#plaintext").val(
-          AESDecryptCtr(
-            $("#ciphertext").val(),
-            $("#pass").val(),
-            BITS
-          ));
-      });
+      $("#plaintext").blur(
+        function commitChanges() {
+          bin.put($("#plaintext").val());
+        });
+    }
   });
--- a/static-files/index.html	Tue Apr 07 16:07:54 2009 -0700
+++ b/static-files/index.html	Tue Apr 07 16:21:25 2009 -0700
@@ -10,15 +10,8 @@
   pass <input type="text" id="pass"/>
 </p>
 <p>
-  plaintext <textarea id="plaintext"></textarea>
-</p>
-<p>
-  ciphertext <textarea id="ciphertext"></textarea>
+  <textarea rows="40" cols="40" id="plaintext"></textarea>
 </p>
-<div id="commit">commit</div>
-<div id="update">update</div>
-<div id="encrypt">encrypt</div>
-<div id="decrypt">decrypt</div>
 </body>
 <script src="jquery.js"></script>
 <script src="aes.js"></script>