npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aes.js-wrapper

v1.0.0

Published

Encrypt and decrypt very secure and completely uniqe text from and to AES 256 CBC

Downloads

2

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

string

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

string

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

string

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

string

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

Buffer

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

string

buffer (hex)

Decode HEX into a buffer.

Params

| Name | Type | Description | | ---- | ------ | ----------------------- | | hex | string | The hex data to decode. |

Returns

Buffer

md5 (text)

Hash text into a md5 hash.

Params

| Name | Type | Description | | ---- | ------ | -------------------------------- | | text | string | The text to hash to an MD5 hash. |

Returns

string

Example
AESWrapper.md5('hello world')
// '5EB63BBBE01EEED093CB22BB8F5ACDC3'