aes.js-wrapper
v1.0.0
Published
Encrypt and decrypt very secure and completely uniqe text from and to AES 256 CBC
Downloads
3
Readme
AES.js-wrapper
Encrypt and decrypt very secure and completely uniqe text from and to AES 256 CBC
Installation
# With NPM
npm i -S ihack2712/aes.js-wrapper
# With YARN
yarn add ihack2712/aes.js-wrapper
# With bower
bower install ihack2712/aes.js-wrapper
Example
const AES = require('aes.js-wrapper')
var password = 'secret'
, text = 'Hello World'
var encrypted = AES.encrypt(text, password)
, decrypted = AES.decrypt(encrypted, password)
console.log('AES Wrapper Example')
console.log('Password: "' + password + '"')
console.log('Dummy Text: "' + text + '"')
console.log('')
console.log('* Encrypted')
console.log(encrypted)
console.log()
console.log('* Decrypted')
console.log(decrypted)
Results In:
$ node example
AES Wrapper Example
Password: "secret"
Dummy Text: "Hello World"
* Encrypted
c9ea1bf12e83ecb5b06a2f9e1ebb4c7eea0fba8d48ffa4973bd4d4b65b809e648f0996c291dc7035ca1c41dcf39864188f41f5893bc00d73d4b376e74cdc9bf0a933df90723dc9f4510e4d6ad9936694
* Decrypted
Hello World
Properties
| Name | Type | Description | | --------- | ------ | ------------------------------------------------------------------------- | | _iv_ | Buffer | Get the default IV in a buffer. | | dummyText | string | This is the default dummy text to use when hashing and validating hashes. |
Methods
constructor ()
The constructor method in this class is completely useless, it's not used for anything.
encrypt (value, password)
Encrypt normal text to a very uniqe, and very secure hex formatted string.
Params
| Name | Type | Description | | -------- | ------ | ------------------------------------------------------------------------------------------------------ | | value | string | This is the text to encrypt. | | password | string | This is the raw text utf8 password to hash into a md5 hex that will also secure the encryption better. |
Returns
Example
AESWrapper.encrypt('hello world', 'very secret password')
// '39f425031f850fcca2f0f4f56bf3143a8104fa1dd27eb143f64a4fd3f223b85ca6b5849a5b48e6dd4af9fb6ddba9ffbae41c4d165491f8358ae7167d7acc834e58cf97fbab413aef0165ea991a475809'
decrypt (data, password)
Decrypt encrypted text to the normal text using the very secret password.
Params
| Name | Type | Description | | -------- | ------ | ------------------------------------------------------------------------------------------------------ | | data | string | This is the encrypted text to decrypt | | password | string | This is the raw text utf8 password to hash into a md5 hex that will also secure the encryption better. |
Returns
Example
AESWrapper.decrypt('39f425031f850fcca2f0f4f56bf3143a8104fa1dd27eb143f64a4fd3f223b85ca6b5849a5b48e6dd4af9fb6ddba9ffbae41c4d165491f8358ae7167d7acc834e58cf97fbab413aef0165ea991a475809', 'very secret password')
// 'hello world'
hash (key)
Hash text into a completely uniqe hash, that means hashing the same text again won't be equal to this one.
Params
| Name | Type | Description | | ---- | ------ | --------------------------------------------------------------------------------- | | key | string | This key will be used to create the hash, this key will be encrypting dummy text. |
Returns
Example
AESWrapper.hash('Hello World')
// c6ae556bd9a4d728f061ff66cd196e96e00792810061a528db8f4f74f229c60dc9bfc837fbe447eadb7c6353ffce18983849c70ffc7ac754ee3d2502ddc148827032ea83741d9647a6a2e8921cb1800c192381fe42d357de64d397c4e10c0b2eeee18d2255a7817cb36bb9ee97c17fb84ad48da3b2902d3b0953a357f6d0b9720c117474ea2bdf3cc9212645403f6ed94f8106cfb2db4b755ae15c3652721a108654fff81c06379fd092794dea8455019212cd25a983146cb8472049bba75d9a4e5777484c4360dabc233d6fa4c9923a
val (hash, key)
Check if a hash is valid by decrypting dummy text.
Params
| Name | Type | Description | | ---- | ------ | ---------------------------------------------------------------------------------------------------------------------------------- | | hash | string | This is the hash to match against, simply try to decrypt this hash into the dummy text and check if the decryption was successful. | | key | string | This key will be used to decrypt the hash into dummy text. |
Returns
Example
AESWrapper.val('c6ae556bd9a4d728f061ff66cd196e96e00792810061a528db8f4f74f229c60dc9bfc837fbe447eadb7c6353ffce18983849c70ffc7ac754ee3d2502ddc148827032ea83741d9647a6a2e8921cb1800c192381fe42d357de64d397c4e10c0b2eeee18d2255a7817cb36bb9ee97c17fb84ad48da3b2902d3b0953a357f6d0b9720c117474ea2bdf3cc9212645403f6ed94f8106cfb2db4b755ae15c3652721a108654fff81c06379fd092794dea8455019212cd25a983146cb8472049bba75d9a4e5777484c4360dabc233d6fa4c9923a', 'Hello World')
// true
getRandomBytes (length)
This is used to get a random IV, this also makes the encryption uniqe and very secure.
Params
| Name | Type | Description | | ------ | ------ | --------------------------------------------------- | | length | number | This defines how many bytes that will be generated. |
Returns
hex (buffer)
This turns a buffer into a string
Params
| Name | Type | Description | | ------ | ------ | ----------------------------------------------- | | buffer | Buffer | The buffer to encode into a hex formatted text. |
Returns
buffer (hex)
Decode HEX into a buffer.
Params
| Name | Type | Description | | ---- | ------ | ----------------------- | | hex | string | The hex data to decode. |
Returns
md5 (text)
Hash text into a md5 hash.
Params
| Name | Type | Description | | ---- | ------ | -------------------------------- | | text | string | The text to hash to an MD5 hash. |
Returns
Example
AESWrapper.md5('hello world')
// '5EB63BBBE01EEED093CB22BB8F5ACDC3'