Skip to content

Commit 034d533

Browse files
committed
Merge pull request brix#35 from andrewjmead/develop
Updated Readme.md - Added AES example
2 parents a4bff2f + c0787db commit 034d533

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

README.md

+35-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,40 @@ require(["crypto-js"], function (CryptoJS) {
9191

9292
See: https://code.google.com/p/crypto-js
9393

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+
94128
### List of modules
95129

96130

@@ -186,4 +220,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
186220
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
187221
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
188222
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
189-
THE SOFTWARE.
223+
THE SOFTWARE.

0 commit comments

Comments
 (0)