# HG changeset patch
# User Atul Varma
# Date 1239146485 25200
# Node ID ecf3376d2a5a153e15d2ca65e93c51d4dfba1753
# Parent 1c8dbbdce596a388cd5f18eb1289d5f1a6ad3ff1
Changed the web page to be kind of like an editor.
diff -r 1c8dbbdce596 -r ecf3376d2a5a static-files/encryptobin.js
--- 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());
+ });
+ }
});
diff -r 1c8dbbdce596 -r ecf3376d2a5a static-files/index.html
--- 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
- plaintext
-
-
- ciphertext
+
-commit
-update
-encrypt
-decrypt