Mercurial > encryptobin
view 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 |
line wrap: on
line source
function EncryptoBin(secret, crypto) { this.put = function put(data, cb) { if (!cb) cb = function() {}; jQuery.ajax( {type: "PUT", url: "/" + secret, data: crypto.encrypt(data), contentType: "text/plain", success: function(data) { cb(data); }, error: function() { cb(null); }} ); }; this.get = function get(cb) { jQuery.ajax( {type: "GET", url: "/" + secret, 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; if ($("#password").val()) { var crypto = new AESCrypto($("#password").val(), BITS); var bin = new EncryptoBin(window.location.hash.slice(1), crypto); bin.get( function(data) { $("#plaintext").val(data); } ); $("#plaintext").blur( function commitChanges() { bin.put($("#plaintext").val()); }); } });