ostrio:aes-crypto

v1.0.0Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Isomorphic AES cipher

Simplified isomorphic API for AES cipher by CryptoJS

This implementation uses random salt for every encrypted value and CFB padding. This means if you even encrypt two times same value with same password the encrypted result will be both times different. So encrypted values by this method is strong against rainbow tables and all other precomputed tables.

Installation

meteor add ostrio:aes-crypto

API

AESencrypt(plainString, password)
1AESencrypt('My Plain String', 'TXkgUGxhaW4gU3RyaW5n');
2// Returns: '{"ct":"ZQAp/MEV0pMDn6V7oY5YFVvEGNxvG2eJliNPZpT9U2I=","iv":"0e472d2cd20892ac9cfcf91dea4fe98e","s":"35e808ccc71b8c13"}'
AESdecrypt(JSONableString, password)
1AESdecrypt('{"ct":"ZQAp/MEV0pMDn6V7oY5YFVvEGNxvG2eJliNPZpT9U2I=","iv":"0e472d2cd20892ac9cfcf91dea4fe98e","s":"35e808ccc71b8c13"}', 'TXkgUGxhaW4gU3RyaW5n');
2// Returns: 'My Plain String'

Validate encrypted JSONable String

To validate returned object from AESencrypt function use this regular expression:

1/^{"ct":"([A-Za-z0-9+\/]+(\={0,2}))","iv":"([0-9a-f]{32})","s"\:"([0-9a-f]{16})"}$/

#####Example:

1JSONableString = AESencrypt('My Plain String', 'TXkgUGxhaW4gU3RyaW5n');
2/^{"ct":"([A-Za-z0-9+\/]+(\={0,2}))","iv":"([0-9a-f]{32})","s"\:"([0-9a-f]{16})"}$/.test(JSONableString);
3// Returns: true