Permalink
Browse files

add browser side aes.js

  • Loading branch information...
1 parent 26a005b commit c00c85fdb3b0d51afac7df6bd27be89867bce975 Jack Carrick Xiang Cheng committed Jul 31, 2012
Showing with 85 additions and 44 deletions.
  1. +3 −1 README.md
  2. +0 −41 README.md~
  3. +32 −0 client/aes.js
  4. +3 −1 cryptojs.js
  5. +46 −0 lib/jsonformatter.js
  6. +1 −1 package.json
View
@@ -11,12 +11,14 @@ It is built upon award winning browser side javascript library CryptoJS. current
**node-cryptojs-aes** doesn't rely on any external library, such as native openssl libary or any external node.js modules. As a node.js module, it can simply be installed through npm package management system. There is no configuration needed also.
+**node-cryptojs-aes** maximises node.js design spirit. Browser side and server side are running identical javascript cryptography codebase. It allows coder to migrate any browser side logic to server or vice versa without any modification. The message passing between server side and client side has been drastically simplified. The encrypted JSON data is passed between client side and server side without any additional parsing or encoding effort made on both side.
+
## Features
* **Self Contained** It doesn't rely on any external dependency.
* **Server Side Cryptography** It is the only up and running server side javascript cryptography library so far.
* **Cross Platform** It is working across all node.js supported platform.
- * **Code Base** Browser side and server side are running identical javascript cryptography codebase. It allows coder to migrate any browser side logic to server or vice versa without any modification. The message passing between server side and client side has been drastically simplified. The encrypted JSON data is passed between client side and server side without any additional parsing or encoding effort made on both side.
+ * **Code Base** Browser and Server share same codebase.
* **AES symmetric key cryptography** It supports AES-128, AES-192 and AES-256 Encryption.
* **Encoding** It supports Base64 encoding, Hexadecimal, Utf-8 and binary.
* **Cipher Input** The key or iv(initialization vector) can be passed in as parameter of encryption function, or single passphrase can be passed in as parameter.
View
@@ -1,41 +0,0 @@
-node-cryptojs-aes
-=================
-
-**node-cryptojs-aes** is a minimalist port of cryptojs javascript library to node.js, that supports AES symmetric key cryptography.
-
-Unlike node.js native crypto library, **node-cryptojs-aes** removes openssl dependency.
-
-It is built upon award winning browser side javascript library CryptoJS. currently, it has been updated to be compatible with CryptoJS version 3.0.2.
-
-**node-cryptojs-aes** doesn't make any modification to original cryptojs library, the syntax remains the same in accordance with [CryptoJS documentation](http://code.google.com/p/crypto-js/).
-
-**node-cryptojs-aes** doesn't rely on any external library, such as native openssl libary or any external node.js modules. As a node.js module, it can simply be installed through npm package management system. There is no configuration needed also.
-
-## Features
-
- * **Self Contained** It doesn't rely on any external dependency.
- * **Server Side Cryptography** It is the only up and running server side javascript cryptography library so far.
- * **Cross Platform** It is working across all node.js supported platform.
- * **AES symmetric key cryptography** It supports AES-128, AES-192 and AES-256 Encryption.
- * **Encoding** It supports Base64 encoding, Hexadecimal, Utf-8 and binary.
- * **Cipher Input** The key or iv(initialization vector) can be passed in as parameter of encryption function, or single passphrase can be passed in as parameter.
-
-## Sample Usage
-
-## Installation
-
-Install through npm
-
-```
-npm install node-cryptojs-aes
-```
-
-## Donation
-
-To support the developer's development and contribute to open source community and node.js community, you might donate money to help out your fellowmen, no matter how large or small, it all counts. With your effort, we can make a better world, Thank you.
-
-[![Donate to author](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DB26KWR2BQX5W)
-
-
-
-
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -4,5 +4,7 @@ require('./lib/md5');
require('./lib/evpkdf');
require('./lib/cipher-core');
require('./lib/aes');
+var JsonFormatter = require('./lib/jsonformatter').JsonFormatter;
-exports.CryptoJS = CryptoJS;
+exports.CryptoJS = CryptoJS;
+exports.JsonFormatter = JsonFormatter;
View
@@ -0,0 +1,46 @@
+var CryptoJS = require('./core').CryptoJS;
+
+// create custom json serialization format
+var JsonFormatter = {
+ stringify: function (cipherParams) {
+ // create json object with ciphertext
+ var jsonObj = {
+ ct: cipherParams.ciphertext.toString(CryptoJS.enc.Base64)
+ };
+
+ // optionally add iv and salt
+ if (cipherParams.iv) {
+ jsonObj.iv = cipherParams.iv.toString();
+ }
+
+ if (cipherParams.salt) {
+ jsonObj.s = cipherParams.salt.toString();
+ }
+
+ // stringify json object
+ return JSON.stringify(jsonObj)
+ },
+
+ parse: function (jsonStr) {
+ // parse json string
+ var jsonObj = JSON.parse(jsonStr);
+
+ // extract ciphertext from json object, and create cipher params object
+ var cipherParams = CryptoJS.lib.CipherParams.create({
+ ciphertext: CryptoJS.enc.Base64.parse(jsonObj.ct)
+ });
+
+ // optionally extract iv and salt
+ if (jsonObj.iv) {
+ cipherParams.iv = CryptoJS.enc.Hex.parse(jsonObj.iv);
+ }
+
+ if (jsonObj.s) {
+ cipherParams.salt = CryptoJS.enc.Hex.parse(jsonObj.s);
+ }
+
+ return cipherParams;
+ }
+};
+
+exports.JsonFormatter = JsonFormatter;
View
@@ -2,7 +2,7 @@
"author": "Jack Carrick Xiang Cheng <chengxianga2008@yahoo.com> (inovlab.com)",
"name": "node-cryptojs-aes",
"description": "A minimalist port of cryptojs javascript library to node.js, that supports AES symmetric key cryptography.",
- "version": "0.3.3",
+ "version": "0.3.7",
"repository": {
"type": "git",
"url": "git://github.com/chengxianga2008/node-cryptojs-aes.git"

0 comments on commit c00c85f

Please sign in to comment.