UNPKG

aes-ecb

Version:

A pure JavaScript implementation of the AES block cipher algorithm with additional features.

127 lines (72 loc) 2.98 kB
AES-ECB ====== A pure JavaScript implementation of the AES block cipher algorithm and features. Simple and very secure Cipher for encrypt and decrypt some sensetive string values. Features -------- - Pure JavaScript - key size (must be 128 bits (16 bytes), 192 bits (24 bytes) or 256 bits (32 bytes)) - Supports all key sizes (128-bit, 192-bit and 256-bit) - Supports all common modes of operation ( ECB ) - Added prefix feature **Strings and Bytes** Strings could be used as keys. But UTF-8 allows variable length, multi-byte characters, so a string that is 16 *characters* long may not be 16 *bytes* long. Also, UTF8 should **NOT** be used to store arbitrary binary data as it is a *string* encoding format, not a *binary* encoding format. API === #### Node.js To install `aes-ecb` in your node.js project: ``` npm install aes-ecb ``` And to access it from within node, simply add: ```javascript var aesEcb = require('aes-ecb'); ``` KeyString must be 128 bits (16 bytes), 192 bits (24 bytes) or 256 bits (32 bytes) long. How it works ------------ keyString - is some unique secret key that takes part in encryption and decryption process. input - is any string that you want to be encrypted and decrypted later. ```javascript var keyString = 'KeyMustBe16ByteOR24ByteOR32Byte!'; var input = 'Some secret string that should be encrypted or decrypted !'; var encrypt = aesEcb.encrypt(keyString, input); var decrypt = aesEcb.decrypt(keyString, input); ``` Example with "Hello world!" --------------------------- ```javascript //Encrypt aesEcb.encrypt('KeyMustBe16ByteOR24ByteOR32Byte!', 'Hello world!') // result looks like ' C41XiUDI/bEvSwYO1iZvOQ== ' //Decrypt aesEcb.decrypt('KeyMustBe16ByteOR24ByteOR32Byte!', 'C41XiUDI/bEvSwYO1iZvOQ==') // result looks like ' Hello world! ' ``` Features -------- aes-ecb.encrypt has required arguments as "keyString" and "input", and optional as "pref" - prefix & "s" -separator Example with "Hello world" and prefix with separator IMPORTANT * when you want to use prefix you should use separator also it's required! ```javascript //shema aesEcb.encrypt(keyString, input, pref, s); aesEcb.encrypt('KeyMustBe16ByteOR24ByteOR32Byte!', 'Hello world!', "prefix", " :: "); //result looks like ' prefix::C41XiUDI/bEvSwYO1iZvOQ==' ``` IMPORTANT * if you had used prefix and separator for encrypt value so for decrypt you should use separator only, or both prefix and separator as separator! ```javascript //shema aesEcb.decrypt(keyString, input, s); aesEcb.decrypt('KeyMustBe16ByteOR24ByteOR32Byte!', 'Hello world!', " :: "); //result looks like ' Hello world! ' ``` ```javascript //shema aesEcb.decrypt(keyString, input, s); aesEcb.decrypt('KeyMustBe16ByteOR24ByteOR32Byte!', 'Hello world!', " prefix:: "); //result looks like ' Hello world! ' ``` FAQ --- #### How do I get a question I have added? E-mail me at ederz_m@hotmail.com with any questions, suggestions, comments, etc.