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

byte-array-util

v1.0.1

Published

Encapsulate the handling between Buffer and Hex data, very useful for situation that processing TCP/UDP data stream, support AES 256 algorithm encrypt and decrypt.

Downloads

6

Readme

byte-array-util

Encapsulate the handling between Buffer(Binary) and Hex data(String), very useful for situation that processing TCP/UDP data stream, e.g. handling the binary hardware protocol data, support AES 256 algorithm encrypt and decrypt.

Installation

$ npm install byte-array-util

Usage

Usage:

var baUtil = require( 'byte-array-util' );

Data converting

/**
 * 'parseFromHexString' can get a Buffer instance from some HEX format string, it
 * will ignore all the space inside the HEX string which actually HEX string not
 * need that. For example we re-create a binary buffer from log file which has
 * the HEX data string below:
 *
 * 0x5B 0x31 0x32 0x33 0x34 0x35 0x5D <-- Equal to Ascii/UTF-8 String --> [12345]
 *
 *
 * 'toHexString' can convert a Buffer instance( Binary ) into HEX format string,
 * if you want to add some separate string between each HEX string( 2 bytes ), you
 * can set 'needSeparator' to true and provide the 'separator' param to what you
 * want.
 */
var networkDataBuffer = baUtil.parseFromHexString( '5B31323334355D' );
//var networkDataBuffer = baUtil.parseHexStringToByteArr( '5B 31 32 33 34 35 5D ' ); // same with above, space will ignore
if ( networkDataBuffer ){

    // Print the binary data
    console.log( 'networkDataBuffer( HEX ): ' + baUtil.toHexString( networkDataBuffer ) );
    console.log( 'networkDataBuffer( HEX with space separate ): ' + baUtil.toHexString( networkDataBuffer, true, ' ' ) );
    console.log( 'networkDataBuffer( UTF-8 String ): ' + networkDataBuffer.toString( 'utf-8' ) );
}
else{
    console.log( 'networkDataBuffer: null' );
}

Binary data encrypt and decrypt

/**
 * Binary buffer also can be encrypted( before you send over network ) and be
 * decrypted( after you got encrypted data from network ):
 *
 * 'encryptByAES256'
 * 'decryptByAES256'
 */
var keyString               = '#%@_My Secret Key!()*',
    keyStringBuffer         = new Buffer( keyString, 'utf-8' ),
    beforeEncryptBuffer     = new Buffer( '<Here is my scret text, please DO NOT tell anybody about this!!!>', 'utf-8' ),
    encryptedBuffer,
    decryptedBuffer;


console.log( 'keyStringBuffer(Hex): \t\t'      + baUtil.toHexString( keyStringBuffer, false, null ) );
console.log( 'keyStringBuffer(String):\t'      + keyStringBuffer.toString( 'utf-8' ) );
console.log( 'beforeEncryptBuffer(Hex):\t'     + baUtil.toHexString( beforeEncryptBuffer, false, null ) );
console.log( 'beforeEncryptBuffer(String):\t'  + beforeEncryptBuffer.toString( 'utf-8' ) );


encryptedBuffer = baUtil.encryptByAES256( beforeEncryptBuffer, keyStringBuffer );
//encryptedBuffer = baUtil.encryptByAES256( beforeEncryptBuffer, keyString );

if ( encryptedBuffer ) {
    console.log( '\nafterEncryptedBuffer(Hex):\t'  + baUtil.toHexString( encryptedBuffer, false, null ) );
    console.log( 'afterEncryptedBuffer(String):\t' + encryptedBuffer.toString( 'utf-8' ) );
}
else {
    logger.logSetting( '\nafterEncryptedBuffer', 'null' );
}


decryptedBuffer = baUtil.decryptByAES256( encryptedBuffer, keyStringBuffer );
//decryptedBuffer = baUtil.decryptByAES256( encryptedBuffer, keyString );

if ( decryptedBuffer ){
    console.log( '\nafterDecryptedBuffer(Hex):\t'  + baUtil.toHexString( decryptedBuffer, false, null ) );
    console.log( 'afterDecryptedBuffer(String):\t' + decryptedBuffer.toString( 'utf-8' ) );
}
else{
    console.log( '\nafterDecryptedBuffer', 'null' );
}