1 | # crypto-js
|
2 |
|
3 | JavaScript library of crypto standards.
|
4 |
|
5 | ## Node.js (Install)
|
6 |
|
7 | Requirements:
|
8 |
|
9 | - Node.js
|
10 | - npm (Node.js package manager)
|
11 |
|
12 | ```bash
|
13 | npm install crypto-js
|
14 | ```
|
15 |
|
16 | ### Usage
|
17 |
|
18 | Modular include:
|
19 |
|
20 | ```javascript
|
21 | var AES = require("crypto-js/aes");
|
22 | var SHA256 = require("crypto-js/sha256");
|
23 | ...
|
24 | console.log(SHA256("Message"));
|
25 | ```
|
26 |
|
27 | Including all libraries, for access to extra methods:
|
28 |
|
29 | ```javascript
|
30 | var CryptoJS = require("crypto-js");
|
31 | console.log(CryptoJS.HmacSHA1("Message", "Key"));
|
32 | ```
|
33 |
|
34 | ## Client (browser)
|
35 |
|
36 | Requirements:
|
37 |
|
38 | - Node.js
|
39 | - Bower (package manager for frontend)
|
40 |
|
41 | ```bash
|
42 | bower install crypto-js
|
43 | ```
|
44 |
|
45 | ### Usage
|
46 |
|
47 | Modular include:
|
48 |
|
49 | ```javascript
|
50 | require.config({
|
51 | packages: [
|
52 | {
|
53 | name: 'crypto-js',
|
54 | location: 'path-to/bower_components/crypto-js',
|
55 | main: 'index'
|
56 | }
|
57 | ]
|
58 | });
|
59 |
|
60 | require(["crypto-js/aes", "crypto-js/sha256"], function (AES, SHA256) {
|
61 | console.log(SHA256("Message"));
|
62 | });
|
63 | ```
|
64 |
|
65 | Including all libraries, for access to extra methods:
|
66 |
|
67 | ```javascript
|
68 | // Above-mentioned will work or use this simple form
|
69 | require.config({
|
70 | paths: {
|
71 | 'crypto-js': 'path-to/bower_components/crypto-js/crypto-js'
|
72 | }
|
73 | });
|
74 |
|
75 | require(["crypto-js"], function (CryptoJS) {
|
76 | console.log(CryptoJS.HmacSHA1("Message", "Key"));
|
77 | });
|
78 | ```
|
79 |
|
80 | ### Usage without RequireJS
|
81 |
|
82 | ```html
|
83 | <script type="text/javascript" src="path-to/bower_components/crypto-js/crypto-js.js"></script>
|
84 | <script type="text/javascript">
|
85 | var encrypted = CryptoJS.AES(...);
|
86 | var encrypted = CryptoJS.SHA256(...);
|
87 | </script>
|
88 | ```
|
89 |
|
90 | ## API
|
91 |
|
92 | See: https://code.google.com/p/crypto-js
|
93 |
|
94 | ### AES Encryption
|
95 |
|
96 | #### Plain text encryption
|
97 |
|
98 | ```javascript
|
99 | var CryptoJS = require("crypto-js");
|
100 |
|
101 | // Encrypt
|
102 | var ciphertext = CryptoJS.AES.encrypt('my message', 'secret key 123');
|
103 |
|
104 | // Decrypt
|
105 | var bytes = CryptoJS.AES.decrypt(ciphertext.toString(), 'secret key 123');
|
106 | var plaintext = bytes.toString(CryptoJS.enc.Utf8);
|
107 |
|
108 | console.log(plaintext);
|
109 | ```
|
110 |
|
111 | #### Object encryption
|
112 |
|
113 | ```javascript
|
114 | var CryptoJS = require("crypto-js");
|
115 |
|
116 | var data = [{id: 1}, {id: 2}]
|
117 |
|
118 | // Encrypt
|
119 | var ciphertext = CryptoJS.AES.encrypt(JSON.stringify(data), 'secret key 123');
|
120 |
|
121 | // Decrypt
|
122 | var bytes = CryptoJS.AES.decrypt(ciphertext.toString(), 'secret key 123');
|
123 | var decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
|
124 |
|
125 | console.log(decryptedData);
|
126 | ```
|
127 |
|
128 | ### List of modules
|
129 |
|
130 |
|
131 | - ```crypto-js/core```
|
132 | - ```crypto-js/x64-core```
|
133 | - ```crypto-js/lib-typedarrays```
|
134 |
|
135 | ---
|
136 |
|
137 | - ```crypto-js/md5```
|
138 | - ```crypto-js/sha1```
|
139 | - ```crypto-js/sha256```
|
140 | - ```crypto-js/sha224```
|
141 | - ```crypto-js/sha512```
|
142 | - ```crypto-js/sha384```
|
143 | - ```crypto-js/sha3```
|
144 | - ```crypto-js/ripemd160```
|
145 |
|
146 | ---
|
147 |
|
148 | - ```crypto-js/hmac-md5```
|
149 | - ```crypto-js/hmac-sha1```
|
150 | - ```crypto-js/hmac-sha256```
|
151 | - ```crypto-js/hmac-sha224```
|
152 | - ```crypto-js/hmac-sha512```
|
153 | - ```crypto-js/hmac-sha384```
|
154 | - ```crypto-js/hmac-sha3```
|
155 | - ```crypto-js/hmac-ripemd160```
|
156 |
|
157 | ---
|
158 |
|
159 | - ```crypto-js/pbkdf2```
|
160 |
|
161 | ---
|
162 |
|
163 | - ```crypto-js/aes```
|
164 | - ```crypto-js/tripledes```
|
165 | - ```crypto-js/rc4```
|
166 | - ```crypto-js/rabbit```
|
167 | - ```crypto-js/rabbit-legacy```
|
168 | - ```crypto-js/evpkdf```
|
169 |
|
170 | ---
|
171 |
|
172 | - ```crypto-js/format-openssl```
|
173 | - ```crypto-js/format-hex```
|
174 |
|
175 | ---
|
176 |
|
177 | - ```crypto-js/enc-latin1```
|
178 | - ```crypto-js/enc-utf8```
|
179 | - ```crypto-js/enc-hex```
|
180 | - ```crypto-js/enc-utf16```
|
181 | - ```crypto-js/enc-base64```
|
182 |
|
183 | ---
|
184 |
|
185 | - ```crypto-js/mode-cfb```
|
186 | - ```crypto-js/mode-ctr```
|
187 | - ```crypto-js/mode-ctr-gladman```
|
188 | - ```crypto-js/mode-ofb```
|
189 | - ```crypto-js/mode-ecb```
|
190 |
|
191 | ---
|
192 |
|
193 | - ```crypto-js/pad-pkcs7```
|
194 | - ```crypto-js/pad-ansix923```
|
195 | - ```crypto-js/pad-iso10126```
|
196 | - ```crypto-js/pad-iso97971```
|
197 | - ```crypto-js/pad-zeropadding```
|
198 | - ```crypto-js/pad-nopadding```
|
199 |
|
\ | No newline at end of file |