navneet83 / Cross-platform-AES-encryption

Basic cross platform AES encryption
Apache License 2.0
320 stars 152 forks source link

Add support for JavaScript version #38

Open jerryshao2012 opened 8 years ago

jerryshao2012 commented 8 years ago

Any plan to add JavaScript version?

alpertayfun commented 8 years ago

+1

cssxn commented 7 years ago

+1

cssxn commented 7 years ago

@alpertayfun @jerryshao2012

Hi guys! I make it in browserify.

here is what have I done.

browserify ./dist/CryptLib.js  --standalone CryptLib  -o CryptLib.browser.js

Then you can load the CryptLib.browser.js in your html.

<script src="./dist/CryptLib.browser.js" charset="utf-8"></script>
<script>

    var _crypt = new CryptLib();

    plainText = 'This is the text to be encrypted';

    // 16 bytes = 128 bit
    iv = _crypt.generateRandomIV(16);

    //32 bytes = 256 bits
    key = _crypt.getHashSha256('my secret key', 32),

    cypherText = _crypt.encrypt(plainText, key, iv);

console.log('iv = %s', iv);
console.log('key = %s', key);
console.log('Cypher text = %s', cypherText);
console.log('Plain text = %s', _crypt.decrypt(cypherText, key, iv));

</script>