UNPKG

react-native-aes-ecb

Version:

A pure JavaScript implementation of the AES block cipher algorithm with additional features for react-native.

119 lines (68 loc) 2.91 kB
REACT-NATIVE-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 === #### React native To install `react-native-aes-ecb` in your react native project: ``` npm install react-native-aes-ecb ``` And to access it from within you app, simply add: ```javascript var aesEcb = require('react-native-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! ' ```