diff --git a/README.md b/README.md index 376d8af..5e4ace1 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,40 @@ require(["crypto-js"], function (CryptoJS) { See: https://code.google.com/p/crypto-js +### AES Encryption + +#### Plain text encryption + +```javascript +var CryptoJS = require("crypto-js"); + +// Encrypt +var ciphertext = CryptoJS.AES.encrypt('my message', 'secret key 123'); + +// Decrypt +var bytes = CryptoJS.AES.decrypt(ciphertext.toString(), 'secret key 123'); +var plaintext = bytes.toString(CryptoJS.enc.Utf8); + +console.log(plaintext); +``` + +#### Object encryption + +```javascript +var CryptoJS = require("crypto-js"); + +var data = [{id: 1}, {id: 2}] + +// Encrypt +var ciphertext = CryptoJS.AES.encrypt(JSON.stringify(data), 'secret key 123'); + +// Decrypt +var bytes = CryptoJS.AES.decrypt(ciphertext.toString(), 'secret key 123'); +var decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8)); + +console.log(decryptedData); +``` + ### List of modules @@ -186,4 +220,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE.