Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-encoding-utils

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-encoding-utils

Miscellaneous Encoding Utilities for Crypto-related Objects in JavaScript

  • 0.7.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
42K
increased by61.02%
Maintainers
1
Weekly downloads
 
Created
Source

npm version Unit Test codecov Maintainability License: MIT

WARNING: At this time this solution should be considered suitable for research and experimentation, further code and security review is needed before utilization in a production application.

Introduction and Overview

This library is being developed to handle cryptographic data objects, e.g., PEM-formatted X.509 certificate, in JavaScript. Note that this library provides no cryptographic functions like encryption, but provides encoders, decoders and formatters of data formats related to cryptographic data objects. In particular, this introduces Base64(Url)-ArrayBuffer en/decoder, HexString-ArrayBuffer en/decoder and PEM-Binary formatter at this point. Moreover, this library is designed to be 'universal', i.e., it works both on most browsers and on Node.js just by importing from npm/source code.

Installation

At your project directory, do either one of the following.

  • From npm/yarn:

    $ npm install --save js-encoding-utils // npm
    $ yarn add js-encoding-utils // yarn
    
  • From GitHub:

    $ git clone https://github.com/junkurihara/jseu.git
    

Then you should import the package as follows.

import jseu from 'js-encoding-utils'; // for npm
import jseu from 'jseu/dist/index.js'; // for github

Usage

Base64 <-> Binary

// msg is an ArrayBuffer or Typed Array
const encoded = jseu.encoder.encodeBase64(msg);
// now you get Base64 string

const decoded = jseu.encoder.decodeBase64(encoded);
// now you get the original message in Uint8Array

Base64Url <-> Binary

// msg is an ArrayBuffer or Typed Array
const encoded = jseu.encoder.encodeBase64Url(msg);
// now you get Base64Url string

const decoded = jseu.encoder.decodeBase64Url(encoded);
// now you get the original message in Uint8Array

HexString <-> Binary

// msg is an ArrayBuffer or Typed Array
const encoded = jseu.encoder.arrayBufferToHexString(msg);
// now you get the hex-stringified message string

const decoded = jseu.encoder.hexStringToArrayBuffer(encoded);
// now you get the original message in Uint8Array

PEM <-> Binary (usually DER encoding)

// X.509 formatted certificate
const certPEM ='-----BEGIN CERTIFICATE-----...';

const binCert = jseu.formatter.pemToBin(certPEM);
// now you get the DER encoded certificate in Uint8Array

const pemCert = jseu.formatter.binToPem(binCert, 'certificate');
// now you get the original certificate.

License

Licensed under the MIT license, see LICENSE file.

Keywords

FAQs

Package last updated on 02 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc